aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2014-06-17 10:35:26 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2014-06-17 10:35:26 +0000
commitf82cdb61caf9955ea56c6df9448b95ec4e3aacd3 (patch)
treeeed6d199b16a898db2cbf116037e41e0e0183299
parent4ef7a6973707d2e5588372861197f7068737e765 (diff)
downloadgnunet-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...)
-rw-r--r--src/nat/nat.c19
-rw-r--r--src/nat/nat_auto.c9
-rw-r--r--src/nat/nat_mini.c4
-rw-r--r--src/nat/nat_test.c17
-rw-r--r--src/nat/test_nat_mini.c2
-rw-r--r--src/nat/test_nat_test.c2
-rw-r--r--src/transport/gnunet-transport.c2
7 files changed, 41 insertions, 14 deletions
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,
1018 int add_remove, 1018 int add_remove,
1019 const struct sockaddr *addr, 1019 const struct sockaddr *addr,
1020 socklen_t addrlen, 1020 socklen_t addrlen,
1021 enum GNUNET_NAT_FailureCode ret) 1021 enum GNUNET_NAT_StatusCode ret)
1022{ 1022{
1023 struct GNUNET_NAT_Handle *h = cls; 1023 struct GNUNET_NAT_Handle *h = cls;
1024 struct LocalAddressList *pos; 1024 struct LocalAddressList *pos;
@@ -1561,4 +1561,21 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
1561} 1561}
1562 1562
1563 1563
1564/**
1565 * Converts enum GNUNET_NAT_StatusCode to a string
1566 *
1567 * @param err error code to resolve to a string
1568 * @return point to a static string containing the error code
1569 */
1570const char *
1571GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err){
1572 switch (err){
1573 case GNUNET_NAT_ERROR_SUCCESS:
1574 return _("Operation Successful");
1575
1576 default:
1577 return "unknown status code";
1578 }
1579}
1580
1564/* end of nat.c */ 1581/* 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
144 /** 144 /**
145 * Error code for better debugging and user feedback 145 * Error code for better debugging and user feedback
146 */ 146 */
147 enum GNUNET_NAT_FailureCode ret; 147 enum GNUNET_NAT_StatusCode ret;
148}; 148};
149 149
150 150
@@ -167,10 +167,11 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah);
167 */ 167 */
168static void 168static void
169result_callback (void *cls, 169result_callback (void *cls,
170 enum GNUNET_NAT_FailureCode ret) 170 enum GNUNET_NAT_StatusCode ret)
171{ 171{
172 struct GNUNET_NAT_AutoHandle *ah = cls; 172 struct GNUNET_NAT_AutoHandle *ah = cls;
173 GNUNET_NAT_test_stop (ah->tst); 173 if (GNUNET_NAT_ERROR_SUCCESS == ret)
174 GNUNET_NAT_test_stop (ah->tst);
174 ah->tst = NULL; 175 ah->tst = NULL;
175 ah->ret = ret; 176 ah->ret = ret;
176 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 177 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -231,7 +232,7 @@ test_online (struct GNUNET_NAT_AutoHandle *ah)
231static void 232static void
232set_external_ipv4 (void *cls, 233set_external_ipv4 (void *cls,
233 const struct in_addr *addr, 234 const struct in_addr *addr,
234 enum GNUNET_NAT_FailureCode ret) 235 enum GNUNET_NAT_StatusCode ret)
235{ 236{
236 struct GNUNET_NAT_AutoHandle *ah = cls; 237 struct GNUNET_NAT_AutoHandle *ah = cls;
237 char buf[INET_ADDRSTRLEN]; 238 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
101 /** 101 /**
102 * Error code for better debugging and user feedback 102 * Error code for better debugging and user feedback
103 */ 103 */
104 enum GNUNET_NAT_FailureCode ret; 104 enum GNUNET_NAT_StatusCode ret;
105}; 105};
106 106
107 107
@@ -223,7 +223,7 @@ GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
223 if (NULL == eh->eip) 223 if (NULL == eh->eip)
224 { 224 {
225 GNUNET_DISK_pipe_close (eh->opipe); 225 GNUNET_DISK_pipe_close (eh->opipe);
226 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_EXECUTEABLE; 226 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED;
227 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, 227 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
228 eh); 228 eh);
229 return eh; 229 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
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 */
405struct GNUNET_NAT_Test * 411struct GNUNET_NAT_Test *
406GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 412GNUNET_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 }
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
45addr_callback (void *cls, int add_remove, 45addr_callback (void *cls, int add_remove,
46 const struct sockaddr *addr, 46 const struct sockaddr *addr,
47 socklen_t addrlen, 47 socklen_t addrlen,
48 enum GNUNET_NAT_FailureCode ret) 48 enum GNUNET_NAT_StatusCode ret)
49{ 49{
50 if (GNUNET_NAT_ERROR_SUCCESS == ret) 50 if (GNUNET_NAT_ERROR_SUCCESS == ret)
51 { 51 {
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;
41 41
42static void 42static void
43report_result (void *cls, 43report_result (void *cls,
44 enum GNUNET_NAT_FailureCode aret) 44 enum GNUNET_NAT_StatusCode aret)
45{ 45{
46 if (GNUNET_NAT_ERROR_TIMEOUT == aret) 46 if (GNUNET_NAT_ERROR_TIMEOUT == aret)
47 fprintf (stderr, 47 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)
545 * @param emsg error message, NULL on success 545 * @param emsg error message, NULL on success
546 */ 546 */
547static void 547static void
548result_callback (void *cls, enum GNUNET_NAT_FailureCode result) 548result_callback (void *cls, enum GNUNET_NAT_StatusCode result)
549{ 549{
550 struct TestContext *tc = cls; 550 struct TestContext *tc = cls;
551 display_test_result (tc, result); 551 display_test_result (tc, result);