diff options
-rw-r--r-- | src/transport/Makefile.am | 16 | ||||
-rw-r--r-- | src/transport/plugin_transport_http.c | 127 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_data_http.conf | 28 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_http.c | 15 | ||||
-rw-r--r-- | src/transport/test_transport_api_http_peer1.conf | 3 | ||||
-rw-r--r-- | src/transport/test_transport_api_http_peer2.conf | 3 |
6 files changed, 157 insertions, 35 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 1cb61c0a9..c6f2bc2ff 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -6,6 +6,12 @@ if MINGW | |||
6 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | 6 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols |
7 | endif | 7 | endif |
8 | 8 | ||
9 | if HAVE_MHD | ||
10 | GN_LIBMHD = -lmicrohttpd | ||
11 | HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la | ||
12 | HTTP_PLGUIN_CHECK = test_plugin_transport_http | ||
13 | endif | ||
14 | |||
9 | if USE_COVERAGE | 15 | if USE_COVERAGE |
10 | AM_CFLAGS = --coverage -O0 | 16 | AM_CFLAGS = --coverage -O0 |
11 | endif | 17 | endif |
@@ -69,8 +75,8 @@ plugin_LTLIBRARIES = \ | |||
69 | libgnunet_plugin_transport_tcp.la \ | 75 | libgnunet_plugin_transport_tcp.la \ |
70 | libgnunet_plugin_transport_udp.la \ | 76 | libgnunet_plugin_transport_udp.la \ |
71 | libgnunet_plugin_transport_udp_nat.la \ | 77 | libgnunet_plugin_transport_udp_nat.la \ |
78 | $(HTTP_PLUGIN_LA) \ | ||
72 | libgnunet_plugin_transport_template.la | 79 | libgnunet_plugin_transport_template.la |
73 | # libgnunet_plugin_transport_http.la | ||
74 | # TODO: add http, nat, etc. | 80 | # TODO: add http, nat, etc. |
75 | 81 | ||
76 | libgnunet_plugin_transport_tcp_la_SOURCES = \ | 82 | libgnunet_plugin_transport_tcp_la_SOURCES = \ |
@@ -110,6 +116,7 @@ libgnunet_plugin_transport_udp_nat_la_LIBADD = \ | |||
110 | libgnunet_plugin_transport_udp_nat_la_LDFLAGS = \ | 116 | libgnunet_plugin_transport_udp_nat_la_LDFLAGS = \ |
111 | $(GN_PLUGIN_LDFLAGS) | 117 | $(GN_PLUGIN_LDFLAGS) |
112 | 118 | ||
119 | if HAVE_MHD | ||
113 | libgnunet_plugin_transport_http_la_SOURCES = \ | 120 | libgnunet_plugin_transport_http_la_SOURCES = \ |
114 | plugin_transport_http.c | 121 | plugin_transport_http.c |
115 | libgnunet_plugin_transport_http_la_LIBADD = \ | 122 | libgnunet_plugin_transport_http_la_LIBADD = \ |
@@ -118,14 +125,15 @@ libgnunet_plugin_transport_http_la_LIBADD = \ | |||
118 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | 125 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ |
119 | $(top_builddir)/src/util/libgnunetutil.la | 126 | $(top_builddir)/src/util/libgnunetutil.la |
120 | libgnunet_plugin_transport_http_la_LDFLAGS = \ | 127 | libgnunet_plugin_transport_http_la_LDFLAGS = \ |
128 | $(GN_LIBMHD) \ | ||
121 | $(GN_PLUGIN_LDFLAGS) | 129 | $(GN_PLUGIN_LDFLAGS) |
122 | 130 | endif | |
123 | 131 | ||
124 | check_PROGRAMS = \ | 132 | check_PROGRAMS = \ |
125 | test_transport_api_tcp \ | 133 | test_transport_api_tcp \ |
126 | test_transport_api_udp \ | 134 | test_transport_api_udp \ |
127 | test_transport_api_udp_nat \ | 135 | $(HTTP_PLGUIN_CHECK) \ |
128 | test_plugin_transport_http | 136 | test_transport_api_udp_nat |
129 | # test_transport_api_http \ | 137 | # test_transport_api_http \ |
130 | # TODO: add tests for http, nat, etc. | 138 | # TODO: add tests for http, nat, etc. |
131 | 139 | ||
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index a0711660b..7ede6da3c 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -32,8 +32,10 @@ | |||
32 | #include "gnunet_statistics_service.h" | 32 | #include "gnunet_statistics_service.h" |
33 | #include "gnunet_transport_service.h" | 33 | #include "gnunet_transport_service.h" |
34 | #include "plugin_transport.h" | 34 | #include "plugin_transport.h" |
35 | #include "microhttpd.h" | ||
35 | 36 | ||
36 | #define DEBUG_HTTP GNUNET_YES | 37 | #define VERBOSE GNUNET_YES |
38 | #define DEBUG GNUNET_YES | ||
37 | 39 | ||
38 | /** | 40 | /** |
39 | * After how long do we expire an address that we | 41 | * After how long do we expire an address that we |
@@ -42,6 +44,7 @@ | |||
42 | */ | 44 | */ |
43 | #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) | 45 | #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) |
44 | 46 | ||
47 | #define HTTP_TIMEOUT 600 | ||
45 | 48 | ||
46 | /** | 49 | /** |
47 | * Encapsulation of all of the state of the plugin. | 50 | * Encapsulation of all of the state of the plugin. |
@@ -130,6 +133,11 @@ struct Plugin | |||
130 | }; | 133 | }; |
131 | 134 | ||
132 | /** | 135 | /** |
136 | * Daemon for listening for new connections. | ||
137 | */ | ||
138 | static struct MHD_Daemon *http_daemon; | ||
139 | |||
140 | /** | ||
133 | * Function that can be used by the transport service to transmit | 141 | * Function that can be used by the transport service to transmit |
134 | * a message using the plugin. | 142 | * a message using the plugin. |
135 | * | 143 | * |
@@ -247,6 +255,46 @@ http_plugin_address_suggested (void *cls, | |||
247 | return GNUNET_OK; | 255 | return GNUNET_OK; |
248 | } | 256 | } |
249 | 257 | ||
258 | /** | ||
259 | * Check if we are allowed to connect to the given IP. | ||
260 | */ | ||
261 | static int | ||
262 | acceptPolicyCallback (void *cls, | ||
263 | const struct sockaddr *addr, socklen_t addr_len) | ||
264 | { | ||
265 | return MHD_YES; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * Process GET or PUT request received via MHD. For | ||
270 | * GET, queue response that will send back our pending | ||
271 | * messages. For PUT, process incoming data and send | ||
272 | * to GNUnet core. In either case, check if a session | ||
273 | * already exists and create a new one if not. | ||
274 | */ | ||
275 | static int | ||
276 | accessHandlerCallback (void *cls, | ||
277 | struct MHD_Connection *session, | ||
278 | const char *url, | ||
279 | const char *method, | ||
280 | const char *version, | ||
281 | const char *upload_data, | ||
282 | size_t * upload_data_size, void **httpSessionCache) | ||
283 | { | ||
284 | return MHD_YES; | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * MHD is done handling a request. Cleanup | ||
289 | * the respective transport state. | ||
290 | */ | ||
291 | static void | ||
292 | requestCompletedCallback (void *unused, | ||
293 | struct MHD_Connection *session, | ||
294 | void **httpSessionCache) | ||
295 | { | ||
296 | |||
297 | } | ||
250 | 298 | ||
251 | /** | 299 | /** |
252 | * Entry point for the plugin. | 300 | * Entry point for the plugin. |
@@ -257,6 +305,8 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
257 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 305 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
258 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 306 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
259 | struct Plugin *plugin; | 307 | struct Plugin *plugin; |
308 | long long unsigned int port; | ||
309 | int use_ipv6; | ||
260 | 310 | ||
261 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 311 | plugin = GNUNET_malloc (sizeof (struct Plugin)); |
262 | plugin->env = env; | 312 | plugin->env = env; |
@@ -267,7 +317,73 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
267 | api->disconnect = &http_plugin_disconnect; | 317 | api->disconnect = &http_plugin_disconnect; |
268 | api->address_pretty_printer = &http_plugin_address_pretty_printer; | 318 | api->address_pretty_printer = &http_plugin_address_pretty_printer; |
269 | api->check_address = &http_plugin_address_suggested; | 319 | api->check_address = &http_plugin_address_suggested; |
270 | return api; | 320 | |
321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); | ||
322 | /* Reading port number from config file */ | ||
323 | if ((GNUNET_OK != | ||
324 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | ||
325 | "transport-http", | ||
326 | "PORT", | ||
327 | &port)) || | ||
328 | (port > 65535) ) | ||
329 | { | ||
330 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
331 | "http", | ||
332 | _ | ||
333 | ("Require valid port number for service `%s' in configuration!\n"), | ||
334 | "transport-http"); | ||
335 | return NULL; | ||
336 | } | ||
337 | use_ipv6 = GNUNET_YES; | ||
338 | use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-http","USE_IPV6"); | ||
339 | if ((http_daemon == NULL) && (port != 0)) | ||
340 | { | ||
341 | if ( use_ipv6 == GNUNET_YES) | ||
342 | { | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon could not started, http plugin not working\n"); | ||
344 | http_daemon = MHD_start_daemon (MHD_USE_IPv6, | ||
345 | port, | ||
346 | &acceptPolicyCallback, | ||
347 | NULL, &accessHandlerCallback, NULL, | ||
348 | MHD_OPTION_CONNECTION_TIMEOUT, | ||
349 | (unsigned int) HTTP_TIMEOUT, | ||
350 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | ||
351 | (unsigned int) GNUNET_SERVER_MAX_MESSAGE_SIZE, | ||
352 | MHD_OPTION_CONNECTION_LIMIT, | ||
353 | (unsigned int) 128, | ||
354 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | ||
355 | (unsigned int) 8, | ||
356 | MHD_OPTION_NOTIFY_COMPLETED, | ||
357 | &requestCompletedCallback, NULL, | ||
358 | MHD_OPTION_END); | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv6 disabled\n",port); | ||
363 | http_daemon = MHD_start_daemon (MHD_NO_FLAG, | ||
364 | port, | ||
365 | &acceptPolicyCallback, | ||
366 | NULL, &accessHandlerCallback, NULL, | ||
367 | MHD_OPTION_CONNECTION_TIMEOUT, | ||
368 | (unsigned int) HTTP_TIMEOUT, | ||
369 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | ||
370 | (unsigned int) GNUNET_SERVER_MAX_MESSAGE_SIZE, | ||
371 | MHD_OPTION_CONNECTION_LIMIT, | ||
372 | (unsigned int) 128, | ||
373 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | ||
374 | (unsigned int) 8, | ||
375 | MHD_OPTION_NOTIFY_COMPLETED, | ||
376 | &requestCompletedCallback, NULL, | ||
377 | MHD_OPTION_END); | ||
378 | } | ||
379 | } | ||
380 | if ( NULL != http_daemon ) | ||
381 | return api; | ||
382 | else | ||
383 | { | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Starting MHD on port %u with IPv6 disabled\n",port); | ||
385 | return NULL; | ||
386 | } | ||
271 | } | 387 | } |
272 | 388 | ||
273 | 389 | ||
@@ -280,6 +396,13 @@ libgnunet_plugin_transport_http_done (void *cls) | |||
280 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 396 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
281 | struct Plugin *plugin = api->cls; | 397 | struct Plugin *plugin = api->cls; |
282 | 398 | ||
399 | if (http_daemon != NULL) | ||
400 | { | ||
401 | MHD_stop_daemon (http_daemon); | ||
402 | http_daemon = NULL; | ||
403 | } | ||
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Shutting down http plugin...\n"); | ||
405 | |||
283 | GNUNET_free (plugin); | 406 | GNUNET_free (plugin); |
284 | GNUNET_free (api); | 407 | GNUNET_free (api); |
285 | return NULL; | 408 | return NULL; |
diff --git a/src/transport/test_plugin_transport_data_http.conf b/src/transport/test_plugin_transport_data_http.conf index f794c8f87..77f4bdbbb 100644 --- a/src/transport/test_plugin_transport_data_http.conf +++ b/src/transport/test_plugin_transport_data_http.conf | |||
@@ -1,24 +1,8 @@ | |||
1 | [PATHS] | 1 | [PATHS] |
2 | SERVICEHOME = /tmp/test-gnunetd-plugin-transport_http/ | 2 | DEFAULTCONFIG = test_transport_api_tcp_peer1.conf |
3 | SERVICEHOME = /tmp/test-gnunetd-transport-peer-1/ | ||
3 | 4 | ||
4 | [resolver] | 5 | [transport-http] |
5 | PORT = 2364 | 6 | PORT = 12389 |
6 | 7 | DEBUG = YES | |
7 | [transport] | 8 | USE_IPV6 = NO \ No newline at end of file |
8 | PORT = 2365 | ||
9 | PLUGINS = http | ||
10 | |||
11 | [arm] | ||
12 | PORT = 2366 | ||
13 | |||
14 | [statistics] | ||
15 | PORT = 2367 | ||
16 | |||
17 | [transport-udp] | ||
18 | PORT = 2368 | ||
19 | |||
20 | [peerinfo] | ||
21 | PORT = 2369 | ||
22 | |||
23 | [testing] | ||
24 | WEAKRANDOM = YES | ||
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index f8b5e4dba..76e4f64f6 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c | |||
@@ -36,7 +36,8 @@ | |||
36 | #include "plugin_transport.h" | 36 | #include "plugin_transport.h" |
37 | #include "transport.h" | 37 | #include "transport.h" |
38 | 38 | ||
39 | #define VERBOSE GNUNET_NO | 39 | #define VERBOSE GNUNET_YES |
40 | #define DEBUG GNUNET_YES | ||
40 | 41 | ||
41 | /** | 42 | /** |
42 | * How long until we give up on transmitting the message? | 43 | * How long until we give up on transmitting the message? |
@@ -124,7 +125,7 @@ static void | |||
124 | unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 125 | unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
125 | { | 126 | { |
126 | GNUNET_assert (NULL == | 127 | GNUNET_assert (NULL == |
127 | GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp", | 128 | GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", |
128 | api)); | 129 | api)); |
129 | if (my_private_key != NULL) | 130 | if (my_private_key != NULL) |
130 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 131 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
@@ -143,7 +144,6 @@ static void | |||
143 | test_validation () | 144 | test_validation () |
144 | { | 145 | { |
145 | struct sockaddr_in soaddr; | 146 | struct sockaddr_in soaddr; |
146 | |||
147 | memset (&soaddr, 0, sizeof (soaddr)); | 147 | memset (&soaddr, 0, sizeof (soaddr)); |
148 | #if HAVE_SOCKADDR_IN_SIN_LEN | 148 | #if HAVE_SOCKADDR_IN_SIN_LEN |
149 | soaddr.sin_len = sizeof (soaddr); | 149 | soaddr.sin_len = sizeof (soaddr); |
@@ -207,6 +207,7 @@ run (void *cls, | |||
207 | GNUNET_SCHEDULER_shutdown (s); | 207 | GNUNET_SCHEDULER_shutdown (s); |
208 | return; | 208 | return; |
209 | } | 209 | } |
210 | /* | ||
210 | max_connect_per_transport = (uint32_t) tneigh; | 211 | max_connect_per_transport = (uint32_t) tneigh; |
211 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 212 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
212 | GNUNET_free (keyfile); | 213 | GNUNET_free (keyfile); |
@@ -220,14 +221,18 @@ run (void *cls, | |||
220 | } | 221 | } |
221 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | 222 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
222 | GNUNET_CRYPTO_hash (&my_public_key, | 223 | GNUNET_CRYPTO_hash (&my_public_key, |
223 | sizeof (my_public_key), &my_identity.hashPubKey); | 224 | sizeof (my_public_key), &my_identity.hashPubKey);*/ |
224 | 225 | ||
225 | /* load plugins... */ | 226 | /* load plugins... */ |
226 | setup_plugin_environment (); | 227 | setup_plugin_environment (); |
227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading http transport plugin\n")); | 228 | |
228 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http"); | 229 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http"); |
229 | 230 | ||
230 | api = GNUNET_PLUGIN_load (libname, &env); | 231 | api = GNUNET_PLUGIN_load (libname, &env); |
232 | if (api != NULL ) | ||
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
234 | "Loading transport plugin for http `%s' successful\n",libname); | ||
235 | |||
231 | GNUNET_free (libname); | 236 | GNUNET_free (libname); |
232 | if (api == NULL) | 237 | if (api == NULL) |
233 | { | 238 | { |
diff --git a/src/transport/test_transport_api_http_peer1.conf b/src/transport/test_transport_api_http_peer1.conf index 5fe8864e2..2f9e3425d 100644 --- a/src/transport/test_transport_api_http_peer1.conf +++ b/src/transport/test_transport_api_http_peer1.conf | |||
@@ -1,5 +1,6 @@ | |||
1 | [transport-http] | 1 | [transport-http] |
2 | PORT = 12368 | 2 | #PORT = 12368 |
3 | DEBUG=YES | ||
3 | 4 | ||
4 | [fs] | 5 | [fs] |
5 | ALLOW_SHUTDOWN = YES | 6 | ALLOW_SHUTDOWN = YES |
diff --git a/src/transport/test_transport_api_http_peer2.conf b/src/transport/test_transport_api_http_peer2.conf index 2ca26fddd..44bb71f26 100644 --- a/src/transport/test_transport_api_http_peer2.conf +++ b/src/transport/test_transport_api_http_peer2.conf | |||
@@ -1,5 +1,6 @@ | |||
1 | [transport-http] | 1 | [transport-http] |
2 | PORT = 22368 | 2 | PORT = 22368 |
3 | DEBUG = YES | ||
3 | 4 | ||
4 | [fs] | 5 | [fs] |
5 | ALLOW_SHUTDOWN = YES | 6 | ALLOW_SHUTDOWN = YES |
@@ -49,7 +50,7 @@ MINIMUM-FRIENDS = 0 | |||
49 | 50 | ||
50 | [transport] | 51 | [transport] |
51 | PLUGINS = http | 52 | PLUGINS = http |
52 | #DEBUG = YES | 53 | DEBUG = YES |
53 | # PREFIX = | 54 | # PREFIX = |
54 | ALLOW_SHUTDOWN = YES | 55 | ALLOW_SHUTDOWN = YES |
55 | ACCEPT_FROM6 = ::1; | 56 | ACCEPT_FROM6 = ::1; |