gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r33679 - in gnunet/src: nat transport


From: gnunet
Subject: [GNUnet-SVN] r33679 - in gnunet/src: nat transport
Date: Tue, 17 Jun 2014 12:35:26 +0200

Author: cfuchs
Date: 2014-06-17 12:35:26 +0200 (Tue, 17 Jun 2014)
New Revision: 33679

Modified:
   gnunet/src/nat/nat.c
   gnunet/src/nat/nat_auto.c
   gnunet/src/nat/nat_mini.c
   gnunet/src/nat/nat_test.c
   gnunet/src/nat/test_nat_mini.c
   gnunet/src/nat/test_nat_test.c
   gnunet/src/transport/gnunet-transport.c
Log:
- 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...)

Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c        2014-06-17 10:28:40 UTC (rev 33678)
+++ gnunet/src/nat/nat.c        2014-06-17 10:35:26 UTC (rev 33679)
@@ -1018,7 +1018,7 @@
           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 @@
 }
 
 
+/**
+ * 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 */

Modified: gnunet/src/nat/nat_auto.c
===================================================================
--- gnunet/src/nat/nat_auto.c   2014-06-17 10:28:40 UTC (rev 33678)
+++ gnunet/src/nat/nat_auto.c   2014-06-17 10:35:26 UTC (rev 33679)
@@ -144,7 +144,7 @@
   /**
    * Error code for better debugging and user feedback
    */
-  enum GNUNET_NAT_FailureCode ret;
+  enum GNUNET_NAT_StatusCode ret;
 };
 
 
@@ -167,10 +167,11 @@
  */
 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 @@
 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];

Modified: gnunet/src/nat/nat_mini.c
===================================================================
--- gnunet/src/nat/nat_mini.c   2014-06-17 10:28:40 UTC (rev 33678)
+++ gnunet/src/nat/nat_mini.c   2014-06-17 10:35:26 UTC (rev 33679)
@@ -101,7 +101,7 @@
   /**
    * Error code for better debugging and user feedback
    */
-  enum GNUNET_NAT_FailureCode ret;
+  enum GNUNET_NAT_StatusCode ret;
 };
 
 
@@ -223,7 +223,7 @@
   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;

Modified: gnunet/src/nat/nat_test.c
===================================================================
--- gnunet/src/nat/nat_test.c   2014-06-17 10:28:40 UTC (rev 33678)
+++ gnunet/src/nat/nat_test.c   2014-06-17 10:35:26 UTC (rev 33679)
@@ -163,6 +163,10 @@
    */
   uint16_t adv_port;
 
+  /**
+   * Status code to be reported to the timeout/status call
+   */
+  enum GNUNET_NAT_StatusCode status;
 };
 
 
@@ -371,6 +375,8 @@
  * 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 @@
   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 @@
  * @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 @@
   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 @@
                   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_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;
     }
   }

Modified: gnunet/src/nat/test_nat_mini.c
===================================================================
--- gnunet/src/nat/test_nat_mini.c      2014-06-17 10:28:40 UTC (rev 33678)
+++ gnunet/src/nat/test_nat_mini.c      2014-06-17 10:35:26 UTC (rev 33679)
@@ -45,7 +45,7 @@
 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)
   {

Modified: gnunet/src/nat/test_nat_test.c
===================================================================
--- gnunet/src/nat/test_nat_test.c      2014-06-17 10:28:40 UTC (rev 33678)
+++ gnunet/src/nat/test_nat_test.c      2014-06-17 10:35:26 UTC (rev 33679)
@@ -41,7 +41,7 @@
 
 static void
 report_result (void *cls,
-                enum GNUNET_NAT_FailureCode aret)
+                enum GNUNET_NAT_StatusCode aret)
 {
   if (GNUNET_NAT_ERROR_TIMEOUT == aret)
     fprintf (stderr,

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2014-06-17 10:28:40 UTC (rev 
33678)
+++ gnunet/src/transport/gnunet-transport.c     2014-06-17 10:35:26 UTC (rev 
33679)
@@ -545,7 +545,7 @@
  * @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);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]