diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-27 15:02:56 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-27 15:02:56 +0000 |
commit | 3e9940cb3859618e37cc35cb45ef6d62ff92677c (patch) | |
tree | d107c9a76a44f445720cb59de0a7835123198d0f /src/transport/plugin_transport_http_client.c | |
parent | b3bc7b843015205ed9bbf0f08e20d84c7ad5ac7f (diff) | |
download | gnunet-3e9940cb3859618e37cc35cb45ef6d62ff92677c.tar.gz gnunet-3e9940cb3859618e37cc35cb45ef6d62ff92677c.zip |
changes
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index fc954498c..3e4de2cf7 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | 35 | ||
36 | #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 36 | #define VERBOSE_CURL GNUNET_YES |
37 | 37 | ||
38 | #include "platform.h" | 38 | #include "platform.h" |
39 | #include "gnunet_protocols.h" | 39 | #include "gnunet_protocols.h" |
@@ -309,6 +309,43 @@ client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s) | |||
309 | return GNUNET_NO; | 309 | return GNUNET_NO; |
310 | } | 310 | } |
311 | 311 | ||
312 | #if VERBOSE_CURL | ||
313 | /** | ||
314 | * Function to log curl debug messages with GNUNET_log | ||
315 | * @param curl handle | ||
316 | * @param type curl_infotype | ||
317 | * @param data data | ||
318 | * @param size size | ||
319 | * @param cls closure | ||
320 | * @return 0 | ||
321 | */ | ||
322 | static int | ||
323 | client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls) | ||
324 | { | ||
325 | if (type == CURLINFO_TEXT) | ||
326 | { | ||
327 | char text[size + 2]; | ||
328 | |||
329 | memcpy (text, data, size); | ||
330 | if (text[size - 1] == '\n') | ||
331 | text[size] = '\0'; | ||
332 | else | ||
333 | { | ||
334 | text[size] = '\n'; | ||
335 | text[size + 1] = '\0'; | ||
336 | } | ||
337 | #if BUILD_HTTPS | ||
338 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https_client", | ||
339 | "Connection: %p - %s", cls, text); | ||
340 | #else | ||
341 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http_client", | ||
342 | "Connection %p: - %s", cls, text); | ||
343 | #endif | ||
344 | } | ||
345 | return 0; | ||
346 | } | ||
347 | #endif | ||
348 | |||
312 | /** | 349 | /** |
313 | * Function that can be used by the transport service to transmit | 350 | * Function that can be used by the transport service to transmit |
314 | * a message using the plugin. Note that in the case of a | 351 | * a message using the plugin. Note that in the case of a |
@@ -435,7 +472,7 @@ client_disconnect (struct Session *s) | |||
435 | int res = GNUNET_OK; | 472 | int res = GNUNET_OK; |
436 | CURLMcode mret; | 473 | CURLMcode mret; |
437 | 474 | ||
438 | if (GNUNET_YES != client_exist_session(plugin, s)) | 475 | if (GNUNET_YES != client_exist_session (plugin, s)) |
439 | { | 476 | { |
440 | GNUNET_break (0); | 477 | GNUNET_break (0); |
441 | return GNUNET_SYSERR; | 478 | return GNUNET_SYSERR; |
@@ -699,8 +736,6 @@ client_receive_mst_cb (void *cls, void *client, | |||
699 | static size_t | 736 | static size_t |
700 | client_receive (void *stream, size_t size, size_t nmemb, void *cls) | 737 | client_receive (void *stream, size_t size, size_t nmemb, void *cls) |
701 | { | 738 | { |
702 | return 0; | ||
703 | |||
704 | struct Session *s = cls; | 739 | struct Session *s = cls; |
705 | struct GNUNET_TIME_Absolute now; | 740 | struct GNUNET_TIME_Absolute now; |
706 | size_t len = size * nmemb; | 741 | size_t len = size * nmemb; |
@@ -932,10 +967,10 @@ client_connect (struct Session *s) | |||
932 | curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, client_receive); | 967 | curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, client_receive); |
933 | curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s); | 968 | curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s); |
934 | curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, | 969 | curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, |
935 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); | 970 | (long) CLIENT_SESSION_TIMEOUT.rel_value); |
936 | curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s); | 971 | curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s); |
937 | curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS, | 972 | curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS, |
938 | (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); | 973 | (long) HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value); |
939 | curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE, | 974 | curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE, |
940 | 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); | 975 | 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); |
941 | #if CURL_TCP_NODELAY | 976 | #if CURL_TCP_NODELAY |
@@ -963,10 +998,10 @@ client_connect (struct Session *s) | |||
963 | curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive); | 998 | curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive); |
964 | curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s); | 999 | curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s); |
965 | curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, | 1000 | curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, |
966 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); | 1001 | (long) CLIENT_SESSION_TIMEOUT.rel_value); |
967 | curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s); | 1002 | curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s); |
968 | curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS, | 1003 | curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS, |
969 | (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value); | 1004 | (long) HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value); |
970 | curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE, | 1005 | curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE, |
971 | 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); | 1006 | 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); |
972 | #if CURL_TCP_NODELAY | 1007 | #if CURL_TCP_NODELAY |
@@ -1104,7 +1139,7 @@ client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1104 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1139 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1105 | GNUNET_log (TIMEOUT_LOG, | 1140 | GNUNET_log (TIMEOUT_LOG, |
1106 | "Session %p was idle for %llu ms, disconnecting\n", | 1141 | "Session %p was idle for %llu ms, disconnecting\n", |
1107 | s, (unsigned long long) TIMEOUT.rel_value); | 1142 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); |
1108 | 1143 | ||
1109 | /* call session destroy function */ | 1144 | /* call session destroy function */ |
1110 | GNUNET_assert (GNUNET_OK == client_disconnect (s)); | 1145 | GNUNET_assert (GNUNET_OK == client_disconnect (s)); |
@@ -1119,12 +1154,12 @@ client_start_session_timeout (struct Session *s) | |||
1119 | 1154 | ||
1120 | GNUNET_assert (NULL != s); | 1155 | GNUNET_assert (NULL != s); |
1121 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); | 1156 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); |
1122 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 1157 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (CLIENT_SESSION_TIMEOUT, |
1123 | &client_session_timeout, | 1158 | &client_session_timeout, |
1124 | s); | 1159 | s); |
1125 | GNUNET_log (TIMEOUT_LOG, | 1160 | GNUNET_log (TIMEOUT_LOG, |
1126 | "Timeout for session %p set to %llu ms\n", | 1161 | "Timeout for session %p set to %llu ms\n", |
1127 | s, (unsigned long long) TIMEOUT.rel_value); | 1162 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); |
1128 | } | 1163 | } |
1129 | 1164 | ||
1130 | /** | 1165 | /** |
@@ -1138,12 +1173,12 @@ client_reschedule_session_timeout (struct Session *s) | |||
1138 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | 1173 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); |
1139 | 1174 | ||
1140 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 1175 | GNUNET_SCHEDULER_cancel (s->timeout_task); |
1141 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 1176 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (CLIENT_SESSION_TIMEOUT, |
1142 | &client_session_timeout, | 1177 | &client_session_timeout, |
1143 | s); | 1178 | s); |
1144 | GNUNET_log (TIMEOUT_LOG, | 1179 | GNUNET_log (TIMEOUT_LOG, |
1145 | "Timeout rescheduled for session %p set to %llu ms\n", | 1180 | "Timeout rescheduled for session %p set to %llu ms\n", |
1146 | s, (unsigned long long) TIMEOUT.rel_value); | 1181 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); |
1147 | } | 1182 | } |
1148 | 1183 | ||
1149 | /** | 1184 | /** |
@@ -1199,20 +1234,26 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1199 | _("Shutting down plugin `%s'\n"), | 1234 | _("Shutting down plugin `%s'\n"), |
1200 | plugin->name); | 1235 | plugin->name); |
1201 | 1236 | ||
1237 | if (NULL == api->cls) | ||
1238 | { | ||
1239 | /* Stub shutdown */ | ||
1240 | GNUNET_free (api); | ||
1241 | return NULL; | ||
1242 | } | ||
1243 | |||
1202 | next = plugin->head; | 1244 | next = plugin->head; |
1203 | while (NULL != (pos = next)) | 1245 | while (NULL != (pos = next)) |
1204 | { | 1246 | { |
1205 | next = pos->next; | 1247 | next = pos->next; |
1206 | GNUNET_CONTAINER_DLL_remove( plugin->head, plugin->tail, pos); | ||
1207 | client_disconnect (pos); | 1248 | client_disconnect (pos); |
1208 | } | 1249 | } |
1209 | 1250 | if (GNUNET_SCHEDULER_NO_TASK != plugin->client_perform_task) | |
1210 | if (NULL == api->cls) | ||
1211 | { | 1251 | { |
1212 | GNUNET_free (api); | 1252 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); |
1213 | return NULL; | 1253 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
1214 | } | 1254 | } |
1215 | 1255 | ||
1256 | |||
1216 | if (NULL != plugin->curl_multi_handle) | 1257 | if (NULL != plugin->curl_multi_handle) |
1217 | { | 1258 | { |
1218 | curl_multi_cleanup (plugin->curl_multi_handle); | 1259 | curl_multi_cleanup (plugin->curl_multi_handle); |