gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36441 - in gnunet/src: include nat peerinfo-tool transport


From: gnunet
Subject: [GNUnet-SVN] r36441 - in gnunet/src: include nat peerinfo-tool transport
Date: Mon, 5 Oct 2015 17:28:22 +0200

Author: grothoff
Date: 2015-10-05 17:28:21 +0200 (Mon, 05 Oct 2015)
New Revision: 36441

Modified:
   gnunet/src/include/gnunet_nat_lib.h
   gnunet/src/include/gnunet_peerstore_service.h
   gnunet/src/nat/nat.c
   gnunet/src/nat/nat.h
   gnunet/src/peerinfo-tool/gnunet-peerinfo.c
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/gnunet-service-transport_hello.c
   gnunet/src/transport/plugin_transport_udp.c
Log:
fix #3986

Modified: gnunet/src/include/gnunet_nat_lib.h
===================================================================
--- gnunet/src/include/gnunet_nat_lib.h 2015-10-05 10:06:13 UTC (rev 36440)
+++ gnunet/src/include/gnunet_nat_lib.h 2015-10-05 15:28:21 UTC (rev 36441)
@@ -80,14 +80,17 @@
    * We have a direct connection
    */
   GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK,
+
   /**
    * We are under a NAT but cannot traverse it
    */
   GNUNET_NAT_TYPE_UNREACHABLE_NAT,
+
   /**
    * We can traverse using STUN
    */
   GNUNET_NAT_TYPE_STUN_PUNCHED_NAT,
+
   /**
    * WE can traverse using UPNP
    */
@@ -195,8 +198,6 @@
    */
   GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND,
 
-
-
   /**
    *
    */

Modified: gnunet/src/include/gnunet_peerstore_service.h
===================================================================
--- gnunet/src/include/gnunet_peerstore_service.h       2015-10-05 10:06:13 UTC 
(rev 36440)
+++ gnunet/src/include/gnunet_peerstore_service.h       2015-10-05 15:28:21 UTC 
(rev 36441)
@@ -116,8 +116,10 @@
  * @param success #GNUNET_OK or #GNUNET_SYSERR
  */
 typedef void
-(*GNUNET_PEERSTORE_Continuation)(void *cls, int success);
+(*GNUNET_PEERSTORE_Continuation)(void *cls,
+                                 int success);
 
+
 /**
  * Function called by PEERSTORE for each matching record.
  *

Modified: gnunet/src/nat/nat.c
===================================================================
--- gnunet/src/nat/nat.c        2015-10-05 10:06:13 UTC (rev 36440)
+++ gnunet/src/nat/nat.c        2015-10-05 15:28:21 UTC (rev 36441)
@@ -454,8 +454,6 @@
 start_gnunet_nat_server (struct GNUNET_NAT_Handle *h);
 
 
-
-
 /**
  * Call task to process STUN
  *
@@ -462,10 +460,9 @@
  * @param cls handle to NAT
  * @param tc TaskContext
  */
-
 static void
 process_stun (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc);
+              const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 
 /**
@@ -488,10 +485,14 @@
     next = pos->next;
     if (pos->source != src)
       continue;
-    GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos);
+    GNUNET_CONTAINER_DLL_remove (h->lal_head,
+                                 h->lal_tail,
+                                 pos);
     if (NULL != h->address_callback)
-      h->address_callback (h->callback_cls, GNUNET_NO,
-                           (const struct sockaddr *) &pos[1], pos->addrlen);
+      h->address_callback (h->callback_cls,
+                           GNUNET_NO,
+                           (const struct sockaddr *) &pos[1],
+                           pos->addrlen);
     GNUNET_free (pos);
   }
 }
@@ -509,7 +510,8 @@
 static void
 add_to_address_list_as_is (struct GNUNET_NAT_Handle *h,
                            enum LocalAddressSource src,
-                           const struct sockaddr *arg, socklen_t arg_size)
+                           const struct sockaddr *arg,
+                           socklen_t arg_size)
 {
   struct LocalAddressList *lal;
 
@@ -517,13 +519,18 @@
   memcpy (&lal[1], arg, arg_size);
   lal->addrlen = arg_size;
   lal->source = src;
-  GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal);
+  GNUNET_CONTAINER_DLL_insert (h->lal_head,
+                               h->lal_tail,
+                               lal);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Adding address `%s' from source %d\n",
        GNUNET_a2s (arg, arg_size),
        src);
   if (NULL != h->address_callback)
-    h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size);
+    h->address_callback (h->callback_cls,
+                         GNUNET_YES,
+                         arg,
+                         arg_size);
 }
 
 
@@ -1110,15 +1117,13 @@
  * @param result , the status
  */
 static void
