diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-06-08 15:26:55 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-06-08 15:26:55 +0000 |
commit | a860f03c736a43edf67bd9166eccbae2a553991d (patch) | |
tree | 38cb578fe47ccab77d62b13b5b2f103fc51c7e53 /src/nat | |
parent | bddb39798942db2d4a1603487ebbc13d6f5c60bd (diff) | |
download | gnunet-a860f03c736a43edf67bd9166eccbae2a553991d.tar.gz gnunet-a860f03c736a43edf67bd9166eccbae2a553991d.zip |
- moved timeout handling responsibility from for nat tests from caller to the library
- updated NAT API accordingly
- removed obsolete timeout handling code from gnunet-transport
- updated result callback for nat-test gnunet-transport to not always just report success, but we now actually report the proper result code we got from the NAT API
- updated nat tests
Diffstat (limited to 'src/nat')
-rw-r--r-- | src/nat/nat_auto.c | 58 | ||||
-rw-r--r-- | src/nat/nat_test.c | 33 | ||||
-rw-r--r-- | src/nat/test_nat_test.c | 16 |
3 files changed, 40 insertions, 67 deletions
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c index 3ee520d9b..5b40857af 100644 --- a/src/nat/nat_auto.c +++ b/src/nat/nat_auto.c | |||
@@ -158,35 +158,8 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah); | |||
158 | 158 | ||
159 | 159 | ||
160 | /** | 160 | /** |
161 | * Function called if NAT failed to confirm success. | 161 | * Function called by NAT to report the outcome of the nat-test. |
162 | * Clean up and update GUI (with failure). | 162 | * Clean up and update GUI. |
163 | * | ||
164 | * @param cls closure with setup context | ||
165 | * @param tc scheduler callback | ||
166 | */ | ||
167 | static void | ||
168 | fail_timeout (void *cls, | ||
169 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
170 | { | ||
171 | struct GNUNET_NAT_AutoHandle *ah = cls; | ||
172 | |||
173 | ah->ret = GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT; | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
175 | _("NAT traversal with ICMP Server timed out.\n")); | ||
176 | GNUNET_assert (NULL != ah->tst); | ||
177 | ah->task = GNUNET_SCHEDULER_NO_TASK; | ||
178 | GNUNET_NAT_test_stop (ah->tst); | ||
179 | ah->tst = NULL; | ||
180 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", | ||
181 | "ENABLE_ICMP_SERVER", | ||
182 | "NO"); | ||
183 | next_phase (ah); | ||
184 | } | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Function called by NAT on success. | ||
189 | * Clean up and update GUI (with success). | ||
190 | * | 163 | * |
191 | * @param cls the auto handle | 164 | * @param cls the auto handle |
192 | * @param success currently always #GNUNET_OK | 165 | * @param success currently always #GNUNET_OK |
@@ -197,17 +170,15 @@ result_callback (void *cls, | |||
197 | enum GNUNET_NAT_FailureCode ret) | 170 | enum GNUNET_NAT_FailureCode ret) |
198 | { | 171 | { |
199 | struct GNUNET_NAT_AutoHandle *ah = cls; | 172 | struct GNUNET_NAT_AutoHandle *ah = cls; |
200 | |||
201 | GNUNET_SCHEDULER_cancel (ah->task); | ||
202 | ah->task = GNUNET_SCHEDULER_NO_TASK; | ||
203 | GNUNET_NAT_test_stop (ah->tst); | 173 | GNUNET_NAT_test_stop (ah->tst); |
204 | ah->tst = NULL; | 174 | ah->tst = NULL; |
175 | ah->ret = ret; | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
206 | ret | 177 | GNUNET_NAT_ERROR_SUCCESS == ret |
207 | ? _("NAT traversal with ICMP Server succeeded.\n") | 178 | ? _("NAT traversal with ICMP Server succeeded.\n") |
208 | : _("NAT traversal with ICMP Server failed.\n")); | 179 | : _("NAT traversal with ICMP Server failed.\n")); |
209 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER", | 180 | GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER", |
210 | ret ? "NO" : "YES"); | 181 | GNUNET_NAT_ERROR_SUCCESS == ret ? "NO" : "YES"); |
211 | next_phase (ah); | 182 | next_phase (ah); |
212 | } | 183 | } |
213 | 184 | ||
@@ -228,15 +199,8 @@ reversal_test (void *cls, | |||
228 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
229 | _("Testing connection reversal with ICMP server.\n")); | 200 | _("Testing connection reversal with ICMP server.\n")); |
230 | GNUNET_RESOLVER_connect (ah->cfg); | 201 | GNUNET_RESOLVER_connect (ah->cfg); |
231 | ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0, | 202 | ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0, TIMEOUT, |
232 | &result_callback, ah); | 203 | &result_callback, ah); |
233 | if (NULL == ah->tst) | ||
234 | { | ||
235 | ah->ret = GNUNET_NAT_ERROR_NAT_TEST_START_FAILED; | ||
236 | next_phase (ah); | ||
237 | return; | ||
238 | } | ||
239 | ah->task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, ah); | ||
240 | } | 204 | } |
241 | 205 | ||
242 | 206 | ||
@@ -506,15 +470,8 @@ err: | |||
506 | static void | 470 | static void |
507 | test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) | 471 | test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) |
508 | { | 472 | { |
509 | int ext_ip; | ||
510 | int nated; | ||
511 | int binary; | ||
512 | char *tmp; | 473 | char *tmp; |
513 | char *helper; | 474 | char *helper; |
514 | |||
515 | ext_ip = GNUNET_NO; | ||
516 | nated = GNUNET_NO; | ||
517 | binary = GNUNET_NO; | ||
518 | 475 | ||
519 | tmp = NULL; | 476 | tmp = NULL; |
520 | helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | 477 | helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); |
@@ -522,7 +479,6 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) | |||
522 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS", | 479 | GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS", |
523 | &tmp)) && (0 < strlen (tmp))) | 480 | &tmp)) && (0 < strlen (tmp))) |
524 | { | 481 | { |
525 | ext_ip = GNUNET_OK; | ||
526 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_client not possible, as we have no internal IPv4 address\n")); | 482 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_client not possible, as we have no internal IPv4 address\n")); |
527 | } | 483 | } |
528 | else | 484 | else |
@@ -530,7 +486,6 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) | |||
530 | 486 | ||
531 | if (GNUNET_YES != | 487 | if (GNUNET_YES != |
532 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){ | 488 | GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){ |
533 | nated = GNUNET_YES; | ||
534 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n")); | 489 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n")); |
535 | } | 490 | } |
536 | else | 491 | else |
@@ -539,7 +494,6 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) | |||
539 | if (GNUNET_YES == | 494 | if (GNUNET_YES == |
540 | GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){ | 495 | GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){ |
541 | // none of these parameters are actually used in privilege testing mode | 496 | // none of these parameters are actually used in privilege testing mode |
542 | binary = GNUNET_OK; | ||
543 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n")); | 497 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n")); |
544 | } | 498 | } |
545 | err: | 499 | err: |
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 84cf3b01b..2836730ca 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c | |||
@@ -142,6 +142,11 @@ struct GNUNET_NAT_Test | |||
142 | * Identity of task for the listen socket (if any) | 142 | * Identity of task for the listen socket (if any) |
143 | */ | 143 | */ |
144 | GNUNET_SCHEDULER_TaskIdentifier ltask; | 144 | GNUNET_SCHEDULER_TaskIdentifier ltask; |
145 | |||
146 | /** | ||
147 | * Task identifier for the timeout (if any) | ||
148 | */ | ||
149 | GNUNET_SCHEDULER_TaskIdentifier ttask; | ||
145 | 150 | ||
146 | /** | 151 | /** |
147 | * GNUNET_YES if we're testing TCP | 152 | * GNUNET_YES if we're testing TCP |
@@ -363,13 +368,36 @@ addr_cb (void *cls, | |||
363 | 368 | ||
364 | 369 | ||
365 | /** | 370 | /** |
371 | * Timeout task for a nat test. | ||
372 | * Calls the report-callback with a timeout return value | ||
373 | * | ||
374 | * @param cls handle to the timed out NAT test | ||
375 | * @param tc not used | ||
376 | */ | ||
377 | static void | ||
378 | do_timeout (void *cls, | ||
379 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
380 | { | ||
381 | struct GNUNET_NAT_Test *nh = (struct GNUNET_NAT_Test *) cls; | ||
382 | |||
383 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; | ||
384 | nh->report (nh->report_cls, GNUNET_NAT_ERROR_TIMEOUT); | ||
385 | |||
386 | GNUNET_NAT_test_stop(nh); | ||
387 | } | ||
388 | |||
389 | |||
390 | /** | ||
366 | * Start testing if NAT traversal works using the | 391 | * Start testing if NAT traversal works using the |
367 | * given configuration (IPv4-only). | 392 | * given configuration (IPv4-only). |
393 | * | ||
394 | * ALL failures are reported directly to the report callback | ||
368 | * | 395 | * |
369 | * @param cfg configuration for the NAT traversal | 396 | * @param cfg configuration for the NAT traversal |
370 | * @param is_tcp #GNUNET_YES to test TCP, #GNUNET_NO to test UDP | 397 | * @param is_tcp #GNUNET_YES to test TCP, #GNUNET_NO to test UDP |
371 | * @param bnd_port port to bind to, 0 for connection reversal | 398 | * @param bnd_port port to bind to, 0 for connection reversal |
372 | * @param adv_port externally advertised port to use | 399 | * @param adv_port externally advertised port to use |
400 | * @param timeout delay after which the test should be aborted | ||
373 | * @param report function to call with the result of the test | 401 | * @param report function to call with the result of the test |
374 | * @param report_cls closure for @a report | 402 | * @param report_cls closure for @a report |
375 | * @return handle to cancel NAT test | 403 | * @return handle to cancel NAT test |
@@ -379,6 +407,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
379 | int is_tcp, | 407 | int is_tcp, |
380 | uint16_t bnd_port, | 408 | uint16_t bnd_port, |
381 | uint16_t adv_port, | 409 | uint16_t adv_port, |
410 | struct GNUNET_TIME_Relative timeout, | ||
382 | GNUNET_NAT_TestCallback report, | 411 | GNUNET_NAT_TestCallback report, |
383 | void *report_cls) | 412 | void *report_cls) |
384 | { | 413 | { |
@@ -401,6 +430,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
401 | nh->adv_port = adv_port; | 430 | nh->adv_port = adv_port; |
402 | nh->report = report; | 431 | nh->report = report; |
403 | nh->report_cls = report_cls; | 432 | nh->report_cls = report_cls; |
433 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; | ||
404 | if (0 == bnd_port) | 434 | if (0 == bnd_port) |
405 | { | 435 | { |
406 | nh->nat = | 436 | nh->nat = |
@@ -459,6 +489,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
459 | return NULL; | 489 | return NULL; |
460 | } | 490 | } |
461 | } | 491 | } |
492 | nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, nh); | ||
462 | return nh; | 493 | return nh; |
463 | } | 494 | } |
464 | 495 | ||
@@ -489,6 +520,8 @@ GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst) | |||
489 | GNUNET_NETWORK_socket_close (pos->sock); | 520 | GNUNET_NETWORK_socket_close (pos->sock); |
490 | GNUNET_free (pos); | 521 | GNUNET_free (pos); |
491 | } | 522 | } |
523 | if (GNUNET_SCHEDULER_NO_TASK != tst->ttask) | ||
524 | GNUNET_SCHEDULER_cancel (tst->ttask); | ||
492 | if (GNUNET_SCHEDULER_NO_TASK != tst->ltask) | 525 | if (GNUNET_SCHEDULER_NO_TASK != tst->ltask) |
493 | GNUNET_SCHEDULER_cancel (tst->ltask); | 526 | GNUNET_SCHEDULER_cancel (tst->ltask); |
494 | if (NULL != tst->lsock) | 527 | if (NULL != tst->lsock) |
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c index 39bd6612e..e8f0f5a47 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c | |||
@@ -39,23 +39,12 @@ static int ret = 1; | |||
39 | 39 | ||
40 | static struct GNUNET_NAT_Test *tst; | 40 | static struct GNUNET_NAT_Test *tst; |
41 | 41 | ||
42 | static GNUNET_SCHEDULER_TaskIdentifier end; | ||
43 | |||
44 | static void | ||
45 | end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
46 | { | ||
47 | GNUNET_NAT_test_stop (tst); | ||
48 | } | ||
49 | |||
50 | |||
51 | static void | 42 | static void |
52 | report_success (void *cls, | 43 | report_success (void *cls, |
53 | enum GNUNET_NAT_FailureCode aret) | 44 | enum GNUNET_NAT_FailureCode aret) |
54 | { | 45 | { |
55 | GNUNET_assert (GNUNET_NAT_ERROR_SUCCESS == aret); | 46 | GNUNET_assert (GNUNET_NAT_ERROR_SUCCESS == aret); |
56 | ret = 0; | 47 | ret = 0; |
57 | GNUNET_SCHEDULER_cancel (end); | ||
58 | end = GNUNET_SCHEDULER_add_now (&end_test, NULL); | ||
59 | } | 48 | } |
60 | 49 | ||
61 | 50 | ||
@@ -67,12 +56,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
67 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 56 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
68 | { | 57 | { |
69 | tst = | 58 | tst = |
70 | GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, | 59 | GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT |
71 | &report_success, | 60 | &report_success, |
72 | NULL); | 61 | NULL); |
73 | if (NULL == tst) | ||
74 | return; | ||
75 | end = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | ||
76 | } | 62 | } |
77 | 63 | ||
78 | 64 | ||