aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/plugin_transport_http_client.c77
-rw-r--r--src/transport/plugin_transport_http_common.h23
-rw-r--r--src/transport/plugin_transport_http_server.c27
3 files changed, 94 insertions, 33 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 */
322static int
323client_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,
699static size_t 736static size_t
700client_receive (void *stream, size_t size, size_t nmemb, void *cls) 737client_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);
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h
index 0f83da6b3..edb99c5f2 100644
--- a/src/transport/plugin_transport_http_common.h
+++ b/src/transport/plugin_transport_http_common.h
@@ -27,16 +27,27 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29 29
30#define TESTING GNUNET_NO 30/**
31 * Timeout values for testing
32 */
33#define TESTING GNUNET_YES
31 34
32#if TESTING 35#if TESTING
33#define TIMEOUT_LOG GNUNET_ERROR_TYPE_ERROR 36
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 37#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
35#define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 38#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
39#define CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
40#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
41#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
42
36#else 43#else
37#define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 44
45#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
46#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
47#define CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
48#define SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
38#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG 49#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
39#define TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT 50
40#endif 51#endif
41 52
42/** 53/**
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index d2c5e9c9b..2ce844307 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -990,7 +990,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
990#if MHD_VERSION >= 0x00090E00 990#if MHD_VERSION >= 0x00090E00
991 if ((NULL == s->server_recv) || (NULL == s->server_send)) 991 if ((NULL == s->server_recv) || (NULL == s->server_send))
992 { 992 {
993 to = (HTTP_NOT_VALIDATED_TIMEOUT.rel_value / 1000); 993 to = (HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value / 1000);
994 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to); 994 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to);
995 server_reschedule (plugin, sc->mhd_daemon, GNUNET_NO); 995 server_reschedule (plugin, sc->mhd_daemon, GNUNET_NO);
996 } 996 }
@@ -999,7 +999,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
999 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 999 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1000 "Session %p for peer `%s' fully connected\n", 1000 "Session %p for peer `%s' fully connected\n",
1001 s, GNUNET_i2s (&target)); 1001 s, GNUNET_i2s (&target));
1002 to = (TIMEOUT.rel_value / 1000); 1002 to = (SERVER_SESSION_TIMEOUT.rel_value / 1000);
1003 server_mhd_connection_timeout (plugin, s, to); 1003 server_mhd_connection_timeout (plugin, s, to);
1004 } 1004 }
1005 1005
@@ -1689,12 +1689,12 @@ server_start (struct HTTP_Server_Plugin *plugin)
1689 1689
1690 1690
1691#if MHD_VERSION >= 0x00090E00 1691#if MHD_VERSION >= 0x00090E00
1692 timeout = HTTP_NOT_VALIDATED_TIMEOUT.rel_value / 1000; 1692 timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value / 1000;
1693 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1693 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1694 "MHD can set timeout per connection! Default time out %u sec.\n", 1694 "MHD can set timeout per connection! Default time out %u sec.\n",
1695 timeout); 1695 timeout);
1696#else 1696#else
1697 timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000; 1697 timeout = SERVER_SESSION_TIMEOUT.rel_value / 1000;
1698 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, 1698 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
1699 "MHD cannot set timeout per connection! Default time out %u sec.\n", 1699 "MHD cannot set timeout per connection! Default time out %u sec.\n",
1700 timeout); 1700 timeout);
@@ -2418,7 +2418,7 @@ server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
2418 s->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2418 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2419 GNUNET_log (TIMEOUT_LOG, 2419 GNUNET_log (TIMEOUT_LOG,
2420 "Session %p was idle for %llu ms, disconnecting\n", 2420 "Session %p was idle for %llu ms, disconnecting\n",
2421 s, (unsigned long long) TIMEOUT.rel_value); 2421 s, (unsigned long long) SERVER_SESSION_TIMEOUT.rel_value);
2422 2422
2423 /* call session destroy function */ 2423 /* call session destroy function */
2424 GNUNET_assert (GNUNET_OK == server_disconnect (s)); 2424 GNUNET_assert (GNUNET_OK == server_disconnect (s));
@@ -2432,12 +2432,12 @@ server_start_session_timeout (struct Session *s)
2432{ 2432{
2433 GNUNET_assert (NULL != s); 2433 GNUNET_assert (NULL != s);
2434 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); 2434 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
2435 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 2435 s->timeout_task = GNUNET_SCHEDULER_add_delayed (SERVER_SESSION_TIMEOUT,
2436 &server_session_timeout, 2436 &server_session_timeout,
2437 s); 2437 s);
2438 GNUNET_log (TIMEOUT_LOG, 2438 GNUNET_log (TIMEOUT_LOG,
2439 "Timeout for session %p set to %llu ms\n", 2439 "Timeout for session %p set to %llu ms\n",
2440 s, (unsigned long long) TIMEOUT.rel_value); 2440 s, (unsigned long long) SERVER_SESSION_TIMEOUT.rel_value);
2441} 2441}
2442 2442
2443 2443
@@ -2451,12 +2451,12 @@ server_reschedule_session_timeout (struct Session *s)
2451 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); 2451 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
2452 2452
2453 GNUNET_SCHEDULER_cancel (s->timeout_task); 2453 GNUNET_SCHEDULER_cancel (s->timeout_task);
2454 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 2454 s->timeout_task = GNUNET_SCHEDULER_add_delayed (SERVER_SESSION_TIMEOUT,
2455 &server_session_timeout, 2455 &server_session_timeout,
2456 s); 2456 s);
2457 GNUNET_log (TIMEOUT_LOG, 2457 GNUNET_log (TIMEOUT_LOG,
2458 "Timeout rescheduled for session %p set to %llu ms\n", 2458 "Timeout rescheduled for session %p set to %llu ms\n",
2459 s, (unsigned long long) TIMEOUT.rel_value); 2459 s, (unsigned long long) SERVER_SESSION_TIMEOUT.rel_value);
2460} 2460}
2461 2461
2462/** 2462/**
@@ -2472,10 +2472,15 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2472 2472
2473 if (NULL == api->cls) 2473 if (NULL == api->cls)
2474 { 2474 {
2475 /* Free for stub mode */
2475 GNUNET_free (api); 2476 GNUNET_free (api);
2476 return NULL; 2477 return NULL;
2477 } 2478 }
2478 2479
2480 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2481 _("Shutting down plugin `%s'\n"),
2482 plugin->name);
2483
2479 if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task) 2484 if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task)
2480 { 2485 {
2481 GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); 2486 GNUNET_SCHEDULER_cancel (plugin->notify_ext_task);
@@ -2515,6 +2520,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2515 GNUNET_free_non_null (plugin->server_addr_v4); 2520 GNUNET_free_non_null (plugin->server_addr_v4);
2516 GNUNET_free_non_null (plugin->server_addr_v6); 2521 GNUNET_free_non_null (plugin->server_addr_v6);
2517 2522
2523 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2524 _("Shutdown for plugin `%s' complete\n"),
2525 plugin->name);
2526
2518 GNUNET_free (plugin); 2527 GNUNET_free (plugin);
2519 GNUNET_free (api); 2528 GNUNET_free (api);
2520 return NULL; 2529 return NULL;