gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r33321 - in gnunet/src: include nat transport
Date: Mon, 19 May 2014 14:03:26 +0200

Author: cfuchs
Date: 2014-05-19 14:03:26 +0200 (Mon, 19 May 2014)
New Revision: 33321

Modified:
   gnunet/src/include/gnunet_nat_lib.h
   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/transport/gnunet-transport.c
Log:
- updated NAT callback function defintion to no longer carry around strings,
- NAT lib now uses error-code enums to signal success and errors
- reworked related code to return errorcodes
- added and updated a missing doxygen documention
- todo next: testcases

Modified: gnunet/src/include/gnunet_nat_lib.h
===================================================================
--- gnunet/src/include/gnunet_nat_lib.h 2014-05-19 10:26:08 UTC (rev 33320)
+++ gnunet/src/include/gnunet_nat_lib.h 2014-05-19 12:03:26 UTC (rev 33321)
@@ -71,6 +71,56 @@
 
 
 /**
+ * Error Types for the NAT subsystem (which can then later be 
converted/resolved to a string)
+ */
+enum GNUNET_NAT_FailureCode {
+  /**
+   * Just the default
+   */
+  GNUNET_NAT_ERROR_SUCCESS = 0,
+  
+  /**
+   * `upnpc` command not found
+   */
+  GNUNET_NAT_ERROR_UPNPC_NOT_FOUND,
+  
+  /**
+   * Failed to run `upnpc` command
+   */
+  GNUNET_NAT_ERROR_UPNPC_FAILED,
+  
+  /**
+   * `upnpc' command took too long, process killed
+   */
+  GNUNET_NAT_ERROR_UPNPC_TIMEOUT,
+  
+  /**
+   * `upnpc' command failed to establish port mapping
+   */
+  GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED,
+  
+  /**
+   * `external-ip' command not found
+   */
+  GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND,
+  
+  /**
+   * "no valid address was returned by `external-ip'"
+   */
+  GNUNET_NAT_ERROR_EXTERNAL_IP_NO_VALID_ADDRESS_FOUND,
+  
+  
+  
+  /**
+   * 
+   */
+  GNUNET_NAT_ERROR_,
+  
+  
+};
+
+
+/**
  * Attempt to enable port redirection and detect public IP address
  * contacting UPnP or NAT-PMP routers on the local network. Use addr
  * to specify to which of the local host's addresses should the
@@ -157,14 +207,10 @@
  * NAT configuration test.
  *
  * @param cls closure
- * @param success #GNUNET_OK on success, #GNUNET_NO on failure,
- *                #GNUNET_SYSERR if the test could not be
- *                properly started (internal failure)
- * @param emsg NULL on success, otherwise may include an error message
+ * @param result GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific 
error code
  */
 typedef void (*GNUNET_NAT_TestCallback) (void *cls,
-                                         int success,
-                                         const char *emsg);
+                                         enum GNUNET_NAT_FailureCode result);
 
 
 /**
@@ -202,11 +248,11 @@
  *
  * @param cls closure
  * @param addr the address, NULL on errors
- * @param emsg NULL on success, otherwise may include an error message
+ * @param result GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific 
error code
  */
 typedef void (*GNUNET_NAT_IPCallback) (void *cls,
                                        const struct in_addr *addr,
-                                       const char *emsg);
+                                       enum GNUNET_NAT_FailureCode result);
 
 
 
@@ -254,13 +300,14 @@
  *     the previous (now invalid) one
  * @param addr either the previous or the new public IP address
  * @param addrlen actual length of the @a addr
