From 9def71212263b1fcaaa54795a07c97c5b9118a75 Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Sat, 23 Dec 2017 09:54:23 -0600 Subject: [PATCH] Check for cycles in cadet paths 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 | 29 ++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index a67bbf445..cb213fc54 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c @@ -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