[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34610 - gnunet/src/cadet
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34610 - gnunet/src/cadet |
Date: |
Mon, 15 Dec 2014 08:18:20 +0100 |
Author: bartpolot
Date: 2014-12-15 08:18:20 +0100 (Mon, 15 Dec 2014)
New Revision: 34610
Modified:
gnunet/src/cadet/cadet_path.c
gnunet/src/cadet/cadet_path.h
gnunet/src/cadet/gnunet-service-cadet_connection.c
Log:
- refactorize path checking code, look both ways
Modified: gnunet/src/cadet/cadet_path.c
===================================================================
--- gnunet/src/cadet/cadet_path.c 2014-12-15 07:18:18 UTC (rev 34609)
+++ gnunet/src/cadet/cadet_path.c 2014-12-15 07:18:20 UTC (rev 34610)
@@ -223,6 +223,40 @@
/**
+ * Test if two paths are equivalent (equal or revese of each other).
+ *
+ * @param p1 First path
+ * @param p2 Second path
+ *
+ * @return GNUNET_YES if both paths are equivalent
+ * GNUNET_NO otherwise
+ */
+int
+path_equivalent (const struct CadetPeerPath *p1,
+ const struct CadetPeerPath *p2)
+{
+ unsigned int i;
+ unsigned int l;
+ unsigned int half;
+
+ if (p1->length != p2->length)
+ return GNUNET_NO;
+
+ l = p1->length;
+ if (0 == memcmp (p1->peers, p2->peers, sizeof (p1->peers[0]) * l))
+ return GNUNET_YES;
+
+ half = l / 2;
+ l = l - 1;
+ for (i = 0; i <= half; i++)
+ if (p1->peers[i] != p2->peers[l - i])
+ return GNUNET_NO;
+
+ return GNUNET_YES;
+}
+
+
+/**
* Test if a path is valid (or at least not known to be invalid).
*
* @param path Path to test.
Modified: gnunet/src/cadet/cadet_path.h
===================================================================
--- gnunet/src/cadet/cadet_path.h 2014-12-15 07:18:18 UTC (rev 34609)
+++ gnunet/src/cadet/cadet_path.h 2014-12-15 07:18:20 UTC (rev 34610)
@@ -138,6 +138,19 @@
path_invalidate (struct CadetPeerPath *p);
/**
+ * Test if two paths are equivalent (equal or revese of each other).
+ *
+ * @param p1 First path
+ * @param p2 Second path
+ *
+ * @return GNUNET_YES if both paths are equivalent
+ * GNUNET_NO otherwise
+ */
+int
+path_equivalent (const struct CadetPeerPath *p1,
+ const struct CadetPeerPath *p2);
+
+/**
* Test if a path is valid (or at least not known to be invalid).
*
* @param path Path to test.
Modified: gnunet/src/cadet/gnunet-service-cadet_connection.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_connection.c 2014-12-15 07:18:18 UTC
(rev 34609)
+++ gnunet/src/cadet/gnunet-service-cadet_connection.c 2014-12-15 07:18:20 UTC
(rev 34610)
@@ -1536,16 +1536,14 @@
struct CadetConnection *new_conn = cls;
struct CadetPeerPath *path = new_conn->path;
- LOG (GNUNET_ERROR_TYPE_DEBUG, " checking %s, length %u\n",
- GCC_2s (c), c->path->length);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " checking %s (%p), length %u\n",
+ GCC_2s (c), c, c->path->length);
if (c != new_conn
&& c->destroy == GNUNET_NO
&& c->state != CADET_CONNECTION_BROKEN
&& c->state != CADET_CONNECTION_DESTROYED
- && c->path->length == path->length
- && 0 == memcmp (c->path->peers, path->peers,
- sizeof (path->peers[0]) * path->length))
+ && path_equivalent (path, c->path))
{
new_conn->destroy = GNUNET_YES;
new_conn->path->c = c;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34610 - gnunet/src/cadet,
gnunet <=