+ * @param result GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific 
error code
  */
 typedef void
 (*GNUNET_NAT_MiniAddressCallback) (void *cls,
                                    int add_remove,
                                    const struct sockaddr *addr,
                                    socklen_t addrlen,
-                                   const char *emsg);
+                                   enum GNUNET_NAT_FailureCode result);
 
 
 /**
@@ -307,12 +354,12 @@
  * @param cls closure
  * @param diff minimal suggested changes to the original configuration
  *             to make it work (as best as we can)
- * @param emsg NULL on success, otherwise may include an error message
+ * @param result GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific 
error code
  */
 typedef void
 (*GNUNET_NAT_AutoResultCallback)(void *cls,
                                  const struct GNUNET_CONFIGURATION_Handle 
*diff,
-                                 const char *emsg);
+                                 enum GNUNET_NAT_FailureCode result);
 
 
 /**

Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c        2014-05-19 10:26:08 UTC (rev 33320)
+++ gnunet/src/nat/nat.c        2014-05-19 12:03:26 UTC (rev 33321)
@@ -1011,20 +1011,31 @@
  *     the previous (now invalid) one
  * @param addr either the previous or the new public IP address
  * @param addrlen actual lenght of @a addr
- * @param emsg NULL on success, otherwise an error message
+ * @param ret GNUNET_NAT_ERROR_SUCCESS on success, otherwise an error code
  */
 static void
 upnp_add (void *cls,
           int add_remove,
           const struct sockaddr *addr,
           socklen_t addrlen,
-          const char *emsg)
+          enum GNUNET_NAT_FailureCode ret)
 {
   struct GNUNET_NAT_Handle *h = cls;
   struct LocalAddressList *pos;
   struct LocalAddressList *next;
 
 
+  if (GNUNET_NAT_ERROR_SUCCESS != ret)
+  {
+    /* Error while running upnp client */
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+          _("Error while running upnp client:\n"));
+
+    //FIXME: convert error code to string
+    
+    return;
+  }
+  
   if (GNUNET_YES == add_remove)
   {
     add_to_address_list (h, LAL_UPNP, addr, addrlen);
@@ -1053,17 +1064,6 @@
          GNUNET_a2s(addr, addrlen));
     GNUNET_break (0);
   }
-  else if (GNUNET_SYSERR == add_remove)
-  {
-    /* Error while running upnp client */
-    if (NULL != emsg)
-      LOG (GNUNET_ERROR_TYPE_ERROR,
-          _("Error while running upnp client: `%s'\n"), emsg);
-    else
-      LOG (GNUNET_ERROR_TYPE_ERROR,
-          _("Error while running upnp client \n"));
-    return;
-  }
   else
   {
 

Modified: gnunet/src/nat/nat_auto.c
===================================================================
--- gnunet/src/nat/nat_auto.c   2014-05-19 10:26:08 UTC (rev 33320)
+++ gnunet/src/nat/nat_auto.c   2014-05-19 12:03:26 UTC (rev 33321)
@@ -189,8 +189,7 @@
  */
 static void
 result_callback (void *cls,
-                 int success,
-                 const char *emsg)
+                 enum GNUNET_NAT_FailureCode ret)
 {
   struct GNUNET_NAT_AutoHandle *ah = cls;
 
@@ -199,11 +198,11 @@
   GNUNET_NAT_test_stop (ah->tst);
   ah->tst = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             success
+              ret
              ? _("NAT traversal with ICMP Server succeeded.\n")
              : _("NAT traversal with ICMP Server failed.\n"));
   GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER",
-                                        success ? "YES": "NO");
+                                        ret ? "NO" : "YES");
   next_phase (ah);
 }
 
@@ -258,7 +257,7 @@
 static void
 set_external_ipv4 (void *cls,
                    const struct in_addr *addr,
-                   const char *emsg)
+                   enum GNUNET_NAT_FailureCode ret)
 {
   struct GNUNET_NAT_AutoHandle *ah = cls;
   char buf[INET_ADDRSTRLEN];
@@ -525,7 +524,7 @@
                                          ah->cfg);
     ah->fin_cb (ah->fin_cb_cls,
                diff,
-                NULL);
+                GNUNET_NAT_ERROR_SUCCESS);
     GNUNET_CONFIGURATION_destroy (diff);
     GNUNET_NAT_autoconfig_cancel (ah);
     return;

Modified: gnunet/src/nat/nat_mini.c
===================================================================
--- gnunet/src/nat/nat_mini.c   2014-05-19 10:26:08 UTC (rev 33320)
+++ gnunet/src/nat/nat_mini.c   2014-05-19 12:03:26 UTC (rev 33321)
@@ -150,9 +150,7 @@
           (GNUNET_OK == iret)
           ? &addr :
           NULL,
-          (GNUNET_OK == iret)
-          ? NULL
-          : _("no valid address was returned by `external-ip'"));
+          GNUNET_NAT_ERROR_EXTERNAL_IP_NO_VALID_ADDRESS_FOUND);
   GNUNET_NAT_mini_get_external_ipv4_cancel (eh);
 }
 
@@ -172,7 +170,7 @@
   eh->task = GNUNET_SCHEDULER_NO_TASK;
   eh->cb (eh->cb_cls,
           NULL,
-          _("`external-ip' command not found"));
+          GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND);
   GNUNET_free (eh);
 }
 
@@ -363,7 +361,7 @@
     mini->ac (mini->ac_cls,
               GNUNET_SYSERR,
               NULL, 0,
-              _("Failed to run `upnpc` command"));
+              GNUNET_NAT_ERROR_UPNPC_FAILED);
     return;
   }
 }
