gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36455 - gnunet/src/nat


From: gnunet
Subject: [GNUnet-SVN] r36455 - gnunet/src/nat
Date: Tue, 6 Oct 2015 21:09:31 +0200

Author: bartpolot
Date: 2015-10-06 21:09:30 +0200 (Tue, 06 Oct 2015)
New Revision: 36455

Modified:
   gnunet/src/nat/nat_auto.c
   gnunet/src/nat/nat_stun.c
   gnunet/src/nat/test_stun.c
Log:
- fix multiple gnunet-nat crashes

Modified: gnunet/src/nat/nat_auto.c
===================================================================
--- gnunet/src/nat/nat_auto.c   2015-10-06 19:09:29 UTC (rev 36454)
+++ gnunet/src/nat/nat_auto.c   2015-10-06 19:09:30 UTC (rev 36455)
@@ -236,16 +236,21 @@
 static void
 stop_stun ()
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping STUN and quitting...\n");
 
-  //Clean task
+  /* Clean task */
   if(NULL != ltask4)
+  {
     GNUNET_SCHEDULER_cancel (ltask4);
+    ltask4 = NULL;
+  }
 
-  //Clean socket
+  /* Clean socket */
   if(NULL != lsock4)
+  {
     GNUNET_NETWORK_socket_close (lsock4);
-
+    lsock4 = NULL;
+  }
 }
 
 /**
@@ -271,29 +276,23 @@
   {
     rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof (reply_buf));
 
-
     //Lets handle the packet
     memset(&answer, 0, sizeof(struct sockaddr_in));
-
-
-
-
-
     if(ah->phase == AUTO_NAT_PUNCHED)
     {
       //Destroy the connection
       GNUNET_NETWORK_socket_close (lsock4);
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "The external server was able to 
connect back");
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "The external server was able to connect back");
       ah->connected_back = GNUNET_YES;
       next_phase (ah);
     }
     else
     {
-      if(GNUNET_OK == GNUNET_NAT_stun_handle_packet(reply_buf,rlen, &answer))
+      if (GNUNET_OK == GNUNET_NAT_stun_handle_packet (reply_buf, rlen, 
&answer))
       {
         //Process the answer
-        process_stun_reply(&answer, ah);
-
+        process_stun_reply (&answer, ah);
       }
       else
       {
@@ -300,18 +299,17 @@
         next_phase (ah);
       }
     }
-
-
   }
   else
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "TIMEOUT while aiting for an answer");
-    if(ah->phase == AUTO_NAT_PUNCHED)
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "TIMEOUT while waiting for an answer\n");
+    if (ah->phase == AUTO_NAT_PUNCHED)
     {
       stop_stun();
     }
 
-    next_phase(ah);
+    next_phase (ah);
   }
 
 
@@ -357,14 +355,15 @@
 
 
 
-static void request_callback(void *cls,
-                             enum GNUNET_NAT_StatusCode result)
+static void request_callback (void *cls,
+                              enum GNUNET_NAT_StatusCode result)
 {
-  struct GNUNET_NAT_AutoHandle *ah = cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n");
-  stop_stun();
+  // struct GNUNET_NAT_AutoHandle *ah = cls;
 
-  next_phase(ah);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Request callback: stop and quit\n");
+  stop_stun ();
+
+  // next_phase (ah); FIXME this always will be NULL, as called in test_stun()
 };
 
 
@@ -498,7 +497,7 @@
 test_stun (struct GNUNET_NAT_AutoHandle *ah)
 {
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,"Running STUN test");
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running STUN test\n");
 
   /* Get port from the configuration */
   if (GNUNET_OK !=
@@ -530,14 +529,15 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "STUN service listens on port %u\n",
               port);
-  if( GNUNET_NO == GNUNET_NAT_stun_make_request(stun_server, stun_port, 
lsock4, &request_callback, NULL))
+  if (GNUNET_NO == GNUNET_NAT_stun_make_request (stun_server, stun_port,
+                                                 lsock4, &request_callback,
+                                                 NULL))
   {
     /*An error happened*/
-    stop_stun();
-    next_phase(ah);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n");
+    stop_stun ();
+    next_phase (ah);
   }
