gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10435 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r10435 - gnunet/src/transport
Date: Wed, 24 Feb 2010 11:09:42 +0100

Author: nevans
Date: 2010-02-24 11:09:42 +0100 (Wed, 24 Feb 2010)
New Revision: 10435

Modified:
   gnunet/src/transport/gnunet-nat-server.c
   gnunet/src/transport/plugin_transport_udp_nat.c
   gnunet/src/transport/test_transport_api_udp_nat_peer1.conf
   gnunet/src/transport/test_transport_api_udp_nat_peer2.conf
Log:
changes so that udp_nat sends running port along with icmp echo reply for 
optimistic nat traversal

Modified: gnunet/src/transport/gnunet-nat-server.c
===================================================================
--- gnunet/src/transport/gnunet-nat-server.c    2010-02-24 08:24:01 UTC (rev 
10434)
+++ gnunet/src/transport/gnunet-nat-server.c    2010-02-24 10:09:42 UTC (rev 
10435)
@@ -62,7 +62,7 @@
  */
 #define DUMMY_IP "1.2.3.4"
 
-#define VERBOSE 1
+#define VERBOSE 0
 
 /**
  * How often do we send our ICMP messages to receive replies?

Modified: gnunet/src/transport/plugin_transport_udp_nat.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp_nat.c     2010-02-24 08:24:01 UTC 
(rev 10434)
+++ gnunet/src/transport/plugin_transport_udp_nat.c     2010-02-24 10:09:42 UTC 
(rev 10435)
@@ -279,6 +279,11 @@
    */
   struct sockaddr_in sock_addr;
 
+  /**
+   * The port to send this probe to, 0 to choose randomly
+   */
+  int port;
+
 };
 
 
@@ -328,10 +333,6 @@
    */
   uint16_t starting_port;
 
-  /**
-   * Main listen port, only needed for testing...
-   */
-  uint16_t listen_port;
 
   /**
    * Starting port for sending out crazy messages
@@ -577,6 +578,7 @@
 {
   char inet4[INET_ADDRSTRLEN];
   char *address_as_string;
+  char *port_as_string;
   pid_t pid;
   const struct sockaddr *sa = (const struct sockaddr *)addr;
 
@@ -597,12 +599,15 @@
       return;
     }
 
+  GNUNET_asprintf(&port_as_string, "%d", plugin->starting_port);
 #if DEBUG_UDP_NAT
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp-nat",
-                  _("Running gnunet-nat-client with address %s\n"), 
address_as_string);
+                  _("Running gnunet-nat-client with arguments: %s %s %d\n"), 
plugin->external_address, address_as_string, plugin->starting_port);
 #endif
   /* Start the server process */
-  pid = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", 
"gnunet-nat-client", plugin->external_address, address_as_string, NULL);
+  pid = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", 
"gnunet-nat-client", plugin->external_address, address_as_string, 
port_as_string, NULL);
+  GNUNET_free(address_as_string);
+  GNUNET_free(port_as_string);
   GNUNET_OS_process_wait (pid);
 }
 
@@ -758,7 +763,7 @@
           v4->sin_port = htons (0); /* Indicates to receiver we are behind NAT 
*/
         }
       else
-        v4->sin_port = htons (plugin->listen_port);
+        v4->sin_port = htons (plugin->starting_port);
     }
   else
     {
@@ -767,7 +772,7 @@
       if (plugin->behind_nat == GNUNET_YES)
         v6->sin6_port = htons (0);
       else
-        v6->sin6_port = htons (plugin->listen_port);
+        v6->sin6_port = htons (plugin->starting_port);
     }
 
 #if !IPV6
@@ -833,7 +838,12 @@
   message->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE);
   /* Try the agreed upon port first, then go in order starting with our 
randomly chosen port */
   if (probe->index == 0)
-    probe->sock_addr.sin_port = htons(plugin->starting_port);
+    {
+      if (probe->port != 0)
+        probe->sock_addr.sin_port = htons(probe->port);
+      else
+        probe->sock_addr.sin_port = htons(plugin->starting_port);
+    }
   else
     probe->sock_addr.sin_port = htons 
(GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* 
Find a non-root port */
 #if DEBUG_UDP_NAT
@@ -933,7 +943,8 @@
   memset(&mybuf, 0, sizeof(mybuf));
   int i;
   struct UDP_NAT_Probes *temp_probe;
-
+  int port;
+  char *port_start;
   bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, &mybuf, 
sizeof(mybuf));
 
   if (bytes < 1)
@@ -945,15 +956,26 @@
       return;
     }
 
+  port = 0;
+  port_start = NULL;
   for (i = 0; i < sizeof(mybuf); i++)
     {
       if (mybuf[i] == '\n')
         mybuf[i] = '\0';
+
+      if ((mybuf[i] == ':') && (i + 1 < sizeof(mybuf)))
+        {
+          mybuf[i] = '\0';
+          port_start = &mybuf[i + 1];
+        }
     }
 
