Check for cycles in cadet paths
authorDavid Barksdale <amatus@amat.us>
Sat, 23 Dec 2017 15:54:23 +0000 (09:54 -0600)
committerDavid Barksdale <amatus@amat.us>
Sat, 23 Dec 2017 15:54:23 +0000 (09:54 -0600)
I believe this is the underlying issue from commit
012ff13acc0cb2f5d7210aa48819395fecf12a3d. I tested out this change and
saw that cyclic paths were dropped and GCP_set_mq() no longer had to
deal with multiple removals. After this commit I'll revert that one.

src/cadet/gnunet-service-cadet_core.c

index a67bbf445636c084cea62ded71a132475ba1c3a8..cb213fc545c72fcb4c9645de706444fb28cba20f 100644 (file)
@@ -773,10 +773,31 @@ handle_connection_create (void *cls,
   path_length = size / sizeof (struct GNUNET_PeerIdentity);
   if (0 == path_length)
   {
-    /* bogus request */
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Dropping CADET_CONNECTION_CREATE with empty path\n");
     GNUNET_break_op (0);
     return;
   }
+  /* Check for loops */
+  struct GNUNET_CONTAINER_MultiPeerMap *map;
+  map = GNUNET_CONTAINER_multipeermap_create (path_length,
+                                              GNUNET_YES);
+  GNUNET_assert (NULL != map);
+  for (off = 0; off < path_length; off++) {
+    if (GNUNET_SYSERR ==
+        GNUNET_CONTAINER_multipeermap_put (map,
+                                           &pids[off],
+                                           NULL,
+                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) {
+      /* bogus request */
+      GNUNET_CONTAINER_multipeermap_destroy (map);
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
+      GNUNET_break_op (0);
+      return;
+    }
+  }
+  GNUNET_CONTAINER_multipeermap_destroy (map);
   /* Initiator is at offset 0. */
   for (off=1;off<path_length;off++)
     if (0 == memcmp (&my_full_id,
@@ -785,7 +806,8 @@ handle_connection_create (void *cls,
       break;
   if (off == path_length)
   {
-    /* We are not on the path, bogus request */
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Dropping CADET_CONNECTION_CREATE without us in the path\n");
     GNUNET_break_op (0);
     return;
   }
@@ -793,7 +815,8 @@ handle_connection_create (void *cls,
   if (sender != GCP_get (&pids[off - 1],
                          GNUNET_NO))
   {
-    /* sender is not on the path, not allowed */
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Dropping CADET_CONNECTION_CREATE without sender in the path\n");
     GNUNET_break_op (0);
     return;
   }