From 5c9b9bac3b0a6f1e090342e460f6393c68492797 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 26 Sep 2011 15:58:11 +0000 Subject: fixed: - session matching - curl send handle suspending --- src/transport/plugin_transport_http.h | 2 +- src/transport/plugin_transport_http_client.c | 49 ++++++++++++++++++++-------- src/transport/plugin_transport_http_new.c | 16 ++++++--- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index 249b92c9d..7120accfb 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h @@ -244,7 +244,7 @@ struct Session void *client_put; void *client_get; - int put_paused; + int client_put_paused; void *server_recv; void *server_send; diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index e4942248a..0643663b3 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -61,15 +61,6 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls) } #endif -int -client_send (struct Session *s, struct HTTP_Message *msg) -{ - GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); - if (s != NULL) - curl_easy_pause(s->client_put, CURLPAUSE_CONT); - return GNUNET_OK; -} - /** * Task performing curl operations * @param cls plugin as closure @@ -148,6 +139,25 @@ client_schedule (struct Plugin *plugin) } +int +client_send (struct Session *s, struct HTTP_Message *msg) +{ + GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); + + if ((s != NULL) && (s->client_put_paused == GNUNET_YES)) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Client: %X was suspended, unpausing\n", s->client_put); + s->client_put_paused = GNUNET_NO; + curl_easy_pause(s->client_put, CURLPAUSE_CONT); + } + + client_schedule (s->plugin); + + return GNUNET_OK; +} + + + /** * Task performing curl operations * @param cls plugin as closure @@ -335,16 +345,19 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) struct Session *s = cls; struct Plugin *plugin = s->plugin; struct GNUNET_TIME_Absolute now; + size_t len = size * nmemb; + #if VERBOSE_CLIENT GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: Received %Zu bytes from peer `%s'\n", - size * nmemb, + len, GNUNET_i2s (&s->target)); #endif now = GNUNET_TIME_absolute_get(); if (now.abs_value < s->delay.abs_value) { +#if 0 #if DEBUG_CLIENT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No inbound bandwidth available! Next read was delayed for %llu ms\n", @@ -357,16 +370,19 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) } s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed( GNUNET_TIME_absolute_get_difference(s->delay, now), &client_wake_up, s); return CURLPAUSE_ALL; +#endif } if (s->msg_tk == NULL) s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); - GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, size * nmemb, GNUNET_NO, + GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); - return (size * nmemb); + return len; + + client_wake_up (NULL, NULL); } /** @@ -376,7 +392,7 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) * @param size size of an individual element * @param nmemb count of elements that can be written to the buffer * @param ptr source pointer, passed to the libcurl handle - * @return bytes written to stream + * @return bytes written to stream, returning 0 will terminate connection! */ static size_t client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) @@ -401,7 +417,12 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) } */ if (msg == NULL) - return bytes_sent; + { + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put); + s->client_put_paused = GNUNET_YES; + return CURL_READFUNC_PAUSE; + } + GNUNET_assert (msg != NULL); /* data to send */ if (msg->pos < msg->size) diff --git a/src/transport/plugin_transport_http_new.c b/src/transport/plugin_transport_http_new.c index 2c7037694..042c977f5 100644 --- a/src/transport/plugin_transport_http_new.c +++ b/src/transport/plugin_transport_http_new.c @@ -340,6 +340,12 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, return NULL; while (t != NULL) { +#if 0 + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, + "Comparing peer `%s' address `%s' len %i session %X to \n", GNUNET_i2s(target), GNUNET_a2s(addr,addrlen), addrlen, session); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"peer `%s' address `%s' len %i session %X \n\n", GNUNET_i2s(&t->target), GNUNET_a2s(t->addr,t->addrlen), t->addrlen, t); + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"memcmp %i \n", memcmp (addr, t->addr, addrlen)); +#endif e_peer = GNUNET_NO; e_addr = GNUNET_NO; @@ -348,7 +354,7 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, e_peer = GNUNET_YES; if (addrlen == t->addrlen) { - if (0 == memcmp (addr, &t->addr, addrlen)) + if (0 == memcmp (addr, t->addr, addrlen)) { e_addr = GNUNET_YES; } @@ -492,7 +498,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, s = lookup_session (plugin, target, session, addr, addrlen, 1); #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "%s exisiting session\n", (s!=NULL) ? "Found" : "NOT Found"); + "%s existing session: %s\n", (s!=NULL) ? "Found" : "NOT Found", ((s != NULL) && (s->inbound == GNUNET_YES)) ? "inbound" : "outbound"); #endif /* create new outbound connection */ @@ -749,7 +755,7 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr, { GNUNET_assert (cls != NULL); struct Plugin *plugin = cls; - //static int limit; + static int limit; #if DEBUG_HTTP GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "NPMC called %s to address `%s'\n", @@ -761,9 +767,9 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr, { case GNUNET_YES: // FIXME DEBUGGING - //if (limit < 1) + if (limit < 1) nat_add_address (cls, add_remove, addr, addrlen); - //limit++; + limit++; // FIXME END break; case GNUNET_NO: -- cgit v1.2.3