aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-07-16 08:14:36 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-07-16 08:14:36 +0000
commitf301aa4fd5c7ec64889dcd4a5b6c3621a1895853 (patch)
treef4158307257d31753e2a4e5b18655c5e7de97c67 /src
parent4f4c12e9fc90d7afe7c50db16b4c3b93f07765c5 (diff)
downloadgnunet-f301aa4fd5c7ec64889dcd4a5b6c3621a1895853.tar.gz
gnunet-f301aa4fd5c7ec64889dcd4a5b6c3621a1895853.zip
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http.c72
-rw-r--r--src/transport/test_plugin_transport_data_http.conf2
2 files changed, 48 insertions, 26 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index dd98dd84e..d754c7e67 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -40,9 +40,8 @@
40#include "microhttpd.h" 40#include "microhttpd.h"
41#include <curl/curl.h> 41#include <curl/curl.h>
42 42
43#define VERBOSE GNUNET_NO 43#define DEBUG_HTTP GNUNET_YES
44#define DEBUG_CURL GNUNET_NO 44#define DEBUG_CURL GNUNET_NO
45#define DEBUG_HTTP GNUNET_NO
46#define DEBUG_CONNECTIONS GNUNET_NO 45#define DEBUG_CONNECTIONS GNUNET_NO
47#define DEBUG_SESSION_SELECTION GNUNET_NO 46#define DEBUG_SESSION_SELECTION GNUNET_NO
48 47
@@ -483,9 +482,9 @@ int remove_peer_context_Iterator (void *cls, const GNUNET_HashCode *key, void *v
483 struct Session * tmp = NULL; 482 struct Session * tmp = NULL;
484 struct HTTP_Message * msg = NULL; 483 struct HTTP_Message * msg = NULL;
485 struct HTTP_Message * msg_tmp = NULL; 484 struct HTTP_Message * msg_tmp = NULL;
486 485#if DEBUG_HTTP
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing context for peer `%s'\n",GNUNET_i2s(&pc->identity)); 486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing context for peer `%s'\n",GNUNET_i2s(&pc->identity));
488 487#endif
489 while (ps!=NULL) 488 while (ps!=NULL)
490 { 489 {
491 plugin->env->session_end(plugin, &pc->identity, ps); 490 plugin->env->session_end(plugin, &pc->identity, ps);
@@ -638,14 +637,14 @@ static void mhd_write_mst_cb (void *cls,
638 struct HTTP_PeerContext *pc = ps->peercontext; 637 struct HTTP_PeerContext *pc = ps->peercontext;
639 GNUNET_assert(ps != NULL); 638 GNUNET_assert(ps != NULL);
640 GNUNET_assert(pc != NULL); 639 GNUNET_assert(pc != NULL);
641 640#if DEBUG_HTTP
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
643 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 642 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
644 ps, 643 ps,
645 ntohs(message->type), 644 ntohs(message->type),
646 ntohs(message->size), 645 ntohs(message->size),
647 GNUNET_i2s(&(ps->peercontext)->identity),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); 646 GNUNET_i2s(&(ps->peercontext)->identity),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen));
648 647#endif
649 pc->plugin->env->receive (ps->peercontext->plugin->env->cls, 648 pc->plugin->env->receive (ps->peercontext->plugin->env->cls,
650 &pc->identity, 649 &pc->identity,
651 message, 1, ps, 650 message, 1, ps,
@@ -775,10 +774,12 @@ mdh_access_cb (void *cls,
775 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); 774 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
776 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); 775 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
777 MHD_destroy_response (response); 776 MHD_destroy_response (response);
777#if DEBUG_CONNECTIONS
778 if (res == MHD_YES) 778 if (res == MHD_YES)
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, sent HTTP 1.1/404\n"); 779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, sent HTTP 1.1/404\n");
780 else 780 else
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, could not send error\n"); 781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, could not send error\n");
782#endif
782 return res; 783 return res;
783 } 784 }
784 } 785 }
@@ -862,12 +863,13 @@ mdh_access_cb (void *cls,
862 *httpSessionCache = ps; 863 *httpSessionCache = ps;
863 if (ps->msgtok==NULL) 864 if (ps->msgtok==NULL)
864 ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps); 865 ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
865 866#if DEBUG_HTTP
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", 867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",
867 ps, 868 ps,
868 method, 869 method,
869 GNUNET_i2s(&pc->identity), 870 GNUNET_i2s(&pc->identity),
870 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen)); 871 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen));
872#endif
871 } 873 }
872 874
873 /* Is it a PUT or a GET request */ 875 /* Is it a PUT or a GET request */
@@ -1105,9 +1107,6 @@ static size_t curl_get_header_cb( void *ptr, size_t size, size_t nmemb, void *st
1105 if (tmp[len-2] == 13) 1107 if (tmp[len-2] == 13)
1106 tmp[len-2]= '\0'; 1108 tmp[len-2]= '\0';
1107 } 1109 }
1108#if DEBUG_HTTP
1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s' %u \n",tmp, http_result);
1110#endif
1111 } 1110 }
1112 if (NULL != tmp) 1111 if (NULL != tmp)
1113 GNUNET_free (tmp); 1112 GNUNET_free (tmp);
@@ -1159,9 +1158,6 @@ static size_t curl_put_header_cb( void *ptr, size_t size, size_t nmemb, void *st
1159 if (tmp[len-2] == 13) 1158 if (tmp[len-2] == 13)
1160 tmp[len-2]= '\0'; 1159 tmp[len-2]= '\0';
1161 } 1160 }
1162#if DEBUG_HTTP
1163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s' %u \n",tmp, http_result);
1164#endif
1165 } 1161 }
1166 if (NULL != tmp) 1162 if (NULL != tmp)
1167 GNUNET_free (tmp); 1163 GNUNET_free (tmp);
@@ -1245,14 +1241,14 @@ static void curl_receive_mst_cb (void *cls,
1245 struct HTTP_PeerContext *pc = ps->peercontext; 1241 struct HTTP_PeerContext *pc = ps->peercontext;
1246 GNUNET_assert(ps != NULL); 1242 GNUNET_assert(ps != NULL);
1247 GNUNET_assert(pc != NULL); 1243 GNUNET_assert(pc != NULL);
1248 1244#if DEBUG_HTTP
1249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1250 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1246 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1251 ps, 1247 ps,
1252 ntohs(message->type), 1248 ntohs(message->type),
1253 ntohs(message->size), 1249 ntohs(message->size),
1254 GNUNET_i2s(&(pc->identity)),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); 1250 GNUNET_i2s(&(pc->identity)),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen));
1255 1251#endif
1256 pc->plugin->env->receive (pc->plugin->env->cls, 1252 pc->plugin->env->receive (pc->plugin->env->cls,
1257 &pc->identity, 1253 &pc->identity,
1258 message, 1, ps, 1254 message, 1, ps,
@@ -1806,6 +1802,7 @@ http_plugin_send (void *cls,
1806 1802
1807 GNUNET_assert(cls !=NULL); 1803 GNUNET_assert(cls !=NULL);
1808 1804
1805#if DEBUG_HTTP
1809 char * force = GNUNET_malloc(40); 1806 char * force = GNUNET_malloc(40);
1810 if (force_address == GNUNET_YES) 1807 if (force_address == GNUNET_YES)
1811 strcpy(force,"forced addr."); 1808 strcpy(force,"forced addr.");
@@ -1813,13 +1810,16 @@ http_plugin_send (void *cls,
1813 strcpy(force,"any addr."); 1810 strcpy(force,"any addr.");
1814 if (force_address == GNUNET_SYSERR) 1811 if (force_address == GNUNET_SYSERR)
1815 strcpy(force,"reliable bi-direc. address addr."); 1812 strcpy(force,"reliable bi-direc. address addr.");
1813
1816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n", 1814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n",
1817 msgbuf_size, 1815 msgbuf_size,
1818 GNUNET_i2s(target), 1816 GNUNET_i2s(target),
1819 force, 1817 force,
1820 http_plugin_address_to_string(NULL, addr, addrlen), 1818 http_plugin_address_to_string(NULL, addr, addrlen),
1821 session); 1819 session);
1820
1822 GNUNET_free(force); 1821 GNUNET_free(force);
1822#endif
1823 1823
1824 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey); 1824 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
1825 /* Peer unknown */ 1825 /* Peer unknown */
@@ -1841,11 +1841,12 @@ http_plugin_send (void *cls,
1841 if ((addr!=NULL) && (addrlen!=0)) 1841 if ((addr!=NULL) && (addrlen!=0))
1842 { 1842 {
1843 ps = GNUNET_malloc(sizeof (struct Session)); 1843 ps = GNUNET_malloc(sizeof (struct Session));
1844#if DEBUG_SESSION_SELECTION
1844 if (force_address == GNUNET_YES) 1845 if (force_address == GNUNET_YES)
1845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection & forced address: creating new session %X to peer %s\n", ps, GNUNET_i2s(target)); 1846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection & forced address: creating new session %X to peer %s\n", ps, GNUNET_i2s(target));
1846 if (force_address != GNUNET_YES) 1847 if (force_address != GNUNET_YES)
1847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection: creating new session %X to peer %s\n", ps, GNUNET_i2s(target)); 1848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection: creating new session %X to peer %s\n", ps, GNUNET_i2s(target));
1848 1849#endif
1849 if ((addrlen!=0) && (addr!=NULL)) 1850 if ((addrlen!=0) && (addr!=NULL))
1850 { 1851 {
1851 ps->addr = GNUNET_malloc(addrlen); 1852 ps->addr = GNUNET_malloc(addrlen);
@@ -1874,7 +1875,9 @@ http_plugin_send (void *cls,
1874 } 1875 }
1875 else 1876 else
1876 { 1877 {
1878#if DEBUG_HTTP
1877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing session found & and no address given: no way to send this message to peer `%s'!\n", GNUNET_i2s(target)); 1879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing session found & and no address given: no way to send this message to peer `%s'!\n", GNUNET_i2s(target));
1880#endif
1878 return GNUNET_SYSERR; 1881 return GNUNET_SYSERR;
1879 } 1882 }
1880 } 1883 }
@@ -2192,8 +2195,10 @@ libgnunet_plugin_transport_http_done (void *cls)
2192 if (plugin->multi_handle!=NULL) 2195 if (plugin->multi_handle!=NULL)
2193 { 2196 {
2194 mret = curl_multi_cleanup(plugin->multi_handle); 2197 mret = curl_multi_cleanup(plugin->multi_handle);
2198#if DEBUG_HTTP
2195 if ( CURLM_OK != mret) 2199 if ( CURLM_OK != mret)
2196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl multihandle clean up failed\n"); 2200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl multihandle clean up failed\n");
2201#endif
2197 plugin->multi_handle = NULL; 2202 plugin->multi_handle = NULL;
2198 } 2203 }
2199 curl_global_cleanup(); 2204 curl_global_cleanup();
@@ -2207,7 +2212,9 @@ libgnunet_plugin_transport_http_done (void *cls)
2207 GNUNET_free_non_null (plugin->bind_address); 2212 GNUNET_free_non_null (plugin->bind_address);
2208 GNUNET_free (plugin); 2213 GNUNET_free (plugin);
2209 GNUNET_free (api); 2214 GNUNET_free (api);
2215#if DEBUG_HTTP
2210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unload http plugin complete...\n"); 2216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unload http plugin complete...\n");
2217#endif
2211 return NULL; 2218 return NULL;
2212} 2219}
2213 2220
@@ -2226,7 +2233,9 @@ libgnunet_plugin_transport_http_init (void *cls)
2226 char * hostname; 2233 char * hostname;
2227 2234
2228 GNUNET_assert(cls !=NULL); 2235 GNUNET_assert(cls !=NULL);
2236#if DEBUG_HTTP
2229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); 2237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
2238#endif
2230 2239
2231 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2240 plugin = GNUNET_malloc (sizeof (struct Plugin));
2232 plugin->stats = env->stats; 2241 plugin->stats = env->stats;
@@ -2255,8 +2264,7 @@ libgnunet_plugin_transport_http_init (void *cls)
2255 { 2264 {
2256 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2265 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2257 "http", 2266 "http",
2258 _ 2267 _("Require valid port number for transport plugin `%s' in configuration!\n"),
2259 ("Require valid port number for transport plugin `%s' in configuration!\n"),
2260 "transport-http"); 2268 "transport-http");
2261 libgnunet_plugin_transport_http_done (api); 2269 libgnunet_plugin_transport_http_done (api);
2262 return NULL; 2270 return NULL;
@@ -2273,7 +2281,10 @@ libgnunet_plugin_transport_http_init (void *cls)
2273 &hostname)); 2281 &hostname));
2274 if (inet_aton(hostname, plugin->bind_address)==0) 2282 if (inet_aton(hostname, plugin->bind_address)==0)
2275 { 2283 {
2276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Misconfigured address to bind to in configuration\n"); 2284 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2285 "http",
2286 _("Misconfigured address to bind to in configuration!\n"),
2287 "transport-http");
2277 GNUNET_free(plugin->bind_address); 2288 GNUNET_free(plugin->bind_address);
2278 plugin->bind_address = NULL; 2289 plugin->bind_address = NULL;
2279 } 2290 }
@@ -2285,7 +2296,7 @@ libgnunet_plugin_transport_http_init (void *cls)
2285 if ((plugin->http_server_daemon_v4 == NULL) && (plugin->http_server_daemon_v6 == NULL) && (port != 0)) 2296 if ((plugin->http_server_daemon_v4 == NULL) && (plugin->http_server_daemon_v6 == NULL) && (port != 0))
2286 { 2297 {
2287 plugin->http_server_daemon_v6 = MHD_start_daemon ( 2298 plugin->http_server_daemon_v6 = MHD_start_daemon (
2288#if DEBUG_HTTP 2299#if DEBUG_CONNECTIONS
2289 MHD_USE_DEBUG | 2300 MHD_USE_DEBUG |
2290#endif 2301#endif
2291 MHD_USE_IPv6, 2302 MHD_USE_IPv6,
@@ -2300,7 +2311,7 @@ libgnunet_plugin_transport_http_init (void *cls)
2300 MHD_OPTION_END); 2311 MHD_OPTION_END);
2301 2312
2302 plugin->http_server_daemon_v4 = MHD_start_daemon ( 2313 plugin->http_server_daemon_v4 = MHD_start_daemon (
2303#if DEBUG_HTTP 2314#if DEBUG_CONNECTIONS
2304 MHD_USE_DEBUG | 2315 MHD_USE_DEBUG |
2305#endif 2316#endif
2306 MHD_NO_FLAG, 2317 MHD_NO_FLAG,
@@ -2320,13 +2331,24 @@ libgnunet_plugin_transport_http_init (void *cls)
2320 if (plugin->http_server_daemon_v6 != NULL) 2331 if (plugin->http_server_daemon_v6 != NULL)
2321 plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); 2332 plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
2322 2333
2334
2323 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 2335 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
2324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); 2336 {
2337#if DEBUG_HTTP
2338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port);
2339#endif
2340 }
2325 else if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) 2341 else if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
2342 {
2343#if DEBUG_HTTP
2326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); 2344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
2345#endif
2346 }
2327 else 2347 else
2328 { 2348 {
2349#if DEBUG_HTTP
2329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No MHD was started, transport plugin not functional!\n"); 2350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No MHD was started, transport plugin not functional!\n");
2351#endif
2330 libgnunet_plugin_transport_http_done (api); 2352 libgnunet_plugin_transport_http_done (api);
2331 return NULL; 2353 return NULL;
2332 } 2354 }
@@ -2338,9 +2360,9 @@ libgnunet_plugin_transport_http_init (void *cls)
2338 if ( NULL == plugin->multi_handle ) 2360 if ( NULL == plugin->multi_handle )
2339 { 2361 {
2340 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2362 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2341 "http", 2363 "http",
2342 _("Could not initialize curl multi handle, failed to start http plugin!\n"), 2364 _("Could not initialize curl multi handle, failed to start http plugin!\n"),
2343 "transport-http"); 2365 "transport-http");
2344 libgnunet_plugin_transport_http_done (api); 2366 libgnunet_plugin_transport_http_done (api);
2345 return NULL; 2367 return NULL;
2346 } 2368 }
diff --git a/src/transport/test_plugin_transport_data_http.conf b/src/transport/test_plugin_transport_data_http.conf
index 80a615b7e..7a14f793a 100644
--- a/src/transport/test_plugin_transport_data_http.conf
+++ b/src/transport/test_plugin_transport_data_http.conf
@@ -12,7 +12,7 @@ BINDTO = 127.0.0.1
12 12
13[transport] 13[transport]
14PREFIX = valgrind --leak-check=full 14PREFIX = valgrind --leak-check=full
15DEBUG = NO 15DEBUG = YES
16 16
17[statistics] 17[statistics]
18ACCEPT_FROM6 = ::1; 18ACCEPT_FROM6 = ::1;