gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r33606 - in gnunet/src: include nat transport
Date: Sun, 8 Jun 2014 17:26:56 +0200

Author: cfuchs
Date: 2014-06-08 17:26:55 +0200 (Sun, 08 Jun 2014)
New Revision: 33606

Modified:
   gnunet/src/include/gnunet_nat_lib.h
   gnunet/src/nat/nat_auto.c
   gnunet/src/nat/nat_test.c
   gnunet/src/nat/test_nat_test.c
   gnunet/src/transport/gnunet-transport.c
Log:
- moved timeout handling responsibility from for nat tests from caller to the 
library
- updated NAT API accordingly
- removed obsolete timeout handling code from gnunet-transport
- updated result callback for nat-test gnunet-transport to not always just 
report success, but we now actually report the proper result code we got from 
the NAT API
- updated nat tests

Modified: gnunet/src/include/gnunet_nat_lib.h
===================================================================
--- gnunet/src/include/gnunet_nat_lib.h 2014-06-08 13:54:33 UTC (rev 33605)
+++ gnunet/src/include/gnunet_nat_lib.h 2014-06-08 15:26:55 UTC (rev 33606)
@@ -88,6 +88,11 @@
   /**
    * `external-ip' command not found
    */
+  GNUNET_NAT_ERROR_TIMEOUT,
+  
+  /**
+   * `external-ip' command not found
+   */
   GNUNET_NAT_ERROR_NOT_ONLINE,
   
   /**
@@ -264,6 +269,7 @@
  * @param is_tcp #GNUNET_YES to test TCP, #GNUNET_NO to test UDP
  * @param bnd_port port to bind to, 0 for connection reversal
  * @param adv_port externally advertised port to use
+ * @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
@@ -273,6 +279,7 @@
                        int is_tcp,
                        uint16_t bnd_port,
                        uint16_t adv_port,
+                       struct GNUNET_TIME_Relative timeout,
                        GNUNET_NAT_TestCallback report,
                        void *report_cls);
 

Modified: gnunet/src/nat/nat_auto.c
===================================================================
--- gnunet/src/nat/nat_auto.c   2014-06-08 13:54:33 UTC (rev 33605)
+++ gnunet/src/nat/nat_auto.c   2014-06-08 15:26:55 UTC (rev 33606)
@@ -158,36 +158,9 @@
 
 
 /**
- * Function called if NAT failed to confirm success.
- * Clean up and update GUI (with failure).
+ * Function called by NAT to report the outcome of the nat-test.
+ * Clean up and update GUI.
  *
- * @param cls closure with setup context
- * @param tc scheduler callback
- */
-static void
-fail_timeout (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct GNUNET_NAT_AutoHandle *ah = cls;
-
-  ah->ret = GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT; 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             _("NAT traversal with ICMP Server timed out.\n"));
-  GNUNET_assert (NULL != ah->tst);
-  ah->task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (ah->tst);
-  ah->tst = NULL;
-  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat",
-                                        "ENABLE_ICMP_SERVER",
-                                        "NO");
-  next_phase (ah);
-}
-
-
-/**
- * Function called by NAT on success.
- * Clean up and update GUI (with success).
- *
  * @param cls the auto handle
  * @param success currently always #GNUNET_OK
  * @param emsg NULL on success, otherwise an error message
@@ -197,17 +170,15 @@
                  enum GNUNET_NAT_FailureCode ret)
 {
   struct GNUNET_NAT_AutoHandle *ah = cls;
-
-  GNUNET_SCHEDULER_cancel (ah->task);
-  ah->task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_NAT_test_stop (ah->tst);
   ah->tst = NULL;
+  ah->ret = ret;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              ret
+              GNUNET_NAT_ERROR_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",
-                                        ret ? "NO" : "YES");
+                                        GNUNET_NAT_ERROR_SUCCESS == ret ? "NO" 
: "YES");
   next_phase (ah);
 }
 
@@ -228,15 +199,8 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              _("Testing connection reversal with ICMP server.\n"));
   GNUNET_RESOLVER_connect (ah->cfg);
-  ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0,
+  ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0, TIMEOUT,
                                   &result_callback, ah);
-  if (NULL == ah->tst)
-  {
-    ah->ret = GNUNET_NAT_ERROR_NAT_TEST_START_FAILED;
-    next_phase (ah);
-    return;
-  }
-  ah->task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, ah);
 }
 
 
@@ -506,15 +470,8 @@
 static void
 test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
 {
-  int ext_ip;
-  int nated;
-  int binary;
   char *tmp;
   char *helper;
-  
-  ext_ip = GNUNET_NO;
-  nated = GNUNET_NO;
-  binary = GNUNET_NO;
 
   tmp = NULL;
   helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client");
@@ -522,7 +479,6 @@
         GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", 
"INTERNAL_ADDRESS",
                                                &tmp)) && (0 < strlen (tmp)))
   {
-    ext_ip = GNUNET_OK;
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_client not possible, as 
we have no internal IPv4 address\n"));
   }
   else
@@ -530,7 +486,6 @@
   
   if (GNUNET_YES !=
       GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){
-        nated = GNUNET_YES;
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as 
we are not behind NAT\n"));
   }
   else
@@ -539,7 +494,6 @@
   if (GNUNET_YES ==
       GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 
127.0.0.2 42")){
           // none of these parameters are actually used in privilege testing 
mode
-    binary = GNUNET_OK;
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server 
found\n"));
   }
 err:

Modified: gnunet/src/nat/nat_test.c
===================================================================
--- gnunet/src/nat/nat_test.c   2014-06-08 13:54:33 UTC (rev 33605)
+++ gnunet/src/nat/nat_test.c   2014-06-08 15:26:55 UTC (rev 33606)
@@ -142,6 +142,11 @@
    * Identity of task for the listen socket (if any)
    */
   GNUNET_SCHEDULER_TaskIdentifier ltask;