-stun_request_callback(void *cls,
-                                  enum GNUNET_NAT_StatusCode result)
+stun_request_callback (void *cls,
+                       enum GNUNET_NAT_StatusCode result)
 {
-
   struct GNUNET_NAT_Handle *h = cls;
 
-  if(NULL == cls)
+  if (NULL == h)
     return;
-
   h->waiting_stun = GNUNET_NO;
 
   if(result != GNUNET_OK)
@@ -1126,58 +1131,64 @@
     LOG (GNUNET_ERROR_TYPE_WARNING,
        "Error processing a STUN request");
   }
+}
 
-};
 
 /**
- * CHECK if is a valid STUN packet sending to GNUNET_NAT_stun_handle_packet.
+ * CHECK if is a valid STUN packet sending to GNUNET_NAT_stun_handle_packet().
  * It also check if it can handle the packet based on the NAT handler.
  * You don't need to call anything else to check if the packet is valid,
  *
  * @param cls the NAT handle
- * @param data, packet
- * @param len, packet length
- *
+ * @param data packet
+ * @param len packet length
  * @return #GNUNET_NO if it can't decode, #GNUNET_YES if is a packet
  */
 int
-GNUNET_NAT_is_valid_stun_packet(void *cls, const void *data, size_t len)
+GNUNET_NAT_is_valid_stun_packet (void *cls,
+                                 const void *data,
+                                 size_t len)
 {
   struct GNUNET_NAT_Handle *h = cls;
   struct sockaddr_in answer;
 
-  /* We are not expecting a STUN message*/
-  if(!h->waiting_stun)
+  /* We are not expecting a STUN message */
+  if (! h->waiting_stun)
     return GNUNET_NO;
 
-  /*We dont have STUN installed*/
-  if(!h->use_stun)
+  /* We dont have STUN installed */
+  if (! h->use_stun)
     return GNUNET_NO;
 
   /* Empty the answer structure */
-  memset(&answer, 0, sizeof(struct sockaddr_in));
+  memset (&answer,
+          0,
+          sizeof(struct sockaddr_in));
 
   /*Lets handle the packet*/
-  int valid = GNUNET_NAT_stun_handle_packet(data,len, &answer);
-  if(valid)
-  {
-    LOG (GNUNET_ERROR_TYPE_INFO,
-         "Stun server returned IP %s , with port %d \n", 
inet_ntoa(answer.sin_addr), ntohs(answer.sin_port));
-    /* ADD IP AS VALID*/
-    add_to_address_list (h, LAL_EXTERNAL_IP, (const struct sockaddr *) &answer,
-                         sizeof (struct sockaddr_in));
-    h->waiting_stun = GNUNET_NO;
-    return GNUNET_YES;
-  }
-  else
-  {
+  int valid = GNUNET_NAT_stun_handle_packet (data,
+                                             len,
+                                             &answer);
+  if (! valid)
     return GNUNET_NO;
-  }
 
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Stun server returned %s:%d\n",
+       inet_ntoa (answer.sin_addr),
+       ntohs (answer.sin_port));
+  /* Remove old IPs from previous STUN calls */
+  remove_from_address_list_by_source (h,
+                                      LAL_EXTERNAL_STUN_IP);
+  /* Add new IP from STUN packet */
+  add_to_address_list (h,
+                       LAL_EXTERNAL_STUN_IP,
+                       (const struct sockaddr *) &answer,
+                       sizeof (struct sockaddr_in));
+  h->waiting_stun = GNUNET_NO;
+  return GNUNET_YES;
+}
 
 
-}
-
 /**
  * Task to do a STUN request
  *
@@ -1186,21 +1197,23 @@
  */
 static void
 process_stun (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+              const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_NAT_Handle *h = cls;
+  struct StunServerList* elem = h->actual_stun_server;
 
   h->stun_task = NULL;
-
-
-
-  struct StunServerList* elem = h->actual_stun_server;
-
   /* Make the request */
   LOG (GNUNET_ERROR_TYPE_INFO,
-       "I will request the stun server %s:%i !\n", elem->address, elem->port);
-
-  if(GNUNET_OK == GNUNET_NAT_stun_make_request(elem->address, elem->port, 
h->socket, &stun_request_callback, NULL))
+       "I will request the stun server %s:%i\n",
+       elem->address,
+       elem->port);
+  if (GNUNET_OK ==
+      GNUNET_NAT_stun_make_request (elem->address,
+                                    elem->port,
+                                    h->socket,
+                                    &stun_request_callback,
+                                    NULL))
   {
     h->waiting_stun = GNUNET_YES;
   }
