aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-12-15 07:18:20 +0000
committerBart Polot <bart@net.in.tum.de>2014-12-15 07:18:20 +0000
commitdc00985fcabd02043686215f72348e4811943487 (patch)
treea7722112712dfbf7f6e06b53154700ca72140599 /src/cadet
parenta5b5d0f609398c8c02d2a04b7818e8ce0837be02 (diff)
downloadgnunet-dc00985fcabd02043686215f72348e4811943487.tar.gz
gnunet-dc00985fcabd02043686215f72348e4811943487.zip
- refactorize path checking code, look both ways
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_path.c34
-rw-r--r--src/cadet/cadet_path.h13
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c8
3 files changed, 50 insertions, 5 deletions
diff --git a/src/cadet/cadet_path.c b/src/cadet/cadet_path.c
index 1b2d377f5..d1aa9dcf2 100644
--- a/src/cadet/cadet_path.c
+++ b/src/cadet/cadet_path.c
@@ -223,6 +223,40 @@ path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers,
223 223
224 224
225/** 225/**
226 * Test if two paths are equivalent (equal or revese of each other).
227 *
228 * @param p1 First path
229 * @param p2 Second path
230 *
231 * @return GNUNET_YES if both paths are equivalent
232 * GNUNET_NO otherwise
233 */
234int
235path_equivalent (const struct CadetPeerPath *p1,
236 const struct CadetPeerPath *p2)
237{
238 unsigned int i;
239 unsigned int l;
240 unsigned int half;
241
242 if (p1->length != p2->length)
243 return GNUNET_NO;
244
245 l = p1->length;
246 if (0 == memcmp (p1->peers, p2->peers, sizeof (p1->peers[0]) * l))
247 return GNUNET_YES;
248
249 half = l / 2;
250 l = l - 1;
251 for (i = 0; i <= half; i++)
252 if (p1->peers[i] != p2->peers[l - i])
253 return GNUNET_NO;
254
255 return GNUNET_YES;
256}
257
258
259/**
226 * Test if a path is valid (or at least not known to be invalid). 260 * Test if a path is valid (or at least not known to be invalid).
227 * 261 *
228 * @param path Path to test. 262 * @param path Path to test.
diff --git a/src/cadet/cadet_path.h b/src/cadet/cadet_path.h
index 6281ddc05..761e51156 100644
--- a/src/cadet/cadet_path.h
+++ b/src/cadet/cadet_path.h
@@ -138,6 +138,19 @@ void
138path_invalidate (struct CadetPeerPath *p); 138path_invalidate (struct CadetPeerPath *p);
139 139
140/** 140/**
141 * Test if two paths are equivalent (equal or revese of each other).
142 *
143 * @param p1 First path
144 * @param p2 Second path
145 *
146 * @return GNUNET_YES if both paths are equivalent
147 * GNUNET_NO otherwise
148 */
149int
150path_equivalent (const struct CadetPeerPath *p1,
151 const struct CadetPeerPath *p2);
152
153/**
141 * Test if a path is valid (or at least not known to be invalid). 154 * Test if a path is valid (or at least not known to be invalid).
142 * 155 *
143 * @param path Path to test. 156 * @param path Path to test.
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index e1883ce00..24f63054a 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -1536,16 +1536,14 @@ check_path (void *cls, struct CadetConnection *c)
1536 struct CadetConnection *new_conn = cls; 1536 struct CadetConnection *new_conn = cls;
1537 struct CadetPeerPath *path = new_conn->path; 1537 struct CadetPeerPath *path = new_conn->path;
1538 1538
1539 LOG (GNUNET_ERROR_TYPE_DEBUG, " checking %s, length %u\n", 1539 LOG (GNUNET_ERROR_TYPE_DEBUG, " checking %s (%p), length %u\n",
1540 GCC_2s (c), c->path->length); 1540 GCC_2s (c), c, c->path->length);
1541 1541
1542 if (c != new_conn 1542 if (c != new_conn
1543 && c->destroy == GNUNET_NO 1543 && c->destroy == GNUNET_NO
1544 && c->state != CADET_CONNECTION_BROKEN 1544 && c->state != CADET_CONNECTION_BROKEN
1545 && c->state != CADET_CONNECTION_DESTROYED 1545 && c->state != CADET_CONNECTION_DESTROYED
1546 && c->path->length == path->length 1546 && path_equivalent (path, c->path))
1547 && 0 == memcmp (c->path->peers, path->peers,
1548 sizeof (path->peers[0]) * path->length))
1549 { 1547 {
1550 new_conn->destroy = GNUNET_YES; 1548 new_conn->destroy = GNUNET_YES;
1551 new_conn->path->c = c; 1549 new_conn->path->c = c;