+  
+  /**
+   * Task identifier for the timeout (if any)
+   */
+  GNUNET_SCHEDULER_TaskIdentifier ttask;
 
   /**
    * GNUNET_YES if we're testing TCP
@@ -363,13 +368,36 @@
 
 
 /**
+ * Timeout task for a nat test. 
+ * Calls the report-callback with a timeout return value
+ * 
+ * @param cls handle to the timed out NAT test
+ * @param tc not used
+ */
+static void
+do_timeout (void *cls,
+                 const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+  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);
+  
+  GNUNET_NAT_test_stop(nh);
+}
+
+
+/**
  * Start testing if NAT traversal works using the
  * given configuration (IPv4-only).
+ * 
+ * ALL failures are reported directly to the report callback
  *
  * @param cfg configuration for the NAT traversal
  * @param is_tcp #GNUNET_YES to test TCP, #GNUNET_NO to test UDP
  * @param bnd_port port to bind to, 0 for connection reversal
  * @param adv_port externally advertised port to use
+ * @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
@@ -379,6 +407,7 @@
                        int is_tcp,
                        uint16_t bnd_port,
                        uint16_t adv_port,
+                       struct GNUNET_TIME_Relative timeout,
                        GNUNET_NAT_TestCallback report,
                        void *report_cls)
 {
@@ -401,6 +430,7 @@
   nh->adv_port = adv_port;
   nh->report = report;
   nh->report_cls = report_cls;
+  nh->ttask = GNUNET_SCHEDULER_NO_TASK;
   if (0 == bnd_port)
   {
     nh->nat =
@@ -459,6 +489,7 @@
       return NULL;
     }
   }
+  nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, nh);
   return nh;
 }
 
@@ -489,6 +520,8 @@
     GNUNET_NETWORK_socket_close (pos->sock);
     GNUNET_free (pos);
   }
+  if (GNUNET_SCHEDULER_NO_TASK != tst->ttask)
+    GNUNET_SCHEDULER_cancel (tst->ttask);
   if (GNUNET_SCHEDULER_NO_TASK != tst->ltask)
     GNUNET_SCHEDULER_cancel (tst->ltask);
   if (NULL != tst->lsock)

Modified: gnunet/src/nat/test_nat_test.c
===================================================================
--- gnunet/src/nat/test_nat_test.c      2014-06-08 13:54:33 UTC (rev 33605)
+++ gnunet/src/nat/test_nat_test.c      2014-06-08 15:26:55 UTC (rev 33606)
@@ -39,23 +39,12 @@
 
 static struct GNUNET_NAT_Test *tst;
 
-static GNUNET_SCHEDULER_TaskIdentifier end;
-
 static void
-end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_NAT_test_stop (tst);
-}
-
-
-static void
 report_success (void *cls,
                 enum GNUNET_NAT_FailureCode aret)
 {
   GNUNET_assert (GNUNET_NAT_ERROR_SUCCESS == aret);
   ret = 0;
-  GNUNET_SCHEDULER_cancel (end);
-  end = GNUNET_SCHEDULER_add_now (&end_test, NULL);
 }
 
 
@@ -67,12 +56,9 @@
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   tst =
-      GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285,
+      GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, TIMEOUT
                              &report_success,
                              NULL);
-  if (NULL == tst)
-    return;
-  end = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
 }
 
 

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2014-06-08 13:54:33 UTC (rev 
33605)
+++ gnunet/src/transport/gnunet-transport.c     2014-06-08 15:26:55 UTC (rev 
33606)
@@ -537,8 +537,8 @@
 }
 
 /**
- * Function called by NAT on success.
- * Clean up and update GUI (with success).
+ * Function called by NAT to report the outcome of the nat-test.
+ * Clean up and update GUI.
  *
  * @param cls test context
  * @param success currently always #GNUNET_OK
@@ -551,24 +551,7 @@
   display_test_result (tc, result);
 }
 
-/**
- * Function called if NAT failed to confirm success.
- * Clean up and update GUI (with failure).
- *
- * @param cls test context
- * @param tc scheduler callback
- */
 static void
-fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct TestContext *tstc = cls;
-
-  tstc->tsk = GNUNET_SCHEDULER_NO_TASK;
-  display_test_result (tstc, NAT_TEST_TIMEOUT);
-}
-
-
-static void
 resolve_validation_address (const struct GNUNET_PeerIdentity *id,
                             const struct GNUNET_HELLO_Address *address,
                             int numeric,
@@ -751,13 +734,8 @@
       (0 == strcasecmp (head->name, "udp")) ? GNUNET_NO : GNUNET_YES,
       (uint16_t) head->bnd_port,
       (uint16_t) head->adv_port,
+      TIMEOUT,
       &result_callback, head);
-  if (NULL == head->tst)
-  {
-    display_test_result (head, NAT_TEST_FAILED_TO_START);
-    return;
-  }
-  head->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, head);
 }
 
 




reply via email to

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