@@ -1207,15 +1220,16 @@
   else
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
-         "STUN request failed %s:%i !\n", elem->address, elem->port);
+         "STUN request to %s:%i failed\n",
+         elem->address,
+         elem->port);
   }
-
   h->stun_task =
-          GNUNET_SCHEDULER_add_delayed (h->stun_frequency,
-                                        &process_stun, h);
+    GNUNET_SCHEDULER_add_delayed (h->stun_frequency,
+                                  &process_stun, h);
 
   /* Set actual Server*/
-  if(elem->next)
+  if (NULL != elem->next)
   {
     h->actual_stun_server = elem->next;
   }
@@ -1223,11 +1237,9 @@
   {
     h->actual_stun_server = h->stun_servers_head;
   }
-
 }
 
 
-
 /**
  * Task to do a lookup on our hostname for IP addresses.
  *
@@ -1303,15 +1315,16 @@
     /* 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);
+    add_to_address_list (h,
+                         LAL_UPNP,
+                         addr,
+                         addrlen);
     return;
   }
   else if (GNUNET_NO == add_remove)
@@ -1324,10 +1337,14 @@
       if ((pos->source != LAL_UPNP) || (pos->addrlen != addrlen) ||
           (0 != memcmp (&pos[1], addr, addrlen)))
         continue;
-      GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos);
+      GNUNET_CONTAINER_DLL_remove (h->lal_head,
+                                   h->lal_tail,
+                                   pos);
       if (NULL != h->address_callback)
-        h->address_callback (h->callback_cls, GNUNET_NO,
-                             (const struct sockaddr *) &pos[1], pos->addrlen);
+        h->address_callback (h->callback_cls,
+                             GNUNET_NO,
+                             (const struct sockaddr *) &pos[1],
+                             pos->addrlen);
       GNUNET_free (pos);
       return;                     /* only remove once */
     }
@@ -1377,7 +1394,9 @@
     return;
   }
 
-  GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml);
+  GNUNET_CONTAINER_DLL_insert (h->mini_head,
+                               h->mini_tail,
+                               ml);
 }
 
 
@@ -1470,7 +1489,7 @@
                      GNUNET_NAT_AddressCallback address_callback,
                      GNUNET_NAT_ReversalCallback reversal_callback,
                      void *callback_cls,
-                     struct GNUNET_NETWORK_Handle* sock )
+                     struct GNUNET_NETWORK_Handle *sock)
 {
   struct GNUNET_NAT_Handle *h;
   struct in_addr in_addr;
@@ -1489,7 +1508,7 @@
   h->callback_cls = callback_cls;
   h->num_local_addrs = num_addrs;
   h->adv_port = adv_port;
-  if (num_addrs != 0)
+  if (0 != num_addrs)
   {
     h->local_addrs = GNUNET_malloc (num_addrs * sizeof (struct sockaddr *));
     h->local_addrlens = GNUNET_malloc (num_addrs * sizeof (socklen_t));
@@ -1574,11 +1593,14 @@
 
   /* STUN */
   h->use_stun =
-          GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat",
-                                                "USE_STUN");
+    GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                          "nat",
+                                          "USE_STUN");
 
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_time (cfg, "nat", "STUN_FREQUENCY",
+      GNUNET_CONFIGURATION_get_value_time (cfg,
+                                           "nat",
+                                           "STUN_FREQUENCY",
                                            &h->stun_frequency))
     h->stun_frequency = STUN_FREQUENCY;
 
