From 5d4332d1f19f435eecbb6976416e26d5aee30410 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 15 Sep 2011 12:31:32 +0000 Subject: implemented disconnect notifications for outbound connections --- src/transport/plugin_transport_http.h | 5 +++ src/transport/plugin_transport_http_client.c | 50 +++++++++++++++++++--------- src/transport/plugin_transport_http_new.c | 10 ++++-- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index 3cba2ace0..24752aff3 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h @@ -252,4 +252,9 @@ server_start (struct Plugin *plugin); void server_stop (struct Plugin *plugin); +void +notify_session_end (void *cls, + const struct GNUNET_PeerIdentity * + peer, struct Session * s); + /* end of plugin_transport_http.h */ diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 312d5a78d..ea8a55614 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -158,15 +158,34 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; + do { running = 0; mret = curl_multi_perform (plugin->client_mh, &running); - if ((running < handles_last_run) && (running > 0)) - { - } - //curl_handle_finished (plugin); + CURLMsg * msg; + int msgs_left; + while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left))) + { + CURL *easy_h = msg->easy_handle; + struct Session *s; + GNUNET_assert (easy_h != NULL); + + GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &s)); + GNUNET_assert (s != NULL); + + if (msg->msg == CURLMSG_DONE) + { +#if DEBUG_HTTP + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), http_plugin_address_to_string(s->plugin, s->addr, s->addrlen)); +#endif + client_disconnect(s); + notify_session_end (s->plugin, &s->target, s); + } + } + handles_last_run = running; } while (mret == CURLM_CALL_MULTI_PERFORM); @@ -181,8 +200,8 @@ client_disconnect (struct Session *s) struct Plugin *plugin = s->plugin; #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, - "Deleting outbound session peer `%s'\n", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Deleting outbound PUT session to peer `%s'\n", GNUNET_i2s (&s->target)); #endif @@ -195,6 +214,12 @@ client_disconnect (struct Session *s) } curl_easy_cleanup (s->client_put); +#if DEBUG_HTTP + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Deleting outbound GET session to peer `%s'\n", + GNUNET_i2s (&s->target)); +#endif + mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); if (mret != CURLM_OK) { @@ -225,7 +250,7 @@ client_connect (struct Session *s) CURLMcode mret; #if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Initiating outbound session peer `%s'\n", GNUNET_i2s (&s->target)); #endif @@ -233,12 +258,7 @@ client_connect (struct Session *s) s->inbound = GNUNET_NO; /* create url */ - GNUNET_asprintf (&url, "%s://%s/", s->plugin->protocol, - http_plugin_address_to_string (NULL, s->addr, s->addrlen)); - -#if DEBUG_HTTP - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, "URL `%s'\n", url); -#endif + GNUNET_asprintf (&url, "%s", http_plugin_address_to_string (s->plugin, s->addr, s->addrlen)); /* create get connection */ s->client_get = curl_easy_init (); @@ -261,7 +281,7 @@ client_connect (struct Session *s) //curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, ps); curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); - //curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, ps); + curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s); curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS, (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE, @@ -292,7 +312,7 @@ client_connect (struct Session *s) //curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, ps); curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); - //curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, ps); + curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s); curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS, (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE, diff --git a/src/transport/plugin_transport_http_new.c b/src/transport/plugin_transport_http_new.c index da401575b..37fae8972 100644 --- a/src/transport/plugin_transport_http_new.c +++ b/src/transport/plugin_transport_http_new.c @@ -306,6 +306,8 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) const char * http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { + struct Plugin *plugin = cls; + const struct IPv4HttpAddress *t4; const struct IPv6HttpAddress *t6; struct sockaddr_in a4; @@ -315,6 +317,8 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) uint16_t port; int res; + GNUNET_assert (plugin != NULL); + if (addrlen == sizeof (struct IPv6HttpAddress)) { address = GNUNET_malloc (INET6_ADDRSTRLEN); @@ -338,8 +342,10 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) } GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13)); - - res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", address, port); + if (addrlen == sizeof (struct IPv6HttpAddress)) + res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", plugin->protocol, address, port); + else if (addrlen == sizeof (struct IPv4HttpAddress)) + res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", plugin->protocol, address, port); GNUNET_free (address); GNUNET_assert (res != 0); -- cgit v1.2.3