-
-
 }
 
 
@@ -648,7 +648,7 @@
   struct GNUNET_NAT_TestMessage msg;
 
 
-  if(ah->stun_ip)
+  if (ah->stun_ip)
   {
     LOG (GNUNET_ERROR_TYPE_INFO,
          "Asking gnunet-nat-server to connect to `%s'\n",
@@ -675,8 +675,12 @@
                                                            NAT_SERVER_TIMEOUT,
                                                            GNUNET_YES, NULL,
                                                            NULL));
-    ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
-                                            lsock4, &do_udp_read, ah);
+    if (NULL != ltask4)
+    {
+      GNUNET_SCHEDULER_cancel (ltask4);
+      ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
+                                              lsock4, &do_udp_read, ah);
+    }
 
   }
   else
@@ -847,7 +851,7 @@
     test_local_ip (ah);
     break;
   case AUTO_NAT_PUNCHED:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run GNUNET_ERROR_TYPE_DEBUG\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Will run AUTO_NAT_PUNCHED\n");
     test_nat_punched (ah);
     break;
   case AUTO_UPNPC:

Modified: gnunet/src/nat/nat_stun.c
===================================================================
--- gnunet/src/nat/nat_stun.c   2015-10-06 19:09:29 UTC (rev 36454)
+++ gnunet/src/nat/nat_stun.c   2015-10-06 19:09:30 UTC (rev 36455)
@@ -19,7 +19,7 @@
 */
 
 /**
- * 
+ *
  * This code provides some support for doing STUN transactions.
  * We send simplest possible packet ia REQUEST with BIND to a STUN server.
  *
@@ -29,7 +29,7 @@
  * structured as a type, length and a value (whose format depends
  * on the type, but often contains addresses).
  * Of course all fields are in network format.
- * 
+ *
  * This code was based on ministun.c.
  *
  *
@@ -567,7 +567,7 @@
                                              TIMEOUT,
                                              &stun_dns_callback, rh);
 
-    if(rh->dns_active == NULL)
+    if (rh->dns_active == NULL)
     {
         GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "Failed DNS");
         GNUNET_free(rh);

Modified: gnunet/src/nat/test_stun.c
===================================================================
--- gnunet/src/nat/test_stun.c  2015-10-06 19:09:29 UTC (rev 36454)
+++ gnunet/src/nat/test_stun.c  2015-10-06 19:09:30 UTC (rev 36455)
@@ -105,7 +105,7 @@
  * Activity on our incoming socket.  Read data from the
  * incoming connection.
  *
- * @param cls 
+ * @param cls
  * @param tc scheduler context
  */
 static void
@@ -123,7 +123,7 @@
        {
                rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof 
(reply_buf));
 
-               
+
                //Lets handle the packet
                memset(&answer, 0, sizeof(struct sockaddr_in));
 
@@ -154,8 +154,6 @@
   }
 
   ltask4 = NULL;
-
-
 }
 
 
@@ -176,7 +174,7 @@
     sa4.sin_port = htons (port);
 #if HAVE_SOCKADDR_IN_SIN_LEN
     sa4.sin_len = sizeof (sa4);
-#endif 
+#endif
     ls = GNUNET_NETWORK_socket_create (AF_INET,
                                        SOCK_DGRAM,
                                        0);
@@ -243,7 +241,8 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Service listens on port %u\n",
               port);
-  GNUNET_NAT_stun_make_request(stun_server, stun_port, lsock4, 
&request_callback, NULL);
+  GNUNET_NAT_stun_make_request (stun_server, stun_port, lsock4,
+                                &request_callback, NULL);
 
   GNUNET_SCHEDULER_add_delayed (TIMEOUT, &stop, NULL);
 




reply via email to

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