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/nat_test.c | |
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/nat_test.c')
-rw-r--r-- | src/nat/nat_test.c | 33 |
1 files changed, 33 insertions, 0 deletions
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) |