aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-18 11:08:57 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-18 11:08:57 +0000
commite5d90281a1b8b9d91e4ea754bc7831cf56c4a0c9 (patch)
treef4a6a12fd8569b53b95964b6902b4caa963a9701
parentd97fd0c17f23c6d74e8ec09871e9fa58b4231783 (diff)
downloadgnunet-e5d90281a1b8b9d91e4ea754bc7831cf56c4a0c9.tar.gz
gnunet-e5d90281a1b8b9d91e4ea754bc7831cf56c4a0c9.zip
- changes to http
-rw-r--r--src/transport/plugin_transport_http_client.c33
-rw-r--r--src/transport/plugin_transport_http_server.c35
2 files changed, 44 insertions, 24 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 4b10eb52b..7ec0e682e 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -34,7 +34,7 @@
34 34
35#define VERBOSE_CURL GNUNET_YES 35#define VERBOSE_CURL GNUNET_YES
36 36
37#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) 37#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
38 38
39#define ENABLE_PUT GNUNET_YES 39#define ENABLE_PUT GNUNET_YES
40#define ENABLE_GET GNUNET_YES 40#define ENABLE_GET GNUNET_YES
@@ -694,6 +694,8 @@ client_put_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
694 client_schedule (s->plugin, GNUNET_YES); 694 client_schedule (s->plugin, GNUNET_YES);
695} 695}
696 696
697
698
697/** 699/**
698 * Callback method used with libcurl 700 * Callback method used with libcurl
699 * Method is called when libcurl needs to read data during sending 701 * Method is called when libcurl needs to read data during sending
@@ -800,14 +802,13 @@ client_receive_mst_cb (void *cls, void *client,
800 struct HTTP_Client_Plugin *plugin; 802 struct HTTP_Client_Plugin *plugin;
801 struct GNUNET_TIME_Relative delay; 803 struct GNUNET_TIME_Relative delay;
802 struct GNUNET_ATS_Information atsi[2]; 804 struct GNUNET_ATS_Information atsi[2];
803 //GNUNET_break (0);
804 if (GNUNET_YES != client_exist_session(p, s)) 805 if (GNUNET_YES != client_exist_session(p, s))
805 { 806 {
806 GNUNET_break (0); 807 GNUNET_break (0);
807 return GNUNET_OK; 808 return GNUNET_OK;
808 } 809 }
809 plugin = s->plugin; 810 plugin = s->plugin;
810 //GNUNET_break (0); 811
811 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 812 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
812 atsi[0].value = htonl (1); 813 atsi[0].value = htonl (1);
813 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE); 814 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -817,6 +818,7 @@ client_receive_mst_cb (void *cls, void *client,
817 delay = s->plugin->env->receive (plugin->env->cls, &s->target, message, 818 delay = s->plugin->env->receive (plugin->env->cls, &s->target, message,
818 (const struct GNUNET_ATS_Information *) &atsi, 2, 819 (const struct GNUNET_ATS_Information *) &atsi, 2,
819 s, s->addr, s->addrlen); 820 s, s->addr, s->addrlen);
821
820 s->next_receive = 822 s->next_receive =
821 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); 823 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
822 824
@@ -833,10 +835,26 @@ client_receive_mst_cb (void *cls, void *client,
833} 835}
834 836
835 837
838/**
839 * Callback method used with libcurl when data for a PUT connection are
840 * received. We do not expect data here, so we just dismiss it
841 *
842 * @param stream pointer where to write data
843 * @param size size of an individual element
844 * @param nmemb count of elements that can be written to the buffer
845 * @param cls destination pointer, passed to the libcurl handle
846 * @return bytes read from stream
847 */
848static size_t
849client_receive_put (void *stream, size_t size, size_t nmemb, void *cls)
850{
851 return size * nmemb;
852}
853
836 854
837/** 855/**
838 * Callback method used with libcurl 856 * Callback method used with libcurl when data for a GET connection are
839 * Method is called when libcurl needs to write data during sending 857 * received. Forward to MST
840 * 858 *
841 * @param stream pointer where to write data 859 * @param stream pointer where to write data
842 * @param size size of an individual element 860 * @param size size of an individual element
@@ -875,9 +893,8 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls)
875 } 893 }
876 if (NULL == s->msg_tk) 894 if (NULL == s->msg_tk)
877 s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); 895 s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
878 (void) GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); 896 GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
879 return len; 897 return len;
880
881} 898}
882 899
883 900
@@ -1118,7 +1135,7 @@ client_connect_put (struct Session *s)
1118 //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps); 1135 //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps);
1119 curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb); 1136 curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb);
1120 curl_easy_setopt (s->client_put, CURLOPT_READDATA, s); 1137 curl_easy_setopt (s->client_put, CURLOPT_READDATA, s);
1121 curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive); 1138 curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive_put);
1122 curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s); 1139 curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s);
1123 /* No timeout by default, timeout done with session timeout */ 1140 /* No timeout by default, timeout done with session timeout */
1124 curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT, 0); 1141 curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT, 0);
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 6d4549f35..0f2cf7138 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -524,6 +524,11 @@ http_server_plugin_send (void *cls,
524 if (GNUNET_YES == session->server_send->disconnect) 524 if (GNUNET_YES == session->server_send->disconnect)
525 return GNUNET_SYSERR; 525 return GNUNET_SYSERR;
526 526
527 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name,
528 "Session %p/connection %p: Sending message with %u to peer `%s' with \n",
529 session, session->server_send,
530 msgbuf_size, GNUNET_i2s (&session->target));
531
527 /* create new message and schedule */ 532 /* create new message and schedule */
528 bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size; 533 bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size;
529 msg = GNUNET_malloc (bytes_sent); 534 msg = GNUNET_malloc (bytes_sent);
@@ -1167,7 +1172,8 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1167 GNUNET_free (msg); 1172 GNUNET_free (msg);
1168 } 1173 }
1169 } 1174 }
1170 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, 1175 if (0 < bytes_read)
1176 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
1171 "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); 1177 "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s);
1172 return bytes_read; 1178 return bytes_read;
1173} 1179}
@@ -1248,10 +1254,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1248 struct MHD_Response *response; 1254 struct MHD_Response *response;
1249 1255
1250 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1256 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1251 _("Access from connection %p (%u of %u) for %s %s url `%s' \n"), 1257 _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"),
1252 sc, 1258 sc,
1253 plugin->cur_connections, plugin->max_connections, 1259 plugin->cur_connections, plugin->max_connections,
1254 method, version, url); 1260 method, version, url, (*upload_data_size));
1255 1261
1256 GNUNET_assert (cls != NULL); 1262 GNUNET_assert (cls != NULL);
1257 if (sc == NULL) 1263 if (sc == NULL)
@@ -1259,7 +1265,9 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1259 /* new connection */ 1265 /* new connection */
1260 sc = server_lookup_connection (plugin, mhd_connection, url, method); 1266 sc = server_lookup_connection (plugin, mhd_connection, url, method);
1261 if (sc != NULL) 1267 if (sc != NULL)
1268 {
1262 (*httpSessionCache) = sc; 1269 (*httpSessionCache) = sc;
1270 }
1263 else 1271 else
1264 { 1272 {
1265 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); 1273 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
@@ -1281,7 +1289,6 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1281 /* existing connection */ 1289 /* existing connection */
1282 sc = (*httpSessionCache); 1290 sc = (*httpSessionCache);
1283 s = sc->session; 1291 s = sc->session;
1284
1285 GNUNET_assert (NULL != s); 1292 GNUNET_assert (NULL != s);
1286 /* connection is to be disconnected */ 1293 /* connection is to be disconnected */
1287 if (sc->disconnect == GNUNET_YES) 1294 if (sc->disconnect == GNUNET_YES)
@@ -1294,14 +1301,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1294 MHD_destroy_response (response); 1301 MHD_destroy_response (response);
1295 return MHD_YES; 1302 return MHD_YES;
1296 } 1303 }
1297
1298 GNUNET_assert (s != NULL); 1304 GNUNET_assert (s != NULL);
1299 /* Check if both directions are connected */
1300 if ((sc->session->server_recv == NULL) || (sc->session->server_send == NULL))
1301 {
1302 /* Delayed read from since not both semi-connections are connected */
1303 return MHD_YES;
1304 }
1305 1305
1306 if (sc->direction == _SEND) 1306 if (sc->direction == _SEND)
1307 { 1307 {
@@ -1319,7 +1319,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1319 { 1319 {
1320 /* (*upload_data_size == 0) first callback when header are passed */ 1320 /* (*upload_data_size == 0) first callback when header are passed */
1321 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1321 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1322 "Peer `%s' PUT on address `%s' connected\n", 1322 "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n",
1323 s, sc,
1323 GNUNET_i2s (&s->target), 1324 GNUNET_i2s (&s->target),
1324 http_common_plugin_address_to_string (NULL, 1325 http_common_plugin_address_to_string (NULL,
1325 s->addr, 1326 s->addr,
@@ -1331,7 +1332,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1331 { 1332 {
1332 /* (*upload_data_size == 0) when upload is complete */ 1333 /* (*upload_data_size == 0) when upload is complete */
1333 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1334 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1334 "Peer `%s' PUT on address `%s' finished upload\n", 1335 "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n",
1336 s, sc,
1335 GNUNET_i2s (&s->target), 1337 GNUNET_i2s (&s->target),
1336 http_common_plugin_address_to_string (NULL, 1338 http_common_plugin_address_to_string (NULL,
1337 s->addr, 1339 s->addr,
@@ -1349,7 +1351,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1349 { 1351 {
1350 /* (*upload_data_size > 0) for every segment received */ 1352 /* (*upload_data_size > 0) for every segment received */
1351 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1353 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1352 "Peer `%s' PUT on address `%s' received %u bytes\n", 1354 "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n",
1355 s, sc,
1353 GNUNET_i2s (&s->target), 1356 GNUNET_i2s (&s->target),
1354 http_common_plugin_address_to_string (NULL, 1357 http_common_plugin_address_to_string (NULL,
1355 s->addr, 1358 s->addr,
@@ -1376,8 +1379,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1376 else 1379 else
1377 { 1380 {
1378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1379 "%p no inbound bandwidth available! Next read was delayed by %llu ms\n", 1382 "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %llu ms\n",
1380 s, now.abs_value - s->next_receive.abs_value); 1383 s, sc, now.abs_value - s->next_receive.abs_value);
1381 } 1384 }
1382 return MHD_YES; 1385 return MHD_YES;
1383 } 1386 }