@@ -1599,25 +1621,28 @@
          "No external IP address given to add to our list of addresses\n");
   }
 
-  /* ENABLE STUN ONLY ON UDP*/
-  if(!is_tcp && (NULL != sock) && h->use_stun  )
+  /* ENABLE STUN ONLY ON UDP */
+  if( (! is_tcp) &&
+      (NULL != sock) &&
+      h->use_stun)
   {
-    h->socket = sock;
-    h->actual_stun_server = NULL;
-
-    /* Lets process the servers*/
     char *stun_servers;
-
     size_t urls;
     int pos;
     size_t pos_port;
 
+    h->socket = sock;
+    h->actual_stun_server = NULL;
+    /* Lets process the servers*/
     if (GNUNET_OK !=
-        GNUNET_CONFIGURATION_get_value_string (cfg, "nat", "STUN_SERVERS",
+        GNUNET_CONFIGURATION_get_value_string (cfg,
+                                               "nat",
+                                               "STUN_SERVERS",
                                                &stun_servers))
     {
       GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
-                                 "nat", "STUN_SERVERS");
+                                 "nat",
+                                 "STUN_SERVERS");
     }
 
     urls = 0;
@@ -1649,10 +1674,7 @@
 
           struct StunServerList* ml = GNUNET_new (struct StunServerList);
 
-          ml->next = NULL;
-          ml->prev = NULL;
-
-          ml->port = atoi(&stun_servers[pos_port]);
+          ml->port = atoi (&stun_servers[pos_port]);
           stun_servers[pos_port-1] = '\0';
 
           /* Remove trailing space */
@@ -1662,11 +1684,15 @@
             ml->address = GNUNET_strdup (&stun_servers[pos]);
 
           LOG (GNUNET_ERROR_TYPE_DEBUG,
-               "Found STUN server %s port %i !!!\n", ml->address, ml->port);
+               "Found STUN server %s:%i\n",
+               ml->address,
+               ml->port);
 
-          GNUNET_CONTAINER_DLL_insert (h->stun_servers_head, 
h->stun_servers_tail, ml);
+          GNUNET_CONTAINER_DLL_insert (h->stun_servers_head,
+                                       h->stun_servers_tail,
+                                       ml);
           /* Make sure that we STOP if is the last one*/
-          if(0== pos)
+          if (0 == pos)
             break;
         }
 
@@ -1684,17 +1710,21 @@
       h->actual_stun_server = h->stun_servers_head;
     }
 
-    h->stun_task = GNUNET_SCHEDULER_add_now(&process_stun,
-                                            h);
+    h->stun_task = GNUNET_SCHEDULER_add_now (&process_stun,
+                                             h);
   }
 
 
   /* Test for SUID binaries */
   binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server");