+  if (port_start != NULL)
+    port = atoi(port_start);
+
 #if DEBUG_UDP_NAT
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp-nat",
-                  _("nat-server-read read: %s\n"), &mybuf);
+                  _("nat-server-read read: %s port %d\n"), &mybuf, port);
 #endif
 
   /* Schedule sending of messages to peer on random ports */
@@ -966,6 +988,7 @@
       temp_probe->sock_addr.sin_family = AF_INET;
       GNUNET_assert(inet_pton(AF_INET, &mybuf[0], 
&temp_probe->sock_addr.sin_addr) == 1);
       temp_probe->index = 0;
+      temp_probe->port = port;
       temp_probe->next = plugin->probes;
       temp_probe->plugin = plugin;
       temp_probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500), 
&send_udp_probe_message, temp_probe);
@@ -1355,7 +1378,7 @@
               serverAddrv4.sin_family = AF_INET;
               serverAddrv4.sin_addr.s_addr = INADDR_ANY;
               if (i == 0)
-                serverAddrv4.sin_port = htons (plugin->listen_port);
+                serverAddrv4.sin_port = htons (plugin->starting_port);
               else
                 serverAddrv4.sin_port = htons 
(GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* 
Find a non-root port */
               addrlen = sizeof (serverAddrv4);
@@ -1602,7 +1625,6 @@
   char *internal_address;
   char *external_address;
   char *starting_port;
-  char *listen_port;
 
   service = GNUNET_SERVICE_start ("transport-udp-nat", env->sched, env->cfg);
   if (service == NULL)
@@ -1651,17 +1673,9 @@
   GNUNET_CONFIGURATION_get_value_string (env->cfg,
                                          "transport-udp-nat",
                                          "PORT",
-                                         &listen_port);
-
-  /* Yes we'll use PORT as the default configuration value, but
-   * for testing we need two different ports for the peers so
-   * STARTING_PORT will have to do!
-   */
-  GNUNET_CONFIGURATION_get_value_string (env->cfg,
-                                         "transport-udp-nat",
-                                         "STARTING_PORT",
                                          &starting_port);
 
+
   mtu = 1240;
   if (mtu < 1200)
     GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
@@ -1672,8 +1686,6 @@
   plugin = GNUNET_malloc (sizeof (struct Plugin));
   plugin->external_address = external_address;
   plugin->internal_address = internal_address;
-  if (listen_port != NULL)
-    plugin->listen_port = atoi(listen_port);
 
   if (starting_port != NULL)
     plugin->starting_port = atoi(starting_port);

Modified: gnunet/src/transport/test_transport_api_udp_nat_peer1.conf
===================================================================
--- gnunet/src/transport/test_transport_api_udp_nat_peer1.conf  2010-02-24 
08:24:01 UTC (rev 10434)
+++ gnunet/src/transport/test_transport_api_udp_nat_peer1.conf  2010-02-24 
10:09:42 UTC (rev 10435)
@@ -1,9 +1,8 @@
 [transport-udp-nat]
 PORT = 12368
 BEHIND_NAT = YES
+INTERNAL_ADDRESS = 127.0.0.1
 EXTERNAL_ADDRESS = 127.0.0.1
-STARTING_PORT = 40000
-RANDOM_START_PORT = 50000
 
 [fs]
 ALLOW_SHUTDOWN = YES
@@ -65,7 +64,7 @@
 
 [transport]
 PLUGINS = udp_nat
-#DEBUG = YES
+DEBUG = NO
 ALLOW_SHUTDOWN = YES
 ACCEPT_FROM6 = ::1;
 ACCEPT_FROM = 127.0.0.1;

Modified: gnunet/src/transport/test_transport_api_udp_nat_peer2.conf
===================================================================
--- gnunet/src/transport/test_transport_api_udp_nat_peer2.conf  2010-02-24 
08:24:01 UTC (rev 10434)
+++ gnunet/src/transport/test_transport_api_udp_nat_peer2.conf  2010-02-24 
10:09:42 UTC (rev 10435)
@@ -1,9 +1,8 @@
 [transport-udp-nat]
 PORT = 22368
-BEHIND_NAT = YES
+BEHIND_NAT = NO
 EXTERNAL_ADDRESS = 127.0.0.1
-STARTING_PORT = 50000
-RANDOM_START_PORT = 40000
+INTERNAL_ADDRESS = 127.0.0.1
 
 [fs]
 ALLOW_SHUTDOWN = YES
@@ -65,7 +64,7 @@
 
 [transport]
 PLUGINS = udp_nat
-#DEBUG = YES
+DEBUG = NO
 PREFIX = 
 ALLOW_SHUTDOWN = YES
 ACCEPT_FROM6 = ::1;





reply via email to

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