diff options
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r-- | src/transport/test_transport_api.c | 68 |
1 files changed, 25 insertions, 43 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index a43f971a0..2db990e82 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -19,7 +19,12 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api.c | 21 | * @file transport/test_transport_api.c |
22 | * @brief testcase for transport_api.c | 22 | * @brief base test case for transport implementations |
23 | * | ||
24 | * This test case serves as a base for tcp, udp, and udp-nat | ||
25 | * transport test cases. Based on the executable being run | ||
26 | * the correct test case will be performed. Conservation of | ||
27 | * C code apparently. | ||
23 | */ | 28 | */ |
24 | #include "platform.h" | 29 | #include "platform.h" |
25 | #include "gnunet_common.h" | 30 | #include "gnunet_common.h" |
@@ -31,14 +36,12 @@ | |||
31 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
32 | #include "transport.h" | 37 | #include "transport.h" |
33 | 38 | ||
34 | #define VERBOSE GNUNET_NO | 39 | #define VERBOSE GNUNET_YES |
35 | 40 | ||
36 | #define VERBOSE_ARM GNUNET_NO | 41 | #define VERBOSE_ARM GNUNET_NO |
37 | 42 | ||
38 | #define START_ARM GNUNET_YES | 43 | #define START_ARM GNUNET_YES |
39 | 44 | ||
40 | #define VERBOSE_TRANSPORT GNUNET_NO | ||
41 | |||
42 | /** | 45 | /** |
43 | * How long until we give up on transmitting the message? | 46 | * How long until we give up on transmitting the message? |
44 | */ | 47 | */ |
@@ -68,6 +71,8 @@ static int is_tcp; | |||
68 | 71 | ||
69 | static int is_udp; | 72 | static int is_udp; |
70 | 73 | ||
74 | static int is_udp_nat; | ||
75 | |||
71 | GNUNET_SCHEDULER_TaskIdentifier die_task; | 76 | GNUNET_SCHEDULER_TaskIdentifier die_task; |
72 | 77 | ||
73 | #if VERBOSE | 78 | #if VERBOSE |
@@ -231,7 +236,8 @@ exchange_hello_last (void *cls, | |||
231 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 236 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
232 | message, &me->id)); | 237 | message, &me->id)); |
233 | 238 | ||
234 | GNUNET_TRANSPORT_offer_hello (p1.th, message); | 239 | /* Can't we get away with only offering one hello? */ |
240 | /* GNUNET_TRANSPORT_offer_hello (p1.th, message); */ | ||
235 | 241 | ||
236 | /*sleep(1);*/ /* Make sure we are not falling prey to the "favorable timing" bug... */ | 242 | /*sleep(1);*/ /* Make sure we are not falling prey to the "favorable timing" bug... */ |
237 | 243 | ||
@@ -264,44 +270,6 @@ exchange_hello (void *cls, | |||
264 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | 270 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); |
265 | } | 271 | } |
266 | 272 | ||
267 | #if WRITECONFIG | ||
268 | static void | ||
269 | setTransportOptions(char * filename) | ||
270 | { | ||
271 | struct GNUNET_CONFIGURATION_Handle * tempcfg; | ||
272 | |||
273 | tempcfg = GNUNET_CONFIGURATION_create(); | ||
274 | GNUNET_CONFIGURATION_load (tempcfg, filename); | ||
275 | |||
276 | unsigned long long curr_port; | ||
277 | GNUNET_CONFIGURATION_get_value_number(tempcfg, "transport", "port", &curr_port); | ||
278 | |||
279 | if (is_udp) | ||
280 | { | ||
281 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "plugins", "udp"); | ||
282 | GNUNET_CONFIGURATION_set_value_number(tempcfg, "transport-udp", "PORT", curr_port + 3); | ||
283 | } | ||
284 | else if (is_tcp) | ||
285 | { | ||
286 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "plugins", "tcp"); | ||
287 | GNUNET_CONFIGURATION_set_value_number(tempcfg, "transport-tcp", "port", curr_port + 3); | ||
288 | } | ||
289 | |||
290 | #if VERBOSE_TRANSPORT | ||
291 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "DEBUG", "YES"); | ||
292 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "PREFIX", "xterm -e xterm -T transport -e gdb --args"); | ||
293 | #else | ||
294 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "DEBUG", "NO"); | ||
295 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "PREFIX", ""); | ||
296 | #endif | ||
297 | |||
298 | GNUNET_CONFIGURATION_write(tempcfg, filename); | ||
299 | |||
300 | GNUNET_CONFIGURATION_destroy(tempcfg); | ||
301 | return; | ||
302 | } | ||
303 | #endif | ||
304 | |||
305 | static void | 273 | static void |
306 | run (void *cls, | 274 | run (void *cls, |
307 | struct GNUNET_SCHEDULER_Handle *s, | 275 | struct GNUNET_SCHEDULER_Handle *s, |
@@ -325,6 +293,14 @@ run (void *cls, | |||
325 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); | 293 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); |
326 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); | 294 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); |
327 | } | 295 | } |
296 | if (is_udp_nat) | ||
297 | { | ||
298 | setup_peer (&p1, "test_transport_api_udp_nat_peer1.conf"); | ||
299 | setup_peer (&p2, "test_transport_api_udp_nat_peer2.conf"); | ||
300 | } | ||
301 | |||
302 | GNUNET_assert(p1.th != NULL); | ||
303 | GNUNET_assert(p2.th != NULL); | ||
328 | 304 | ||
329 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | 305 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); |
330 | } | 306 | } |
@@ -366,8 +342,14 @@ main (int argc, char *argv[]) | |||
366 | 342 | ||
367 | if (strstr(argv[0], "tcp") != NULL) | 343 | if (strstr(argv[0], "tcp") != NULL) |
368 | { | 344 | { |
345 | |||
369 | is_tcp = GNUNET_YES; | 346 | is_tcp = GNUNET_YES; |
370 | } | 347 | } |
348 | else if (strstr(argv[0], "udp_nat") != NULL) | ||
349 | { | ||
350 | fprintf(stderr, "this is a udp_nat test!\n"); | ||
351 | is_udp_nat = GNUNET_YES; | ||
352 | } | ||
371 | else if (strstr(argv[0], "udp") != NULL) | 353 | else if (strstr(argv[0], "udp") != NULL) |
372 | { | 354 | { |
373 | is_udp = GNUNET_YES; | 355 | is_udp = GNUNET_YES; |