diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-15 12:31:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-15 12:31:32 +0000 |
commit | 5d4332d1f19f435eecbb6976416e26d5aee30410 (patch) | |
tree | 6f9bcdbac5bc09eee5f3c0514de54b241ca287f7 | |
parent | 12c5d5b026fae9066ad279298197fd5ca407479d (diff) | |
download | gnunet-5d4332d1f19f435eecbb6976416e26d5aee30410.tar.gz gnunet-5d4332d1f19f435eecbb6976416e26d5aee30410.zip |
implemented disconnect notifications for outbound connections
-rw-r--r-- | src/transport/plugin_transport_http.h | 5 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 50 | ||||
-rw-r--r-- | 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); | |||
252 | void | 252 | void |
253 | server_stop (struct Plugin *plugin); | 253 | server_stop (struct Plugin *plugin); |
254 | 254 | ||
255 | void | ||
256 | notify_session_end (void *cls, | ||
257 | const struct GNUNET_PeerIdentity * | ||
258 | peer, struct Session * s); | ||
259 | |||
255 | /* end of plugin_transport_http.h */ | 260 | /* 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) | |||
158 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; | 158 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
159 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 159 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
160 | return; | 160 | return; |
161 | |||
161 | do | 162 | do |
162 | { | 163 | { |
163 | running = 0; | 164 | running = 0; |
164 | mret = curl_multi_perform (plugin->client_mh, &running); | 165 | mret = curl_multi_perform (plugin->client_mh, &running); |
165 | if ((running < handles_last_run) && (running > 0)) | ||
166 | { | ||
167 | 166 | ||
168 | } | 167 | CURLMsg * msg; |
169 | //curl_handle_finished (plugin); | 168 | int msgs_left; |
169 | while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left))) | ||
170 | { | ||
171 | CURL *easy_h = msg->easy_handle; | ||
172 | struct Session *s; | ||
173 | GNUNET_assert (easy_h != NULL); | ||
174 | |||
175 | GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &s)); | ||
176 | GNUNET_assert (s != NULL); | ||
177 | |||
178 | if (msg->msg == CURLMSG_DONE) | ||
179 | { | ||
180 | #if DEBUG_HTTP | ||
181 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | ||
182 | "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), http_plugin_address_to_string(s->plugin, s->addr, s->addrlen)); | ||
183 | #endif | ||
184 | client_disconnect(s); | ||
185 | notify_session_end (s->plugin, &s->target, s); | ||
186 | } | ||
187 | } | ||
188 | |||
170 | handles_last_run = running; | 189 | handles_last_run = running; |
171 | } | 190 | } |
172 | while (mret == CURLM_CALL_MULTI_PERFORM); | 191 | while (mret == CURLM_CALL_MULTI_PERFORM); |
@@ -181,8 +200,8 @@ client_disconnect (struct Session *s) | |||
181 | struct Plugin *plugin = s->plugin; | 200 | struct Plugin *plugin = s->plugin; |
182 | 201 | ||
183 | #if DEBUG_HTTP | 202 | #if DEBUG_HTTP |
184 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 203 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
185 | "Deleting outbound session peer `%s'\n", | 204 | "Deleting outbound PUT session to peer `%s'\n", |
186 | GNUNET_i2s (&s->target)); | 205 | GNUNET_i2s (&s->target)); |
187 | #endif | 206 | #endif |
188 | 207 | ||
@@ -195,6 +214,12 @@ client_disconnect (struct Session *s) | |||
195 | } | 214 | } |
196 | curl_easy_cleanup (s->client_put); | 215 | curl_easy_cleanup (s->client_put); |
197 | 216 | ||
217 | #if DEBUG_HTTP | ||
218 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | ||
219 | "Deleting outbound GET session to peer `%s'\n", | ||
220 | GNUNET_i2s (&s->target)); | ||
221 | #endif | ||
222 | |||
198 | mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); | 223 | mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); |
199 | if (mret != CURLM_OK) | 224 | if (mret != CURLM_OK) |
200 | { | 225 | { |
@@ -225,7 +250,7 @@ client_connect (struct Session *s) | |||
225 | CURLMcode mret; | 250 | CURLMcode mret; |
226 | 251 | ||
227 | #if DEBUG_HTTP | 252 | #if DEBUG_HTTP |
228 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, | 253 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
229 | "Initiating outbound session peer `%s'\n", | 254 | "Initiating outbound session peer `%s'\n", |
230 | GNUNET_i2s (&s->target)); | 255 | GNUNET_i2s (&s->target)); |
231 | #endif | 256 | #endif |
@@ -233,12 +258,7 @@ client_connect (struct Session *s) | |||
233 | s->inbound = GNUNET_NO; | 258 | s->inbound = GNUNET_NO; |
234 | 259 | ||
235 | /* create url */ | 260 | /* create url */ |
236 | GNUNET_asprintf (&url, "%s://%s/", s->plugin->protocol, | 261 | GNUNET_asprintf (&url, "%s", http_plugin_address_to_string (s->plugin, s->addr, s->addrlen)); |
237 | http_plugin_address_to_string (NULL, s->addr, s->addrlen)); | ||
238 | |||
239 | #if DEBUG_HTTP | ||
240 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, "URL `%s'\n", url); | ||
241 | #endif | ||
242 | 262 | ||
243 | /* create get connection */ | 263 | /* create get connection */ |
244 | s->client_get = curl_easy_init (); | 264 | s->client_get = curl_easy_init (); |
@@ -261,7 +281,7 @@ client_connect (struct Session *s) | |||
261 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, ps); | 281 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, ps); |
262 | curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, | 282 | curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, |
263 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); | 283 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); |
264 | //curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, ps); | 284 | curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s); |
265 | curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS, | 285 | curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS, |
266 | (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); | 286 | (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); |
267 | curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE, | 287 | curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE, |
@@ -292,7 +312,7 @@ client_connect (struct Session *s) | |||
292 | //curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, ps); | 312 | //curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, ps); |
293 | curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, | 313 | curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, |
294 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); | 314 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); |
295 | //curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, ps); | 315 | curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s); |
296 | curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS, | 316 | curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS, |
297 | (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); | 317 | (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); |
298 | curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE, | 318 | 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) | |||
306 | const char * | 306 | const char * |
307 | http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 307 | http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
308 | { | 308 | { |
309 | struct Plugin *plugin = cls; | ||
310 | |||
309 | const struct IPv4HttpAddress *t4; | 311 | const struct IPv4HttpAddress *t4; |
310 | const struct IPv6HttpAddress *t6; | 312 | const struct IPv6HttpAddress *t6; |
311 | struct sockaddr_in a4; | 313 | struct sockaddr_in a4; |
@@ -315,6 +317,8 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
315 | uint16_t port; | 317 | uint16_t port; |
316 | int res; | 318 | int res; |
317 | 319 | ||
320 | GNUNET_assert (plugin != NULL); | ||
321 | |||
318 | if (addrlen == sizeof (struct IPv6HttpAddress)) | 322 | if (addrlen == sizeof (struct IPv6HttpAddress)) |
319 | { | 323 | { |
320 | address = GNUNET_malloc (INET6_ADDRSTRLEN); | 324 | address = GNUNET_malloc (INET6_ADDRSTRLEN); |
@@ -338,8 +342,10 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
338 | } | 342 | } |
339 | 343 | ||
340 | GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13)); | 344 | GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13)); |
341 | 345 | if (addrlen == sizeof (struct IPv6HttpAddress)) | |
342 | res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", address, port); | 346 | res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", plugin->protocol, address, port); |
347 | else if (addrlen == sizeof (struct IPv4HttpAddress)) | ||
348 | res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", plugin->protocol, address, port); | ||
343 | 349 | ||
344 | GNUNET_free (address); | 350 | GNUNET_free (address); |
345 | GNUNET_assert (res != 0); | 351 | GNUNET_assert (res != 0); |