From f82cdb61caf9955ea56c6df9448b95ec4e3aacd3 Mon Sep 17 00:00:00 2001 From: Christian Fuchs Date: Tue, 17 Jun 2014 10:35:26 +0000 Subject: - 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...) --- src/nat/nat.c | 19 ++++++++++++++++++- src/nat/nat_auto.c | 9 +++++---- src/nat/nat_mini.c | 4 ++-- src/nat/nat_test.c | 17 +++++++++++++---- src/nat/test_nat_mini.c | 2 +- src/nat/test_nat_test.c | 2 +- src/transport/gnunet-transport.c | 2 +- 7 files changed, 41 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/nat/nat.c b/src/nat/nat.c index 670ae6a27..61ca5eab7 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -1018,7 +1018,7 @@ upnp_add (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen, - enum GNUNET_NAT_FailureCode ret) + enum GNUNET_NAT_StatusCode ret) { struct GNUNET_NAT_Handle *h = cls; struct LocalAddressList *pos; @@ -1561,4 +1561,21 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, } +/** + * Converts enum GNUNET_NAT_StatusCode to a string + * + * @param err error code to resolve to a string + * @return point to a static string containing the error code + */ +const char * +GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err){ + switch (err){ + case GNUNET_NAT_ERROR_SUCCESS: + return _("Operation Successful"); + + default: + return "unknown status code"; + } +} + /* end of nat.c */ diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c index 5b40857af..8fc85d7a7 100644 --- a/src/nat/nat_auto.c +++ b/src/nat/nat_auto.c @@ -144,7 +144,7 @@ struct GNUNET_NAT_AutoHandle /** * Error code for better debugging and user feedback */ - enum GNUNET_NAT_FailureCode ret; + enum GNUNET_NAT_StatusCode ret; }; @@ -167,10 +167,11 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah); */ static void result_callback (void *cls, - enum GNUNET_NAT_FailureCode ret) + enum GNUNET_NAT_StatusCode ret) { struct GNUNET_NAT_AutoHandle *ah = cls; - GNUNET_NAT_test_stop (ah->tst); + if (GNUNET_NAT_ERROR_SUCCESS == ret) + GNUNET_NAT_test_stop (ah->tst); ah->tst = NULL; ah->ret = ret; GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -231,7 +232,7 @@ test_online (struct GNUNET_NAT_AutoHandle *ah) static void set_external_ipv4 (void *cls, const struct in_addr *addr, - enum GNUNET_NAT_FailureCode ret) + enum GNUNET_NAT_StatusCode ret) { struct GNUNET_NAT_AutoHandle *ah = cls; char buf[INET_ADDRSTRLEN]; diff --git a/src/nat/nat_mini.c b/src/nat/nat_mini.c index ae15b5c13..1e8ab7ecc 100644 --- a/src/nat/nat_mini.c +++ b/src/nat/nat_mini.c @@ -101,7 +101,7 @@ struct GNUNET_NAT_ExternalHandle /** * Error code for better debugging and user feedback */ - enum GNUNET_NAT_FailureCode ret; + enum GNUNET_NAT_StatusCode ret; }; @@ -223,7 +223,7 @@ GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout, if (NULL == eh->eip) { GNUNET_DISK_pipe_close (eh->opipe); - eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_EXECUTEABLE; + eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED; eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh); return eh; 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 */ uint16_t adv_port; + /** + * Status code to be reported to the timeout/status call + */ + enum GNUNET_NAT_StatusCode status; }; @@ -371,6 +375,8 @@ addr_cb (void *cls, * Timeout task for a nat test. * Calls the report-callback with a timeout return value * + * Destroys the nat handle after the callback has been processed. + * * @param cls handle to the timed out NAT test * @param tc not used */ @@ -381,7 +387,7 @@ do_timeout (void *cls, struct GNUNET_NAT_Test *nh = (struct GNUNET_NAT_Test *) cls; nh->ttask = GNUNET_SCHEDULER_NO_TASK; - nh->report (nh->report_cls, GNUNET_NAT_ERROR_TIMEOUT); + nh->report (nh->report_cls, (GNUNET_NAT_ERROR_SUCCESS == nh->status)? GNUNET_NAT_ERROR_TIMEOUT: nh->status ); GNUNET_NAT_test_stop(nh); } @@ -400,7 +406,7 @@ do_timeout (void *cls, * @param timeout delay after which the test should be aborted * @param report function to call with the result of the test * @param report_cls closure for @a report - * @return handle to cancel NAT test + * @return handle to cancel NAT test or NULL. The error is indicated through the report callback */ struct GNUNET_NAT_Test * GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, @@ -431,6 +437,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, nh->report = report; nh->report_cls = report_cls; nh->ttask = GNUNET_SCHEDULER_NO_TASK; + nh->status = GNUNET_NAT_ERROR_SUCCESS; if (0 == bnd_port) { nh->nat = @@ -455,7 +462,8 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, STRERROR (errno)); if (NULL != nh->lsock) GNUNET_NETWORK_socket_close (nh->lsock); - GNUNET_free (nh); + nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; + nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh); return NULL; } if (GNUNET_YES == is_tcp) @@ -485,7 +493,8 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SCHEDULER_cancel (nh->ltask); if (NULL != nh->lsock) GNUNET_NETWORK_socket_close (nh->lsock); - GNUNET_free (nh); + nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; + nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh); return NULL; } } diff --git a/src/nat/test_nat_mini.c b/src/nat/test_nat_mini.c index e9dab8351..da6e09d76 100644 --- a/src/nat/test_nat_mini.c +++ b/src/nat/test_nat_mini.c @@ -45,7 +45,7 @@ static void addr_callback (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen, - enum GNUNET_NAT_FailureCode ret) + enum GNUNET_NAT_StatusCode ret) { if (GNUNET_NAT_ERROR_SUCCESS == ret) { diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c index 4095e840c..e86f2ed11 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c @@ -41,7 +41,7 @@ static struct GNUNET_NAT_Test *tst; static void report_result (void *cls, - enum GNUNET_NAT_FailureCode aret) + enum GNUNET_NAT_StatusCode aret) { if (GNUNET_NAT_ERROR_TIMEOUT == aret) fprintf (stderr, diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 8cd606f81..2f6604bdf 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -545,7 +545,7 @@ display_test_result (struct TestContext *tc, enum TestResult result) * @param emsg error message, NULL on success */ static void -result_callback (void *cls, enum GNUNET_NAT_FailureCode result) +result_callback (void *cls, enum GNUNET_NAT_StatusCode result) { struct TestContext *tc = cls; display_test_result (tc, result); -- cgit v1.2.3