gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated: sanitize paths to eliminate


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: sanitize paths to eliminate loops before using them; fix off-by-one causing a peer to be listed twice
Date: Sun, 29 Jan 2017 19:31:13 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new e1635836e sanitize paths to eliminate loops before using them; fix 
off-by-one causing a peer to be listed twice
e1635836e is described below

commit e1635836e1d844c25c701937e0be08f272fb84f6
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Jan 29 19:31:12 2017 +0100

    sanitize paths to eliminate loops before using them; fix off-by-one causing 
a peer to be listed twice
---
 src/cadet/gnunet-service-cadet-new_paths.c | 38 ++++++++++++++++++++----------
 src/cadet/gnunet-service-cadet-new_peer.c  |  4 ++--
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/cadet/gnunet-service-cadet-new_paths.c 
b/src/cadet/gnunet-service-cadet-new_paths.c
index 685656ec3..28df5e159 100644
--- a/src/cadet/gnunet-service-cadet-new_paths.c
+++ b/src/cadet/gnunet-service-cadet-new_paths.c
@@ -454,25 +454,39 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity 
*get_path,
   struct CadetPeerPath *path;
   struct GNUNET_CONTAINER_HeapNode *hn;
   int i;
+  unsigned int skip;
+  unsigned int total_len;
 
   /* precompute 'cpath' so we can avoid doing the lookups lots of times */
-  for (unsigned int off=0;off<get_path_length + put_path_length;off++)
+  skip = 0;
+  total_len = get_path_length + put_path_length;
+  for (unsigned int off=0;off<total_len;off++)
   {
     const struct GNUNET_PeerIdentity *pid;
 
     pid = (off < get_path_length)
       ? &get_path[get_path_length - off]
       : &put_path[get_path_length + put_path_length - off];
-    cpath[off] = GCP_get (pid,
-                          GNUNET_YES);
+    cpath[off - skip] = GCP_get (pid,
+                                 GNUNET_YES);
+    /* Check that no peer is twice on the path */
+    for (unsigned int i=0;i<off;i++)
+    {
+      if (cpath[i] == cpath[off])
+      {
+        skip = off - i;
+        break;
+      }
+    }
   }
+  total_len -= skip;
 
   /* First figure out if this path is a subset of an existing path, an
      extension of an existing path, or a new path. */
-  cm_ctx.cpath_length = get_path_length + put_path_length;
+  cm_ctx.cpath_length = total_len;
   cm_ctx.cpath = cpath;
   cm_ctx.match = NULL;
-  for (i=get_path_length + put_path_length-1;i>=0;i--)
+  for (i=total_len-1;i>=0;i--)
   {
     GCP_iterate_paths_at (cpath[i],
                           (unsigned int) i,
@@ -480,7 +494,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity 
*get_path,
                           &cm_ctx);
     if (NULL != cm_ctx.match)
     {
-      if (i == get_path_length + put_path_length - 1)
+      if (i == total_len - 1)
       {
         /* Existing path includes this one, nothing to do! */
         LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -494,8 +508,8 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity 
*get_path,
              "Trying to extend existing path %s by additional links discovered 
from DHT\n",
              GCPP_2s (cm_ctx.match));
         extend_path (cm_ctx.match,
-                     &cpath[i],
-                     get_path_length + put_path_length - i,
+                     &cpath[i + 1],
+                     total_len - i - 1,
                      GNUNET_NO);
         return;
       }
@@ -504,7 +518,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity 
*get_path,
 
   /* No match at all, create completely new path */
   path = GNUNET_new (struct CadetPeerPath);
-  path->entries_length = get_path_length + put_path_length;
+  path->entries_length = total_len;
   path->entries = GNUNET_new_array (path->entries_length,
                                     struct CadetPeerPathEntry *);
   for (i=path->entries_length-1;i>=0;i--)
@@ -526,7 +540,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity 
*get_path,
 
   /* Finally, try to attach it */
   hn = NULL;
-  for (i=get_path_length + put_path_length-1;i>=0;i--)
+  for (i=total_len-1;i>=0;i--)
   {
     struct CadetPeerPathEntry *entry = path->entries[i];
 
@@ -613,8 +627,8 @@ GCPP_get_path_from_route (unsigned int path_length,
              "Extending existing path %s to create inverse for incoming 
connection\n",
              GCPP_2s (cm_ctx.match));
         extend_path (cm_ctx.match,
-                     &cpath[i],
-                     path_length - i,
+                     &cpath[i + 1],
+                     path_length - i - 1,
                      GNUNET_YES);
         /* Check that extension was successful */
         GNUNET_assert (cm_ctx.match->entries_length == path_length);
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c 
b/src/cadet/gnunet-service-cadet-new_peer.c
index bcc69be53..9e84550ec 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.c
+++ b/src/cadet/gnunet-service-cadet-new_peer.c
@@ -114,9 +114,9 @@ struct CadetPeer
   struct GNUNET_PeerIdentity pid;
 
   /**
-   * Last time we heard from this peer
+   * Last time we heard from this peer (currently not used!)
    */
-  struct GNUNET_TIME_Absolute last_contact;
+  struct GNUNET_TIME_Absolute last_contactXXX;
 
   /**
    * Array of DLLs of paths traversing the peer, organized by the

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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