-  if ((h->behind_nat == GNUNET_YES) && (GNUNET_YES == h->enable_nat_server) &&
-      (GNUNET_YES !=
-       GNUNET_OS_check_helper_binary (binary, GNUNET_YES, "-d 127.0.0.1" ))) 
// use localhost as source for that one udp-port, ok for testing
+  if ( (GNUNET_YES == h->behind_nat) &&
+       (GNUNET_YES == h->enable_nat_server) &&
+       (GNUNET_YES !=
+        GNUNET_OS_check_helper_binary (binary,
+                                       GNUNET_YES,
+                                       "-d 127.0.0.1" )))
   {
+    // use localhost as source for that one udp-port, ok for testing
     h->enable_nat_server = GNUNET_NO;
     LOG (GNUNET_ERROR_TYPE_WARNING,
          _("Configuration requires `%s', but binary is not installed properly 
(SUID bit not set).  Option disabled.\n"),
@@ -1708,8 +1738,7 @@
   {
     h->enable_nat_client = GNUNET_NO;
     LOG (GNUNET_ERROR_TYPE_WARNING,
-         _
-         ("Configuration requires `%s', but binary is not installed properly 
(SUID bit not set).  Option disabled.\n"),
+         _("Configuration requires `%s', but binary is not installed properly 
(SUID bit not set).  Option disabled.\n"),
          "gnunet-helper-nat-client");
   }
   GNUNET_free (binary);
@@ -1809,10 +1838,14 @@
   }
   while (NULL != (lal = h->lal_head))
   {
-    GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, lal);
+    GNUNET_CONTAINER_DLL_remove (h->lal_head,
+                                 h->lal_tail,
+                                 lal);
     if (NULL != h->address_callback)
-      h->address_callback (h->callback_cls, GNUNET_NO,
-                           (const struct sockaddr *) &lal[1], lal->addrlen);
+      h->address_callback (h->callback_cls,
+                           GNUNET_NO,
+                           (const struct sockaddr *) &lal[1],
+                           lal->addrlen);
     GNUNET_free (lal);
   }
   for (i = 0; i < h->num_local_addrs; i++)

Modified: gnunet/src/nat/nat.h
===================================================================
--- gnunet/src/nat/nat.h        2015-10-05 10:06:13 UTC (rev 36440)
+++ gnunet/src/nat/nat.h        2015-10-05 15:28:21 UTC (rev 36441)
@@ -37,7 +37,7 @@
 struct GNUNET_NAT_TestMessage
 {
   /**
-   * Header with type "GNUNET_MESSAGE_TYPE_NAT_TEST"
+   * Header with type #GNUNET_MESSAGE_TYPE_NAT_TEST
    */
   struct GNUNET_MessageHeader header;
 
@@ -57,7 +57,7 @@
   uint16_t data;
 
   /**
-   * GNUNET_YES for TCP, GNUNET_NO for UDP.
+   * #GNUNET_YES for TCP, #GNUNET_NO for UDP.
    */
   int32_t is_tcp;
 

Modified: gnunet/src/peerinfo-tool/gnunet-peerinfo.c
===================================================================
--- gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2015-10-05 10:06:13 UTC (rev 
36440)
+++ gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2015-10-05 15:28:21 UTC (rev 
36441)
@@ -291,15 +291,19 @@
 
   if (NULL != address)
   {
-    if (NULL == ar->result)
+    if (0 != strlen (address))
+    {
+      if (NULL != ar->result)
+        GNUNET_free (ar->result);
       ar->result = GNUNET_strdup (address);
+    }
     return;
   }
   ar->atsc = NULL;
   if (GNUNET_SYSERR == res)
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             _("Failure: Cannot convert address to string for peer `%s'\n"),
-             GNUNET_i2s (&ar->pc->peer));
+                _("Failure: Cannot convert address to string for peer `%s'\n"),
+                GNUNET_i2s (&ar->pc->peer));
   pc->num_addresses++;
   if (pc->num_addresses == pc->address_list_size)
     dump_pc (pc);
@@ -346,6 +350,11 @@
   ar = &pc->address_list[--pc->off];
   ar->pc = pc;
   ar->expiration = expiration;
+  GNUNET_asprintf (&ar->result,
+                   "%s:%u:%u",
+                   address->transport_name,
+                   address->address_length,
+                   address->local_info);
   ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
                                                  address,
                                                  no_resolve,

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2015-10-05 10:06:13 UTC 
(rev 36440)
+++ gnunet/src/transport/gnunet-service-transport.c     2015-10-05 15:28:21 UTC 
(rev 36441)
@@ -515,23 +515,31 @@
   if (GNUNET_YES == add_remove)
   {
     addresses ++;
-    GNUNET_STATISTICS_update (cfg, "# transport addresses", 1, GNUNET_NO);
+    GNUNET_STATISTICS_update (cfg,
+                              "# transport addresses",
+                              1,
+                              GNUNET_NO);
   }
   else if (GNUNET_NO == add_remove)
   {
     if (0 == addresses)
+    {
       GNUNET_break (0);
+    }
     else
     {
       addresses --;
-      GNUNET_STATISTICS_update (cfg, "# transport addresses", -1, GNUNET_NO);
+      GNUNET_STATISTICS_update (cfg,
+                                "# transport addresses",
+                                -1,
+                                GNUNET_NO);
     }
   }
-
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Transport now has %u addresses to communicate\n",
               addresses);
-  GST_hello_modify_addresses (add_remove, address);
+  GST_hello_modify_addresses (add_remove,
+                              address);
 }
 
 

