diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-05-31 12:02:01 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-05-31 12:02:01 +0000 |
commit | 073dc58f510c96fe869cb9ad907c69cf7078092d (patch) | |
tree | 0281e3b50e187e2956fb604e49ad589684ccd9d1 | |
parent | 5df2844de6e5cd0c5372432135f393566a96d5b0 (diff) | |
download | gnunet-073dc58f510c96fe869cb9ad907c69cf7078092d.tar.gz gnunet-073dc58f510c96fe869cb9ad907c69cf7078092d.zip |
-rw-r--r-- | src/transport/Makefile.am | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_http.c | 105 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_http.c | 82 |
3 files changed, 182 insertions, 9 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index caee5b51d..f42202c45 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -9,7 +9,7 @@ endif | |||
9 | if HAVE_MHD | 9 | if HAVE_MHD |
10 | GN_LIBMHD = -lmicrohttpd | 10 | GN_LIBMHD = -lmicrohttpd |
11 | HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la | 11 | HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la |
12 | HTTP_PLGUIN_CHECK = test_plugin_transport_http | 12 | HTTP_PLUGIN_CHECK = test_plugin_transport_http |
13 | endif | 13 | endif |
14 | 14 | ||
15 | if USE_COVERAGE | 15 | if USE_COVERAGE |
@@ -133,7 +133,7 @@ check_PROGRAMS = \ | |||
133 | test_transport_api_tcp \ | 133 | test_transport_api_tcp \ |
134 | test_transport_api_tcp \ | 134 | test_transport_api_tcp \ |
135 | test_transport_api_udp \ | 135 | test_transport_api_udp \ |
136 | $(HTTP_PLGUIN_CHECK) \ | 136 | $(HTTP_PLUGIN_CHECK) \ |
137 | test_transport_api_udp_nat \ | 137 | test_transport_api_udp_nat \ |
138 | test_transport_api_reliability_tcp | 138 | test_transport_api_reliability_tcp |
139 | # test_transport_api_http \ | 139 | # test_transport_api_http \ |
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 726a9dbe2..5e439e75e 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "gnunet_transport_service.h" | 34 | #include "gnunet_transport_service.h" |
35 | #include "gnunet_resolver_service.h" | 35 | #include "gnunet_resolver_service.h" |
36 | #include "plugin_transport.h" | 36 | #include "plugin_transport.h" |
37 | #include "gnunet_os_lib.h" | ||
37 | #include "microhttpd.h" | 38 | #include "microhttpd.h" |
38 | #include <curl/curl.h> | 39 | #include <curl/curl.h> |
39 | 40 | ||
@@ -70,6 +71,43 @@ | |||
70 | struct Plugin; | 71 | struct Plugin; |
71 | 72 | ||
72 | /** | 73 | /** |
74 | * Network format for IPv4 addresses. | ||
75 | */ | ||
76 | struct IPv4HttpAddress | ||
77 | { | ||
78 | /** | ||
79 | * IPv4 address, in network byte order. | ||
80 | */ | ||
81 | uint32_t ipv4_addr; | ||
82 | |||
83 | /** | ||
84 | * Port number, in network byte order. | ||
85 | */ | ||
86 | uint16_t u_port; | ||
87 | |||
88 | }; | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Network format for IPv6 addresses. | ||
93 | */ | ||
94 | struct IPv6HttpAddress | ||
95 | { | ||
96 | /** | ||
97 | * IPv6 address. | ||
98 | */ | ||
99 | struct in6_addr ipv6_addr; | ||
100 | |||
101 | /** | ||
102 | * Port number, in network byte order. | ||
103 | */ | ||
104 | uint16_t u6_port; | ||
105 | |||
106 | }; | ||
107 | |||
108 | |||
109 | |||
110 | /** | ||
73 | * Message to send using http | 111 | * Message to send using http |
74 | */ | 112 | */ |
75 | struct HTTP_Message | 113 | struct HTTP_Message |
@@ -92,8 +130,6 @@ struct HTTP_Message | |||
92 | /** | 130 | /** |
93 | * amount of data to sent | 131 | * amount of data to sent |
94 | */ | 132 | */ |
95 | size_t size; | ||
96 | |||
97 | size_t len; | 133 | size_t len; |
98 | }; | 134 | }; |
99 | 135 | ||
@@ -204,6 +240,8 @@ struct Plugin | |||
204 | */ | 240 | */ |
205 | struct GNUNET_SERVICE_Context *service; | 241 | struct GNUNET_SERVICE_Context *service; |
206 | 242 | ||
243 | unsigned int port_inbound; | ||
244 | |||
207 | /** | 245 | /** |
208 | * List of open sessions. | 246 | * List of open sessions. |
209 | */ | 247 | */ |
@@ -1106,6 +1144,8 @@ http_plugin_address_pretty_printer (void *cls, | |||
1106 | asc, void *asc_cls) | 1144 | asc, void *asc_cls) |
1107 | { | 1145 | { |
1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_pretty_printer\n"); | 1146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_pretty_printer\n"); |
1147 | |||
1148 | |||
1109 | asc (asc_cls, NULL); | 1149 | asc (asc_cls, NULL); |
1110 | } | 1150 | } |
1111 | 1151 | ||
@@ -1158,6 +1198,61 @@ http_plugin_address_to_string (void *cls, | |||
1158 | } | 1198 | } |
1159 | 1199 | ||
1160 | /** | 1200 | /** |
1201 | * Add the IP of our network interface to the list of | ||
1202 | * our external IP addresses. | ||
1203 | * | ||
1204 | * @param cls the 'struct Plugin*' | ||
1205 | * @param name name of the interface | ||
1206 | * @param isDefault do we think this may be our default interface | ||
1207 | * @param addr address of the interface | ||
1208 | * @param addrlen number of bytes in addr | ||
1209 | * @return GNUNET_OK to continue iterating | ||
1210 | */ | ||
1211 | static int | ||
1212 | process_interfaces (void *cls, | ||
1213 | const char *name, | ||
1214 | int isDefault, | ||
1215 | const struct sockaddr *addr, socklen_t addrlen) | ||
1216 | { | ||
1217 | struct IPv4HttpAddress t4; | ||
1218 | struct IPv6HttpAddress t6; | ||
1219 | int af; | ||
1220 | void *arg; | ||
1221 | uint16_t args; | ||
1222 | |||
1223 | af = addr->sa_family; | ||
1224 | if (af == AF_INET) | ||
1225 | { | ||
1226 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | ||
1227 | t4.u_port = htons (plugin->port_inbound); | ||
1228 | arg = &t4; | ||
1229 | args = sizeof (t4); | ||
1230 | } | ||
1231 | else if (af == AF_INET6) | ||
1232 | { | ||
1233 | if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) | ||
1234 | { | ||
1235 | /* skip link local addresses */ | ||
1236 | return GNUNET_OK; | ||
1237 | } | ||
1238 | memcpy (&t6.ipv6_addr, | ||
1239 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
1240 | sizeof (struct in6_addr)); | ||
1241 | t6.u6_port = htons (plugin->port_inbound); | ||
1242 | arg = &t6; | ||
1243 | args = sizeof (t6); | ||
1244 | } | ||
1245 | else | ||
1246 | { | ||
1247 | GNUNET_break (0); | ||
1248 | return GNUNET_OK; | ||
1249 | } | ||
1250 | plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL); | ||
1251 | |||
1252 | return GNUNET_OK; | ||
1253 | } | ||
1254 | |||
1255 | /** | ||
1161 | * Exit point from the plugin. | 1256 | * Exit point from the plugin. |
1162 | */ | 1257 | */ |
1163 | void * | 1258 | void * |
@@ -1302,7 +1397,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1302 | libgnunet_plugin_transport_http_done (api); | 1397 | libgnunet_plugin_transport_http_done (api); |
1303 | return NULL; | 1398 | return NULL; |
1304 | } | 1399 | } |
1305 | 1400 | plugin->port_inbound = port; | |
1306 | gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; | 1401 | gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; |
1307 | timeout = ( gn_timeout.value / 1000); | 1402 | timeout = ( gn_timeout.value / 1000); |
1308 | if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0)) | 1403 | if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0)) |
@@ -1340,6 +1435,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1340 | if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 1435 | if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK) |
1341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); | 1436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); |
1342 | 1437 | ||
1438 | |||
1343 | /* Initializing cURL */ | 1439 | /* Initializing cURL */ |
1344 | multi_handle = curl_multi_init(); | 1440 | multi_handle = curl_multi_init(); |
1345 | if ( NULL == multi_handle ) | 1441 | if ( NULL == multi_handle ) |
@@ -1351,6 +1447,9 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1351 | libgnunet_plugin_transport_http_done (api); | 1447 | libgnunet_plugin_transport_http_done (api); |
1352 | return NULL; | 1448 | return NULL; |
1353 | } | 1449 | } |
1450 | |||
1451 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | ||
1452 | |||
1354 | return api; | 1453 | return api; |
1355 | } | 1454 | } |
1356 | 1455 | ||
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index aa32e3eb1..6e717470c 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c | |||
@@ -121,6 +121,16 @@ static GNUNET_SCHEDULER_TaskIdentifier ti_send; | |||
121 | 121 | ||
122 | const struct GNUNET_PeerIdentity * p; | 122 | const struct GNUNET_PeerIdentity * p; |
123 | 123 | ||
124 | |||
125 | /** | ||
126 | * Did the test pass or fail? | ||
127 | */ | ||
128 | static int fail_notify_address; | ||
129 | /** | ||
130 | * Did the test pass or fail? | ||
131 | */ | ||
132 | static int fail_notify_address_count; | ||
133 | |||
124 | /** | 134 | /** |
125 | * Did the test pass or fail? | 135 | * Did the test pass or fail? |
126 | */ | 136 | */ |
@@ -220,6 +230,45 @@ receive (void *cls, | |||
220 | return GNUNET_TIME_UNIT_ZERO; | 230 | return GNUNET_TIME_UNIT_ZERO; |
221 | } | 231 | } |
222 | 232 | ||
233 | |||
234 | /** | ||
235 | * Network format for IPv4 addresses. | ||
236 | */ | ||
237 | struct IPv4HttpAddress | ||
238 | { | ||
239 | /** | ||
240 | * IPv4 address, in network byte order. | ||
241 | */ | ||
242 | uint32_t ipv4_addr; | ||
243 | |||
244 | /** | ||
245 | * Port number, in network byte order. | ||
246 | */ | ||
247 | uint16_t u_port; | ||
248 | |||
249 | }; | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Network format for IPv6 addresses. | ||
254 | */ | ||
255 | struct IPv6HttpAddress | ||
256 | { | ||
257 | /** | ||
258 | * IPv6 address. | ||
259 | */ | ||
260 | struct in6_addr ipv6_addr; | ||
261 | |||
262 | /** | ||
263 | * Port number, in network byte order. | ||
264 | */ | ||
265 | uint16_t u6_port; | ||
266 | |||
267 | }; | ||
268 | |||
269 | /** | ||
270 | * Plugin notifies transport (aka testcase) about its addresses | ||
271 | */ | ||
223 | void | 272 | void |
224 | notify_address (void *cls, | 273 | notify_address (void *cls, |
225 | const char *name, | 274 | const char *name, |
@@ -227,7 +276,27 @@ notify_address (void *cls, | |||
227 | uint16_t addrlen, | 276 | uint16_t addrlen, |
228 | struct GNUNET_TIME_Relative expires) | 277 | struct GNUNET_TIME_Relative expires) |
229 | { | 278 | { |
279 | char * address = NULL; | ||
280 | unsigned int port; | ||
230 | 281 | ||
282 | |||
283 | if (addrlen == (sizeof (struct IPv4HttpAddress))) | ||
284 | { | ||
285 | address = GNUNET_malloc (INET_ADDRSTRLEN); | ||
286 | inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN); | ||
287 | port = ntohs(((struct IPv4HttpAddress *) addr)->u_port); | ||
288 | } | ||
289 | |||
290 | if (addrlen == (sizeof (struct IPv6HttpAddress))) | ||
291 | { | ||
292 | address = GNUNET_malloc (INET6_ADDRSTRLEN); | ||
293 | inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN); | ||
294 | port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port); | ||
295 | } | ||
296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Transport plugin notification for address: `%s':%u\n"),address,port); | ||
297 | fail_notify_address_count++; | ||
298 | |||
299 | fail_notify_address = GNUNET_NO; | ||
231 | } | 300 | } |
232 | 301 | ||
233 | /** | 302 | /** |
@@ -308,8 +377,7 @@ run (void *cls, | |||
308 | if (my_private_key == NULL) | 377 | if (my_private_key == NULL) |
309 | { | 378 | { |
310 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
311 | _ | 380 | _("Transport service could not access hostkey. Exiting.\n")); |
312 | ("Transport service could not access hostkey. Exiting.\n")); | ||
313 | GNUNET_SCHEDULER_shutdown (s); | 381 | GNUNET_SCHEDULER_shutdown (s); |
314 | fail = 1; | 382 | fail = 1; |
315 | return; | 383 | return; |
@@ -335,12 +403,18 @@ run (void *cls, | |||
335 | ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT, &task_timeout, NULL); | 403 | ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT, &task_timeout, NULL); |
336 | 404 | ||
337 | /* testing plugin functionality */ | 405 | /* testing plugin functionality */ |
338 | 406 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"), fail_notify_address_count); | |
339 | 407 | ||
340 | /* testing finished, shutting down */ | 408 | /* testing finished, shutting down */ |
409 | |||
410 | if (fail_notify_address == GNUNET_NO) | ||
411 | fail = 0; | ||
412 | |||
413 | |||
414 | |||
341 | shutdown_clean(); | 415 | shutdown_clean(); |
342 | 416 | ||
343 | fail = 0; | 417 | |
344 | return; | 418 | return; |
345 | } | 419 | } |
346 | 420 | ||