aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-03-18 13:32:01 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-03-18 13:32:01 +0000
commit36a3ceafd059b7473cf63ae26d6e332bf3a9ef45 (patch)
tree8d28ddb87063e86b6926867360d613a6ab567236 /src/transport/gnunet-transport.c
parent2cf276284178b7c341531092fea13cb6017015d2 (diff)
downloadgnunet-36a3ceafd059b7473cf63ae26d6e332bf3a9ef45.tar.gz
gnunet-36a3ceafd059b7473cf63ae26d6e332bf3a9ef45.zip
fixed configuration testing: NAT testing was not working
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c108
1 files changed, 75 insertions, 33 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index f9d3ad44a..b3af97c20 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -39,7 +39,7 @@
39 * How long do we wait for the NAT test to report success? 39 * How long do we wait for the NAT test to report success?
40 * Should match NAT_SERVER_TIMEOUT in 'nat_test.c'. 40 * Should match NAT_SERVER_TIMEOUT in 'nat_test.c'.
41 */ 41 */
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
43#define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 43#define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
44#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 44#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
45 45
@@ -197,11 +197,6 @@ static int verbosity;
197struct GNUNET_OS_Process *resolver; 197struct GNUNET_OS_Process *resolver;
198 198
199/** 199/**
200 * Number of tasks running that still need the resolver.
201 */
202static unsigned int resolver_users;
203
204/**
205 * Number of address resolutions pending 200 * Number of address resolutions pending
206 */ 201 */
207static unsigned int address_resolutions; 202static unsigned int address_resolutions;
@@ -211,12 +206,30 @@ static unsigned int address_resolutions;
211 */ 206 */
212static unsigned int address_resolution_in_progress; 207static unsigned int address_resolution_in_progress;
213 208
209/**
210 * DLL for NAT Test Contexts: head
211 */
212struct TestContext *head;
213
214/**
215 * DLL for NAT Test Contexts: tail
216 */
217struct TestContext *tail;
214 218
215/** 219/**
216 * Context for a plugin test. 220 * Context for a plugin test.
217 */ 221 */
218struct TestContext 222struct TestContext
219{ 223{
224 /**
225 * Previous in DLL
226 */
227 struct TestContext *prev;
228
229 /**
230 * Next in DLL
231 */
232 struct TestContext *next;
220 233
221 /** 234 /**
222 * Handle to the active NAT test. 235 * Handle to the active NAT test.
@@ -231,7 +244,17 @@ struct TestContext
231 /** 244 /**
232 * Name of plugin under test. 245 * Name of plugin under test.
233 */ 246 */
234 const char *name; 247 char *name;
248
249 /**
250 * Bound port
251 */
252 unsigned long long bnd_port;
253
254 /**
255 * Advertised ports
256 */
257 unsigned long long adv_port;
235 258
236}; 259};
237 260
@@ -399,6 +422,9 @@ operation_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
399 422
400} 423}
401 424
425static void
426run_nat_test ();
427
402/** 428/**
403 * Display the result of the test. 429 * Display the result of the test.
404 * 430 *
@@ -426,14 +452,19 @@ display_test_result (struct TestContext *tc, int result)
426 GNUNET_NAT_test_stop (tc->tst); 452 GNUNET_NAT_test_stop (tc->tst);
427 tc->tst = NULL; 453 tc->tst = NULL;
428 } 454 }
429 GNUNET_free(tc); 455
430 resolver_users--; 456 GNUNET_CONTAINER_DLL_remove (head, tail, tc);
431 if ((0 == resolver_users) && (NULL != resolver)) 457 GNUNET_free (tc->name);
458 GNUNET_free (tc);
459
460 if ((NULL == head) && (NULL != resolver))
432 { 461 {
433 GNUNET_break(0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG)); 462 GNUNET_break(0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG));
434 GNUNET_OS_process_destroy (resolver); 463 GNUNET_OS_process_destroy (resolver);
435 resolver = NULL; 464 resolver = NULL;
436 } 465 }
466 if (NULL != head)
467 run_nat_test ();
437} 468}
438 469
439/** 470/**
@@ -448,7 +479,6 @@ static void
448result_callback (void *cls, int success, const char *emsg) 479result_callback (void *cls, int success, const char *emsg)
449{ 480{
450 struct TestContext *tc = cls; 481 struct TestContext *tc = cls;
451
452 display_test_result (tc, success); 482 display_test_result (tc, success);
453} 483}
454 484
@@ -620,6 +650,22 @@ void process_validation_cb (void *cls,
620 valid_until, next_validation, state); 650 valid_until, next_validation, state);
621} 651}
622 652
653static void
654run_nat_test ()
655{
656 head->tst = GNUNET_NAT_test_start (cfg,
657 (0 == strcasecmp (head->name, "udp")) ? GNUNET_NO : GNUNET_YES,
658 (uint16_t) head->bnd_port,
659 (uint16_t) head->adv_port,
660 &result_callback, head);
661 if (NULL == head->tst)
662 {
663 display_test_result (head, GNUNET_SYSERR);
664 return;
665 }
666 head->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, head);
667}
668
623/** 669/**
624 * Test our plugin's configuration (NAT traversal, etc.). 670 * Test our plugin's configuration (NAT traversal, etc.).
625 * 671 *
@@ -644,10 +690,10 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
644 ret = 4; 690 ret = 4;
645 return; 691 return;
646 } 692 }
693
647 for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " ")) 694 for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " "))
648 { 695 {
649 char section[12 + strlen (tok)]; 696 char section[12 + strlen (tok)];
650
651 GNUNET_snprintf (section, sizeof(section), "transport-%s", tok); 697 GNUNET_snprintf (section, sizeof(section), "transport-%s", tok);
652 if (GNUNET_OK 698 if (GNUNET_OK
653 != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", 699 != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT",
@@ -661,31 +707,27 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
661 != GNUNET_CONFIGURATION_get_value_number (cfg, section, 707 != GNUNET_CONFIGURATION_get_value_number (cfg, section,
662 "ADVERTISED_PORT", &adv_port)) 708 "ADVERTISED_PORT", &adv_port))
663 adv_port = bnd_port; 709 adv_port = bnd_port;
664 if (NULL == resolver) 710
665 {
666 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
667 resolver = GNUNET_OS_start_process (GNUNET_YES,
668 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
669 NULL, NULL, NULL,
670 binary,
671 "gnunet-service-resolver", NULL );
672 GNUNET_free(binary);
673 }
674 resolver_users++;
675 GNUNET_RESOLVER_connect (cfg);
676 tc = GNUNET_new (struct TestContext); 711 tc = GNUNET_new (struct TestContext);
677 tc->name = GNUNET_strdup (tok); 712 tc->name = GNUNET_strdup (tok);
678 tc->tst = GNUNET_NAT_test_start (cfg, 713 tc->adv_port = adv_port;
679 (0 == strcasecmp (tok, "udp")) ? GNUNET_NO : GNUNET_YES, 714 tc->bnd_port = bnd_port;
680 (uint16_t) bnd_port, (uint16_t) adv_port, &result_callback, tc); 715 GNUNET_CONTAINER_DLL_insert_tail (head, tail, tc);
681 if (NULL == tc->tst)
682 {
683 display_test_result (tc, GNUNET_SYSERR);
684 continue;
685 }
686 tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc);
687 } 716 }
688 GNUNET_free(plugins); 717 GNUNET_free(plugins);
718
719 if ((NULL != head) && (NULL == resolver))
720 {
721 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
722 resolver = GNUNET_OS_start_process (GNUNET_YES,
723 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
724 NULL, NULL, NULL,
725 binary,
726 "gnunet-service-resolver", NULL );
727 GNUNET_free(binary);
728 GNUNET_RESOLVER_connect (cfg);
729 run_nat_test ();
730 }
689} 731}
690 732
691/** 733/**