Modified: gnunet/src/transport/gnunet-service-transport_hello.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_hello.c       2015-10-05 
10:06:13 UTC (rev 36440)
+++ gnunet/src/transport/gnunet-service-transport_hello.c       2015-10-05 
15:28:21 UTC (rev 36441)
@@ -76,6 +76,13 @@
    */
   struct GNUNET_CRYPTO_EddsaSignature pong_signature;
 
+  /**
+   * How often has this address been added/removed? Used as
+   * some plugins may learn the same external address from
+   * multiple origins.
+   */
+  unsigned int rc;
+
 };
 
 
@@ -133,7 +140,7 @@
 
 
 /**
- * Add an address from the 'OwnAddressList' to the buffer.
+ * Add an address from the `struct OwnAddressList` to the buffer.
  *
  * @param cls the `struct GeneratorContext`
  * @param max maximum number of bytes left
@@ -151,8 +158,10 @@
 
   if (NULL == gc->addr_pos)
     return GNUNET_SYSERR; /* Done */
-  ret = GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, buf,
-                                max);
+  ret = GNUNET_HELLO_add_address (gc->addr_pos->address,
+                                  gc->expiration,
+                                  buf,
+                                  max);
   gc->addr_pos = gc->addr_pos->next;
   return ret;
 }
@@ -267,7 +276,7 @@
 const struct GNUNET_MessageHeader *
 GST_hello_get ()
 {
-  return (struct GNUNET_MessageHeader *) our_hello;
+  return (const struct GNUNET_MessageHeader *) our_hello;
 }
 
 
@@ -284,28 +293,44 @@
   struct OwnAddressList *al;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              (addremove ==
-               GNUNET_YES) ? "Adding `%s' to the set of our addresses\n" :
-              "Removing `%s' from the set of our addresses\n",
+              (GNUNET_YES == addremove)
+              ? "Adding `%s' to the set of our addresses\n"
+              : "Removing `%s' from the set of our addresses\n",
               GST_plugins_a2s (address));
-  GNUNET_assert (address != NULL);
+  GNUNET_assert (NULL != address);
+  for (al = oal_head; al != NULL; al = al->next)
+    if (0 == GNUNET_HELLO_address_cmp (address, al->address))
+      break;
   if (GNUNET_NO == addremove)
   {
-    for (al = oal_head; al != NULL; al = al->next)
-      if (0 == GNUNET_HELLO_address_cmp (address, al->address))
-      {
-        GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al);
-        GNUNET_HELLO_address_free (al->address);
-        GNUNET_free (al);
-        refresh_hello ();
-        return;
-      }
-    /* address to be removed not found!? */
-    GNUNET_break (0);
+    if (NULL == al)
+    {
+      /* address to be removed not found!? */
+      GNUNET_break (0);
+      return;
+    }
+    al->rc--;
+    if (0 != al->rc)
+      return; /* RC not yet zero */
+    GNUNET_CONTAINER_DLL_remove (oal_head,
+                                 oal_tail,
+                                 al);
+    GNUNET_HELLO_address_free (al->address);
+    GNUNET_free (al);
+    refresh_hello ();
     return;
   }
+  if (NULL != al)
+  {
+    /* address added twice or more */
+    al->rc++;
+    return;
+  }
   al = GNUNET_new (struct OwnAddressList);
-  GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al);
+  al->rc = 1;
+  GNUNET_CONTAINER_DLL_insert (oal_head,
+                               oal_tail,
+                               al);
   al->address = GNUNET_HELLO_address_copy (address);
   refresh_hello ();
 }

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2015-10-05 10:06:13 UTC (rev 
36440)
+++ gnunet/src/transport/plugin_transport_udp.c 2015-10-05 15:28:21 UTC (rev 
36441)
@@ -2855,12 +2855,12 @@
     return;
   }
 
+  /* Check if this is a STUN packet */
+  if (GNUNET_NAT_is_valid_stun_packet (plugin->nat,
+                                       (uint8_t *)buf,
+                                       size))
+    return; /* was STUN, do not process further */
 
-  /* PROCESS STUN PACKET */
-  if(GNUNET_NAT_is_valid_stun_packet(plugin->nat,(uint8_t *)buf, size ))
-    return;
-
-
   if (size < sizeof(struct GNUNET_MessageHeader))
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,




reply via email to

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