diff options
author | Bart Polot <bart@net.in.tum.de> | 2015-01-15 14:19:55 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2015-01-15 14:19:55 +0000 |
commit | a5806d420808546c4dd4bf47b9017572d79fe799 (patch) | |
tree | 1a6460c0cd2c10b5ec5863461a27c7a46d2fee14 /src/cadet | |
parent | 9a422930cd63c70030f02db5d12659849c05dd31 (diff) | |
download | gnunet-a5806d420808546c4dd4bf47b9017572d79fe799.tar.gz gnunet-a5806d420808546c4dd4bf47b9017572d79fe799.zip |
- added path_cmp
Diffstat (limited to 'src/cadet')
-rw-r--r-- | src/cadet/cadet_path.c | 23 | ||||
-rw-r--r-- | src/cadet/cadet_path.h | 13 |
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 | */ | ||
307 | int | ||
308 | path_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 | |||
297 | char * | 320 | char * |
298 | path_2s (struct CadetPeerPath *p) | 321 | path_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 | |||
172 | path_destroy (struct CadetPeerPath *p); | 172 | path_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 | */ | ||
184 | int | ||
185 | path_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. |