@@ -398,7 +396,7 @@
                   GNUNET_NO,
                   (const struct sockaddr *) &mini->current_addr,
                   sizeof (mini->current_addr),
-                  NULL);
+                  GNUNET_NAT_ERROR_SUCCESS);
         mini->did_map = GNUNET_NO;
       }
       run_upnpc_r (mini);
@@ -423,12 +421,12 @@
     mini->ac (mini->ac_cls, GNUNET_NO,
               (const struct sockaddr *) &mini->current_addr,
               sizeof (mini->current_addr),
-              NULL);
+              GNUNET_NAT_ERROR_SUCCESS);
     mini->current_addr.sin_addr = exip;
     mini->ac (mini->ac_cls, GNUNET_YES,
               (const struct sockaddr *) &mini->current_addr,
               sizeof (mini->current_addr),
-              NULL);
+              GNUNET_NAT_ERROR_SUCCESS);
     return;
   }
   /*
@@ -460,12 +458,12 @@
   mini->ac (mini->ac_cls, GNUNET_NO,
             (const struct sockaddr *) &mini->current_addr,
             sizeof (mini->current_addr),
-            NULL);
+            GNUNET_NAT_ERROR_SUCCESS);
   mini->current_addr.sin_port = htons ((uint16_t) nport);
   mini->ac (mini->ac_cls, GNUNET_YES,
             (const struct sockaddr *) &mini->current_addr,
             sizeof (mini->current_addr),
-            NULL);
+            GNUNET_NAT_ERROR_SUCCESS);
 }
 
 
@@ -509,7 +507,7 @@
     mini->ac (mini->ac_cls,
               GNUNET_SYSERR,
               NULL, 0,
-              _("`upnpc' command took too long, process killed"));
+              GNUNET_NAT_ERROR_UPNPC_TIMEOUT);
 }
 
 
@@ -537,7 +535,7 @@
       mini->ac (mini->ac_cls,
                 GNUNET_SYSERR,
                 NULL, 0,
-                _("`upnpc' command failed to establish port mapping"));
+                GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
     if (GNUNET_SCHEDULER_NO_TASK == mini->refresh_task)
       mini->refresh_task =
         GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
@@ -572,7 +570,7 @@
   mini->ac (mini->ac_cls, GNUNET_YES,
             (const struct sockaddr *) &mini->current_addr,
             sizeof (mini->current_addr),
-            NULL);
+            GNUNET_NAT_ERROR_SUCCESS);
 }
 
 
@@ -605,7 +603,7 @@
     ac (ac_cls,
         GNUNET_SYSERR,
         NULL, 0,
-        _("`upnpc` command not found"));
+        GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
     return NULL;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -682,7 +680,7 @@
   mini->ac (mini->ac_cls, GNUNET_NO,
             (const struct sockaddr *) &mini->current_addr,
             sizeof (mini->current_addr),
-            NULL);
+            GNUNET_NAT_ERROR_SUCCESS);
   /* Note: oddly enough, deletion uses the external port whereas
    * addition uses the internal port; this rarely matters since they
    * often are the same, but it might... */

Modified: gnunet/src/nat/nat_test.c
===================================================================
--- gnunet/src/nat/nat_test.c   2014-05-19 10:26:08 UTC (rev 33320)
+++ gnunet/src/nat/nat_test.c   2014-05-19 12:03:26 UTC (rev 33321)
@@ -187,7 +187,7 @@
     return;                     /* wrong port */
   }
   /* report success */
-  h->report (h->report_cls, GNUNET_OK, NULL);
+  h->report (h->report_cls, GNUNET_NAT_ERROR_SUCCESS);
 }
 
 
@@ -215,7 +215,7 @@
        GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data))))
   {
     if (data == tst->data)
-      tst->report (tst->report_cls, GNUNET_OK, NULL);
+      tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
     else
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Received data mismatches expected value\n");
@@ -250,7 +250,7 @@
        GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data))))
   {
     if (data == tst->data)
-      tst->report (tst->report_cls, GNUNET_OK, NULL);
+      tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
     else
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Received data does not match expected value\n");

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2014-05-19 10:26:08 UTC (rev 
33320)
+++ gnunet/src/transport/gnunet-transport.c     2014-05-19 12:03:26 UTC (rev 
33321)
@@ -545,10 +545,10 @@
  * @param emsg error message, NULL on success
  */
 static void
-result_callback (void *cls, int success, const char *emsg)
+result_callback (void *cls, enum GNUNET_NAT_FailureCode result)
 {
   struct TestContext *tc = cls;
-  display_test_result (tc, success);
+  display_test_result (tc, result);
 }
 
 /**




reply via email to

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