diff options
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 6effb30e2..2acbbaeb1 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -153,6 +153,9 @@ struct ServerConnection | |||
153 | /* Should this connection get disconnected? GNUNET_YES/NO */ | 153 | /* Should this connection get disconnected? GNUNET_YES/NO */ |
154 | int disconnect; | 154 | int disconnect; |
155 | 155 | ||
156 | /* For PUT connections: Is this the first or last callback with size 0 */ | ||
157 | int connected; | ||
158 | |||
156 | /* The session this server connection belongs to */ | 159 | /* The session this server connection belongs to */ |
157 | struct Session *session; | 160 | struct Session *session; |
158 | 161 | ||
@@ -511,7 +514,7 @@ http_server_plugin_send (void *cls, | |||
511 | GNUNET_break (0); | 514 | GNUNET_break (0); |
512 | return GNUNET_SYSERR; | 515 | return GNUNET_SYSERR; |
513 | } | 516 | } |
514 | if ((NULL == session->server_send) || (NULL == session->server_recv)) | 517 | if (NULL == session->server_send) |
515 | { | 518 | { |
516 | GNUNET_break (0); | 519 | GNUNET_break (0); |
517 | return GNUNET_SYSERR; | 520 | return GNUNET_SYSERR; |
@@ -1055,6 +1058,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1055 | sc->mhd_daemon = plugin->server_v6; | 1058 | sc->mhd_daemon = plugin->server_v6; |
1056 | sc->mhd_conn = mhd_connection; | 1059 | sc->mhd_conn = mhd_connection; |
1057 | sc->direction = direction; | 1060 | sc->direction = direction; |
1061 | sc->connected = GNUNET_NO; | ||
1058 | sc->session = s; | 1062 | sc->session = s; |
1059 | if (direction == _SEND) | 1063 | if (direction == _SEND) |
1060 | s->server_send = sc; | 1064 | s->server_send = sc; |
@@ -1165,9 +1169,6 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1165 | } | 1169 | } |
1166 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 1170 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
1167 | "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); | 1171 | "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); |
1168 | |||
1169 | |||
1170 | |||
1171 | return bytes_read; | 1172 | return bytes_read; |
1172 | } | 1173 | } |
1173 | 1174 | ||
@@ -1285,7 +1286,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1285 | /* connection is to be disconnected */ | 1286 | /* connection is to be disconnected */ |
1286 | if (sc->disconnect == GNUNET_YES) | 1287 | if (sc->disconnect == GNUNET_YES) |
1287 | { | 1288 | { |
1288 | /* Sent HTTP/1.1: 200 OK as PUT Response\ */ | 1289 | /* Sent HTTP/1.1: 200 OK as response */ |
1289 | response = MHD_create_response_from_data (strlen ("Thank you!"), | 1290 | response = MHD_create_response_from_data (strlen ("Thank you!"), |
1290 | "Thank you!", | 1291 | "Thank you!", |
1291 | MHD_NO, MHD_NO); | 1292 | MHD_NO, MHD_NO); |
@@ -1314,20 +1315,39 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1314 | } | 1315 | } |
1315 | if (sc->direction == _RECEIVE) | 1316 | if (sc->direction == _RECEIVE) |
1316 | { | 1317 | { |
1317 | if (*upload_data_size == 0) | 1318 | if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO)) |
1318 | { | 1319 | { |
1320 | /* (*upload_data_size == 0) first callback when header are passed */ | ||
1319 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1321 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1320 | "Peer `%s' PUT on address `%s' connected\n", | 1322 | "Peer `%s' PUT on address `%s' connected\n", |
1321 | GNUNET_i2s (&s->target), | 1323 | GNUNET_i2s (&s->target), |
1322 | http_common_plugin_address_to_string (NULL, | 1324 | http_common_plugin_address_to_string (NULL, |
1323 | s->addr, | 1325 | s->addr, |
1324 | s->addrlen)); | 1326 | s->addrlen)); |
1327 | sc->connected = GNUNET_YES; | ||
1325 | return MHD_YES; | 1328 | return MHD_YES; |
1326 | } | 1329 | } |
1327 | 1330 | else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) | |
1328 | /* Receiving data */ | ||
1329 | if ((*upload_data_size > 0)) | ||
1330 | { | 1331 | { |
1332 | /* (*upload_data_size == 0) when upload is complete */ | ||
1333 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | ||
1334 | "Peer `%s' PUT on address `%s' finished upload\n", | ||
1335 | GNUNET_i2s (&s->target), | ||
1336 | http_common_plugin_address_to_string (NULL, | ||
1337 | s->addr, | ||
1338 | s->addrlen)); | ||
1339 | sc->connected = GNUNET_NO; | ||
1340 | /* Sent HTTP/1.1: 200 OK as PUT Response\ */ | ||
1341 | response = MHD_create_response_from_data (strlen ("Thank you!"), | ||
1342 | "Thank you!", | ||
1343 | MHD_NO, MHD_NO); | ||
1344 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | ||
1345 | MHD_destroy_response (response); | ||
1346 | return MHD_YES; | ||
1347 | } | ||
1348 | else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) | ||
1349 | { | ||
1350 | /* (*upload_data_size > 0) for every segment received */ | ||
1331 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1351 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1332 | "Peer `%s' PUT on address `%s' received %u bytes\n", | 1352 | "Peer `%s' PUT on address `%s' received %u bytes\n", |
1333 | GNUNET_i2s (&s->target), | 1353 | GNUNET_i2s (&s->target), |
@@ -1362,7 +1382,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1362 | return MHD_YES; | 1382 | return MHD_YES; |
1363 | } | 1383 | } |
1364 | else | 1384 | else |
1385 | { | ||
1386 | GNUNET_break (0); | ||
1365 | return MHD_NO; | 1387 | return MHD_NO; |
1388 | } | ||
1366 | } | 1389 | } |
1367 | return res; | 1390 | return res; |
1368 | } | 1391 | } |
@@ -1429,6 +1452,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1429 | GNUNET_i2s (&s->target), s->server_recv, | 1452 | GNUNET_i2s (&s->target), s->server_recv, |
1430 | http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)); | 1453 | http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)); |
1431 | s->server_recv = NULL; | 1454 | s->server_recv = NULL; |
1455 | /* Do not terminate session when PUT disconnects | ||
1432 | if (NULL != (s->server_send)) | 1456 | if (NULL != (s->server_send)) |
1433 | { | 1457 | { |
1434 | s->server_send->disconnect = GNUNET_YES; | 1458 | s->server_send->disconnect = GNUNET_YES; |
@@ -1438,7 +1462,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1438 | 1); | 1462 | 1); |
1439 | #endif | 1463 | #endif |
1440 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); | 1464 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); |
1441 | } | 1465 | }*/ |
1442 | if (s->msg_tk != NULL) | 1466 | if (s->msg_tk != NULL) |
1443 | { | 1467 | { |
1444 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 1468 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
@@ -1612,7 +1636,10 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
1612 | last_timeout, timeout); | 1636 | last_timeout, timeout); |
1613 | last_timeout = timeout; | 1637 | last_timeout = timeout; |
1614 | } | 1638 | } |
1615 | tv.rel_value = (uint64_t) timeout; | 1639 | if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value) |
1640 | tv.rel_value = (uint64_t) timeout; | ||
1641 | else | ||
1642 | tv = GNUNET_TIME_UNIT_SECONDS; | ||
1616 | } | 1643 | } |
1617 | else | 1644 | else |
1618 | tv = GNUNET_TIME_UNIT_SECONDS; | 1645 | tv = GNUNET_TIME_UNIT_SECONDS; |