aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-01-15 14:19:55 +0000
committerBart Polot <bart@net.in.tum.de>2015-01-15 14:19:55 +0000
commita5806d420808546c4dd4bf47b9017572d79fe799 (patch)
tree1a6460c0cd2c10b5ec5863461a27c7a46d2fee14 /src/cadet
parent9a422930cd63c70030f02db5d12659849c05dd31 (diff)
downloadgnunet-a5806d420808546c4dd4bf47b9017572d79fe799.tar.gz
gnunet-a5806d420808546c4dd4bf47b9017572d79fe799.zip
- added path_cmp
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_path.c23
-rw-r--r--src/cadet/cadet_path.h13
2 files changed, 36 insertions, 0 deletions
diff --git a/src/cadet/cadet_path.c b/src/cadet/cadet_path.c
index c00e417b1..b09bf0227 100644
--- a/src/cadet/cadet_path.c
+++ b/src/cadet/cadet_path.c
@@ -294,6 +294,29 @@ path_destroy (struct CadetPeerPath *p)
294} 294}
295 295
296 296
297/**
298 * Compare two paths.
299 *
300 * @param p1 First path.
301 * @param p2 Second path.
302 *
303 * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1.
304 * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2.
305 * 0 if they are identical.
306 */
307int
308path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
309{
310 if (p1->length > p2->length)
311 return 1;
312
313 if (p1->length < p2->length)
314 return -1;
315
316 return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length);
317}
318
319
297char * 320char *
298path_2s (struct CadetPeerPath *p) 321path_2s (struct CadetPeerPath *p)
299{ 322{
diff --git a/src/cadet/cadet_path.h b/src/cadet/cadet_path.h
index 326626f9d..aa951e5c8 100644
--- a/src/cadet/cadet_path.h
+++ b/src/cadet/cadet_path.h
@@ -172,6 +172,19 @@ int
172path_destroy (struct CadetPeerPath *p); 172path_destroy (struct CadetPeerPath *p);
173 173
174/** 174/**
175 * Compare two paths.
176 *
177 * @param p1 First path.
178 * @param p2 Second path.
179 *
180 * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1.
181 * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2.
182 * 0 if they are identical.
183 */
184int
185path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2);
186
187/**
175 * Builds a path from a PeerIdentity array. 188 * Builds a path from a PeerIdentity array.
176 * 189 *
177 * @param peers PeerIdentity array. 190 * @param peers PeerIdentity array.