aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-07-13 11:29:51 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-07-13 11:29:51 +0000
commit91291b85b253b88411362e965e543268330a6254 (patch)
tree6dbcca97a996c49bb86e33c456968944434df2f2 /src/transport
parent11321385c74932ce2ae0491e16e29fcb4bdf2f9c (diff)
downloadgnunet-91291b85b253b88411362e965e543268330a6254.tar.gz
gnunet-91291b85b253b88411362e965e543268330a6254.zip
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_http.c62
-rw-r--r--src/transport/test_plugin_transport_http.c7
2 files changed, 45 insertions, 24 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 2aeb44579..44914f2f3 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -40,8 +40,8 @@
40#include <curl/curl.h> 40#include <curl/curl.h>
41 41
42 42
43#define DEBUG_CURL GNUNET_NO 43#define DEBUG_CURL GNUNET_YES
44#define DEBUG_HTTP GNUNET_NO 44#define DEBUG_HTTP GNUNET_YES
45#define DEBUG_CONNECTIONS GNUNET_YES 45#define DEBUG_CONNECTIONS GNUNET_YES
46 46
47#define INBOUND GNUNET_NO 47#define INBOUND GNUNET_NO
@@ -71,6 +71,11 @@
71 */ 71 */
72#define HTTP_CONNECT_TIMEOUT 30 72#define HTTP_CONNECT_TIMEOUT 30
73 73
74#ifdef GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
75#undef GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
76#endif
77#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
78
74/** 79/**
75 * Network format for IPv4 addresses. 80 * Network format for IPv4 addresses.
76 */ 81 */
@@ -304,6 +309,11 @@ struct Plugin
304 */ 309 */
305 struct GNUNET_TRANSPORT_PluginEnvironment *env; 310 struct GNUNET_TRANSPORT_PluginEnvironment *env;
306 311
312 /**
313 * Handle for reporting statistics.
314 */
315 struct GNUNET_STATISTICS_Handle *stats;
316
307 unsigned int port_inbound; 317 unsigned int port_inbound;
308 318
309 struct GNUNET_CONTAINER_MultiHashMap *peers; 319 struct GNUNET_CONTAINER_MultiHashMap *peers;
@@ -400,7 +410,7 @@ static int remove_http_message (struct Session * ps, struct HTTP_Message * msg)
400static int remove_session (struct HTTP_PeerContext * pc, struct Session * ps, int call_msg_cont, int call_msg_cont_result) 410static int remove_session (struct HTTP_PeerContext * pc, struct Session * ps, int call_msg_cont, int call_msg_cont_result)
401{ 411{
402 struct HTTP_Message * msg; 412 struct HTTP_Message * msg;
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: removing %s session with id %u\n", ps, (ps->direction == INBOUND) ? "inbound" : "outbound",ps->session_id); 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: removing %s session %X with id %u\n", ps, (ps->direction == INBOUND) ? "inbound" : "outbound", ps, ps->session_id);
404 GNUNET_free_non_null (ps->addr); 414 GNUNET_free_non_null (ps->addr);
405 GNUNET_SERVER_mst_destroy (ps->msgtok); 415 GNUNET_SERVER_mst_destroy (ps->msgtok);
406 GNUNET_free(ps->url); 416 GNUNET_free(ps->url);
@@ -799,7 +809,7 @@ mdh_access_cb (void *cls,
799 } 809 }
800 if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) 810 if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
801 { 811 {
802 if (ps->send_force_disconnect) 812 if (ps->send_force_disconnect == GNUNET_YES)
803 { 813 {
804#if DEBUG_CONNECTIONS 814#if DEBUG_CONNECTIONS
805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound connection was forced to disconnect\n",ps); 815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound connection was forced to disconnect\n",ps);
@@ -807,16 +817,19 @@ mdh_access_cb (void *cls,
807 ps->send_active = GNUNET_NO; 817 ps->send_active = GNUNET_NO;
808 return MHD_NO; 818 return MHD_NO;
809 } 819 }
810 ps->send_connected = GNUNET_YES; 820 else
811 ps->send_active = GNUNET_YES; 821 {
812 ps->send_endpoint = mhd_connection; 822 ps->send_connected = GNUNET_YES;
823 ps->send_active = GNUNET_YES;
824 ps->send_endpoint = mhd_connection;
813#if DEBUG_CONNECTIONS 825#if DEBUG_CONNECTIONS
814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound GET connection connected\n",ps); 826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound GET connection connected\n",ps);
815#endif 827#endif
816 response = MHD_create_response_from_callback(-1,32 * 1024, &mhd_send_callback, ps, NULL); 828 response = MHD_create_response_from_callback(-1,32 * 1024, &mhd_send_callback, ps, NULL);
817 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 829 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
818 MHD_destroy_response (response); 830 MHD_destroy_response (response);
819 return MHD_YES; 831 return MHD_YES;
832 }
820 } 833 }
821 return MHD_NO; 834 return MHD_NO;
822} 835}
@@ -1154,7 +1167,7 @@ static size_t curl_receive_cb( void *stream, size_t size, size_t nmemb, void *pt
1154 * @param ses session to send data to 1167 * @param ses session to send data to
1155 * @param 1168 * @param
1156 */ 1169 */
1157static int curl_schedule(void *cls, struct Session* ses ); 1170static int curl_schedule(void *cls );
1158 1171
1159 1172
1160 1173
@@ -1170,6 +1183,7 @@ static ssize_t send_check_connections (void *cls, struct Session *ps)
1170 struct Plugin *plugin = cls; 1183 struct Plugin *plugin = cls;
1171 CURLMcode mret; 1184 CURLMcode mret;
1172 struct HTTP_Message * msg; 1185 struct HTTP_Message * msg;
1186
1173 struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; 1187 struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
1174 1188
1175 GNUNET_assert(cls !=NULL); 1189 GNUNET_assert(cls !=NULL);
@@ -1207,7 +1221,7 @@ static ssize_t send_check_connections (void *cls, struct Session *ps)
1207 curl_multi_strerror (mret)); 1221 curl_multi_strerror (mret));
1208 return GNUNET_SYSERR; 1222 return GNUNET_SYSERR;
1209 } 1223 }
1210 if (curl_schedule (plugin, NULL) == GNUNET_SYSERR) 1224 if (curl_schedule (plugin) == GNUNET_SYSERR)
1211 return GNUNET_SYSERR; 1225 return GNUNET_SYSERR;
1212#if DEBUG_CONNECTIONS 1226#if DEBUG_CONNECTIONS
1213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",ps); 1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",ps);
@@ -1280,7 +1294,7 @@ static ssize_t send_check_connections (void *cls, struct Session *ps)
1280 curl_multi_strerror (mret)); 1294 curl_multi_strerror (mret));
1281 return GNUNET_SYSERR; 1295 return GNUNET_SYSERR;
1282 } 1296 }
1283 if (curl_schedule (plugin, NULL) == GNUNET_SYSERR) 1297 if (curl_schedule (plugin) == GNUNET_SYSERR)
1284 return GNUNET_SYSERR; 1298 return GNUNET_SYSERR;
1285 return GNUNET_YES; 1299 return GNUNET_YES;
1286 } 1300 }
@@ -1430,7 +1444,7 @@ static void curl_perform (void *cls,
1430 } 1444 }
1431 if ((ps->recv_connected == GNUNET_NO) && (ps->send_connected == GNUNET_NO)) 1445 if ((ps->recv_connected == GNUNET_NO) && (ps->send_connected == GNUNET_NO))
1432 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR); 1446 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
1433 return; 1447 break;
1434 default: 1448 default:
1435 break; 1449 break;
1436 } 1450 }
@@ -1441,7 +1455,7 @@ static void curl_perform (void *cls,
1441 handles_last_run = running; 1455 handles_last_run = running;
1442 } 1456 }
1443 while (mret == CURLM_CALL_MULTI_PERFORM); 1457 while (mret == CURLM_CALL_MULTI_PERFORM);
1444 curl_schedule(plugin, cls); 1458 curl_schedule(plugin);
1445} 1459}
1446 1460
1447 1461
@@ -1450,7 +1464,7 @@ static void curl_perform (void *cls,
1450 * @param ses session to send data to 1464 * @param ses session to send data to
1451 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok 1465 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
1452 */ 1466 */
1453static int curl_schedule(void *cls, struct Session* ses ) 1467static int curl_schedule(void *cls )
1454{ 1468{
1455 struct Plugin *plugin = cls; 1469 struct Plugin *plugin = cls;
1456 fd_set rs; 1470 fd_set rs;
@@ -1710,6 +1724,7 @@ http_plugin_disconnect (void *cls,
1710 const struct GNUNET_PeerIdentity *target) 1724 const struct GNUNET_PeerIdentity *target)
1711{ 1725{
1712 1726
1727
1713 struct Plugin *plugin = cls; 1728 struct Plugin *plugin = cls;
1714 struct HTTP_PeerContext *pc = NULL; 1729 struct HTTP_PeerContext *pc = NULL;
1715 struct Session *ps = NULL; 1730 struct Session *ps = NULL;
@@ -1728,14 +1743,14 @@ http_plugin_disconnect (void *cls,
1728 { 1743 {
1729 if (ps->send_endpoint!=NULL) 1744 if (ps->send_endpoint!=NULL)
1730 { 1745 {
1731 //curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint); 1746 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint));
1732 //curl_easy_cleanup(ps->send_endpoint); 1747 //curl_easy_cleanup(ps->send_endpoint);
1733 //ps->send_endpoint=NULL; 1748 //ps->send_endpoint=NULL;
1734 ps->send_force_disconnect = GNUNET_YES; 1749 ps->send_force_disconnect = GNUNET_YES;
1735 } 1750 }
1736 if (ps->recv_endpoint!=NULL) 1751 if (ps->recv_endpoint!=NULL)
1737 { 1752 {
1738 //curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint); 1753 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint));
1739 //curl_easy_cleanup(ps->recv_endpoint); 1754 //curl_easy_cleanup(ps->recv_endpoint);
1740 //ps->recv_endpoint=NULL; 1755 //ps->recv_endpoint=NULL;
1741 ps->recv_force_disconnect = GNUNET_YES; 1756 ps->recv_force_disconnect = GNUNET_YES;
@@ -1756,6 +1771,10 @@ http_plugin_disconnect (void *cls,
1756 ps->send_active = GNUNET_NO; 1771 ps->send_active = GNUNET_NO;
1757 ps=ps->next; 1772 ps=ps->next;
1758 } 1773 }
1774 //if (plugin->http_curl_task!= GNUNET_SCHEDULER_NO_TASK)
1775// GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_curl_task);
1776 //curl_schedule(plugin);
1777
1759} 1778}
1760 1779
1761 1780
@@ -2094,6 +2113,8 @@ libgnunet_plugin_transport_http_done (void *cls)
2094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl multihandle clean up failed\n"); 2113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl multihandle clean up failed\n");
2095 plugin->multi_handle = NULL; 2114 plugin->multi_handle = NULL;
2096 } 2115 }
2116 curl_global_cleanup();
2117
2097 GNUNET_free (plugin); 2118 GNUNET_free (plugin);
2098 GNUNET_free (api); 2119 GNUNET_free (api);
2099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unload http plugin complete...\n"); 2120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unload http plugin complete...\n");
@@ -2117,6 +2138,7 @@ libgnunet_plugin_transport_http_init (void *cls)
2117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); 2138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
2118 2139
2119 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2140 plugin = GNUNET_malloc (sizeof (struct Plugin));
2141 plugin->stats = env->stats;
2120 plugin->env = env; 2142 plugin->env = env;
2121 plugin->peers = NULL; 2143 plugin->peers = NULL;
2122 2144
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 76dd9b067..a1dcd5cd8 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -57,7 +57,7 @@
57/** 57/**
58 * Testcase timeout 58 * Testcase timeout
59 */ 59 */
60#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180) 60#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
61 61
62/** 62/**
63 * How long between recieve and send? 63 * How long between recieve and send?
@@ -1081,11 +1081,10 @@ static void run_connection_tests( int phase , void * cls)
1081 1081
1082 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n")); 1082 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n"));
1083 /* disconnect from peer, so new connections are created */ 1083 /* disconnect from peer, so new connections are created */
1084 //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); 1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity));
1085 //api->disconnect(api->cls, &my_identity); 1085 api->disconnect(api->cls, &my_identity);
1086 1086
1087 /* send a multiple GNUNET_messages at a time*/ 1087 /* send a multiple GNUNET_messages at a time*/
1088
1089 size = 2 * sizeof(struct GNUNET_MessageHeader); 1088 size = 2 * sizeof(struct GNUNET_MessageHeader);
1090 msg = GNUNET_malloc( 2* size); 1089 msg = GNUNET_malloc( 2* size);
1091 msg->size = htons(size); 1090 msg->size = htons(size);