diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-06-17 10:35:26 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-06-17 10:35:26 +0000 |
commit | f82cdb61caf9955ea56c6df9448b95ec4e3aacd3 (patch) | |
tree | eed6d199b16a898db2cbf116037e41e0e0183299 /src/nat/nat_test.c | |
parent | 4ef7a6973707d2e5588372861197f7068737e765 (diff) | |
download | gnunet-f82cdb61caf9955ea56c6df9448b95ec4e3aacd3.tar.gz gnunet-f82cdb61caf9955ea56c6df9448b95ec4e3aacd3.zip |
- renamed NAT's failure code to status code across gnunet (not GTK yet)
- added proper error reporting to NAT-test-start/stop
- timed-out nat tests not automatically stop the test itself
- fixed a design flaw in nat-test
- fixed a potential crash in the tests of the nat functionality (NOT NAT_TEST_xy...)
Diffstat (limited to 'src/nat/nat_test.c')
-rw-r--r-- | src/nat/nat_test.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 2836730ca..860c51b26 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c | |||
@@ -163,6 +163,10 @@ struct GNUNET_NAT_Test | |||
163 | */ | 163 | */ |
164 | uint16_t adv_port; | 164 | uint16_t adv_port; |
165 | 165 | ||
166 | /** | ||
167 | * Status code to be reported to the timeout/status call | ||
168 | */ | ||
169 | enum GNUNET_NAT_StatusCode status; | ||
166 | }; | 170 | }; |
167 | 171 | ||
168 | 172 | ||
@@ -371,6 +375,8 @@ addr_cb (void *cls, | |||
371 | * Timeout task for a nat test. | 375 | * Timeout task for a nat test. |
372 | * Calls the report-callback with a timeout return value | 376 | * Calls the report-callback with a timeout return value |
373 | * | 377 | * |
378 | * Destroys the nat handle after the callback has been processed. | ||
379 | * | ||
374 | * @param cls handle to the timed out NAT test | 380 | * @param cls handle to the timed out NAT test |
375 | * @param tc not used | 381 | * @param tc not used |
376 | */ | 382 | */ |
@@ -381,7 +387,7 @@ do_timeout (void *cls, | |||
381 | struct GNUNET_NAT_Test *nh = (struct GNUNET_NAT_Test *) cls; | 387 | struct GNUNET_NAT_Test *nh = (struct GNUNET_NAT_Test *) cls; |
382 | 388 | ||
383 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; | 389 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; |
384 | nh->report (nh->report_cls, GNUNET_NAT_ERROR_TIMEOUT); | 390 | nh->report (nh->report_cls, (GNUNET_NAT_ERROR_SUCCESS == nh->status)? GNUNET_NAT_ERROR_TIMEOUT: nh->status ); |
385 | 391 | ||
386 | GNUNET_NAT_test_stop(nh); | 392 | GNUNET_NAT_test_stop(nh); |
387 | } | 393 | } |
@@ -400,7 +406,7 @@ do_timeout (void *cls, | |||
400 | * @param timeout delay after which the test should be aborted | 406 | * @param timeout delay after which the test should be aborted |
401 | * @param report function to call with the result of the test | 407 | * @param report function to call with the result of the test |
402 | * @param report_cls closure for @a report | 408 | * @param report_cls closure for @a report |
403 | * @return handle to cancel NAT test | 409 | * @return handle to cancel NAT test or NULL. The error is indicated through the report callback |
404 | */ | 410 | */ |
405 | struct GNUNET_NAT_Test * | 411 | struct GNUNET_NAT_Test * |
406 | GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 412 | GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -431,6 +437,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
431 | nh->report = report; | 437 | nh->report = report; |
432 | nh->report_cls = report_cls; | 438 | nh->report_cls = report_cls; |
433 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; | 439 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; |
440 | nh->status = GNUNET_NAT_ERROR_SUCCESS; | ||
434 | if (0 == bnd_port) | 441 | if (0 == bnd_port) |
435 | { | 442 | { |
436 | nh->nat = | 443 | nh->nat = |
@@ -455,7 +462,8 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
455 | STRERROR (errno)); | 462 | STRERROR (errno)); |
456 | if (NULL != nh->lsock) | 463 | if (NULL != nh->lsock) |
457 | GNUNET_NETWORK_socket_close (nh->lsock); | 464 | GNUNET_NETWORK_socket_close (nh->lsock); |
458 | GNUNET_free (nh); | 465 | nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; |
466 | nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh); | ||
459 | return NULL; | 467 | return NULL; |
460 | } | 468 | } |
461 | if (GNUNET_YES == is_tcp) | 469 | if (GNUNET_YES == is_tcp) |
@@ -485,7 +493,8 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
485 | GNUNET_SCHEDULER_cancel (nh->ltask); | 493 | GNUNET_SCHEDULER_cancel (nh->ltask); |
486 | if (NULL != nh->lsock) | 494 | if (NULL != nh->lsock) |
487 | GNUNET_NETWORK_socket_close (nh->lsock); | 495 | GNUNET_NETWORK_socket_close (nh->lsock); |
488 | GNUNET_free (nh); | 496 | nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; |
497 | nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh); | ||
489 | return NULL; | 498 | return NULL; |
490 | } | 499 | } |
491 | } | 500 | } |