aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_path.c')
-rw-r--r--src/cadet/cadet_path.c34
1 files changed, 34 insertions, 0 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.