From e5d90281a1b8b9d91e4ea754bc7831cf56c4a0c9 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 18 Sep 2012 11:08:57 +0000 Subject: - changes to http --- src/transport/plugin_transport_http_client.c | 33 +++++++++++++++++++------- src/transport/plugin_transport_http_server.c | 35 +++++++++++++++------------- 2 files changed, 44 insertions(+), 24 deletions(-) (limited to 'src/transport') 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 @@ #define VERBOSE_CURL GNUNET_YES -#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) +#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) #define ENABLE_PUT GNUNET_YES #define ENABLE_GET GNUNET_YES @@ -694,6 +694,8 @@ client_put_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) client_schedule (s->plugin, GNUNET_YES); } + + /** * Callback method used with libcurl * Method is called when libcurl needs to read data during sending @@ -800,14 +802,13 @@ client_receive_mst_cb (void *cls, void *client, struct HTTP_Client_Plugin *plugin; struct GNUNET_TIME_Relative delay; struct GNUNET_ATS_Information atsi[2]; - //GNUNET_break (0); if (GNUNET_YES != client_exist_session(p, s)) { GNUNET_break (0); return GNUNET_OK; } plugin = s->plugin; - //GNUNET_break (0); + atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); atsi[0].value = htonl (1); atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE); @@ -817,6 +818,7 @@ client_receive_mst_cb (void *cls, void *client, delay = s->plugin->env->receive (plugin->env->cls, &s->target, message, (const struct GNUNET_ATS_Information *) &atsi, 2, s, s->addr, s->addrlen); + s->next_receive = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); @@ -833,10 +835,26 @@ client_receive_mst_cb (void *cls, void *client, } +/** + * Callback method used with libcurl when data for a PUT connection are + * received. We do not expect data here, so we just dismiss it + * + * @param stream pointer where to write data + * @param size size of an individual element + * @param nmemb count of elements that can be written to the buffer + * @param cls destination pointer, passed to the libcurl handle + * @return bytes read from stream + */ +static size_t +client_receive_put (void *stream, size_t size, size_t nmemb, void *cls) +{ + return size * nmemb; +} + /** - * Callback method used with libcurl - * Method is called when libcurl needs to write data during sending + * Callback method used with libcurl when data for a GET connection are + * received. Forward to MST * * @param stream pointer where to write data * @param size size of an individual element @@ -875,9 +893,8 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) } if (NULL == s->msg_tk) s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); - (void) GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); + GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); return len; - } @@ -1118,7 +1135,7 @@ client_connect_put (struct Session *s) //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps); curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb); curl_easy_setopt (s->client_put, CURLOPT_READDATA, s); - curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive); + curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive_put); curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s); /* No timeout by default, timeout done with session timeout */ 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, if (GNUNET_YES == session->server_send->disconnect) return GNUNET_SYSERR; + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name, + "Session %p/connection %p: Sending message with %u to peer `%s' with \n", + session, session->server_send, + msgbuf_size, GNUNET_i2s (&session->target)); + /* create new message and schedule */ bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size; msg = GNUNET_malloc (bytes_sent); @@ -1167,7 +1172,8 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) GNUNET_free (msg); } } - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, + if (0 < bytes_read) + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); return bytes_read; } @@ -1248,10 +1254,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, struct MHD_Response *response; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - _("Access from connection %p (%u of %u) for %s %s url `%s' \n"), + _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), sc, plugin->cur_connections, plugin->max_connections, - method, version, url); + method, version, url, (*upload_data_size)); GNUNET_assert (cls != NULL); if (sc == NULL) @@ -1259,7 +1265,9 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, /* new connection */ sc = server_lookup_connection (plugin, mhd_connection, url, method); if (sc != NULL) + { (*httpSessionCache) = sc; + } else { 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, /* existing connection */ sc = (*httpSessionCache); s = sc->session; - GNUNET_assert (NULL != s); /* connection is to be disconnected */ if (sc->disconnect == GNUNET_YES) @@ -1294,14 +1301,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, MHD_destroy_response (response); return MHD_YES; } - GNUNET_assert (s != NULL); - /* Check if both directions are connected */ - if ((sc->session->server_recv == NULL) || (sc->session->server_send == NULL)) - { - /* Delayed read from since not both semi-connections are connected */ - return MHD_YES; - } if (sc->direction == _SEND) { @@ -1319,7 +1319,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, { /* (*upload_data_size == 0) first callback when header are passed */ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Peer `%s' PUT on address `%s' connected\n", + "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n", + s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, s->addr, @@ -1331,7 +1332,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, { /* (*upload_data_size == 0) when upload is complete */ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Peer `%s' PUT on address `%s' finished upload\n", + "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", + s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, s->addr, @@ -1349,7 +1351,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, { /* (*upload_data_size > 0) for every segment received */ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Peer `%s' PUT on address `%s' received %u bytes\n", + "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", + s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, s->addr, @@ -1376,8 +1379,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%p no inbound bandwidth available! Next read was delayed by %llu ms\n", - s, now.abs_value - s->next_receive.abs_value); + "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %llu ms\n", + s, sc, now.abs_value - s->next_receive.abs_value); } return MHD_YES; } -- cgit v1.2.3