diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-07 22:56:37 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-07 22:56:37 +0000 |
commit | 676fbb0f20ca8372a7c76082c879ae5a3af3971d (patch) | |
tree | 99727d5f14dea051a06afd41557521a8ddbc93c7 /src/rps | |
parent | f4736ff5d86734375c446d80650742d57ebe0ee9 (diff) | |
download | gnunet-676fbb0f20ca8372a7c76082c879ae5a3af3971d.tar.gz gnunet-676fbb0f20ca8372a7c76082c879ae5a3af3971d.zip |
check if id is already in current push/pull_list
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 130fef535..8aef30a9f 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -263,6 +263,35 @@ uint64_t g_i = 0; | |||
263 | ***********************************************************************/ | 263 | ***********************************************************************/ |
264 | 264 | ||
265 | /** | 265 | /** |
266 | * Check if peer is already in peer array. | ||
267 | */ | ||
268 | int | ||
269 | in_arr (const struct GNUNET_PeerIdentity *array, | ||
270 | unsigned int arr_size, | ||
271 | const struct GNUNET_PeerIdentity *peer) | ||
272 | { | ||
273 | GNUNET_assert (NULL != peer); | ||
274 | |||
275 | if (0 == arr_size) | ||
276 | return GNUNET_NO; | ||
277 | |||
278 | GNUNET_assert (NULL != array); | ||
279 | |||
280 | unsigned int i; | ||
281 | |||
282 | i = 0; | ||
283 | while (0 != GNUNET_CRYPTO_cmp_peer_identity (&array[i], peer) && | ||
284 | i < arr_size) | ||
285 | i++; | ||
286 | |||
287 | if (i == arr_size) | ||
288 | return GNUNET_NO; | ||
289 | else | ||
290 | return GNUNET_YES; | ||
291 | } | ||
292 | |||
293 | |||
294 | /** | ||
266 | * Get random peer from the gossip list. | 295 | * Get random peer from the gossip list. |
267 | */ | 296 | */ |
268 | struct GNUNET_PeerIdentity * | 297 | struct GNUNET_PeerIdentity * |
@@ -503,9 +532,8 @@ handle_peer_push (void *cls, | |||
503 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PUSH received (%s)\n", GNUNET_i2s (peer)); | 532 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PUSH received (%s)\n", GNUNET_i2s (peer)); |
504 | 533 | ||
505 | /* Add the sending peer to the push_list */ | 534 | /* Add the sending peer to the push_list */ |
506 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding peer to push_list of size %u\n", push_list_size); | 535 | if (GNUNET_NO == in_arr (push_list, pull_list_size, peer)) |
507 | GNUNET_array_append (push_list, push_list_size, *peer); | 536 | GNUNET_array_append (push_list, push_list_size, *peer); |
508 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Size of push_list is now %u\n", push_list_size); | ||
509 | 537 | ||
510 | return GNUNET_OK; | 538 | return GNUNET_OK; |
511 | } | 539 | } |
@@ -598,7 +626,8 @@ handle_peer_pull_reply (void *cls, | |||
598 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 626 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
599 | for ( i = 0 ; i < GNUNET_ntohll (in_msg->num_peers) ; i++ ) | 627 | for ( i = 0 ; i < GNUNET_ntohll (in_msg->num_peers) ; i++ ) |
600 | { | 628 | { |
601 | GNUNET_array_append (pull_list, pull_list_size, peers[i]); | 629 | if (GNUNET_NO == in_arr(pull_list, pull_list_size, &peers[i])) |
630 | GNUNET_array_append (pull_list, pull_list_size, peers[i]); | ||
602 | } | 631 | } |
603 | 632 | ||
604 | // TODO check that id is valid - whether it is reachable | 633 | // TODO check that id is valid - whether it is reachable |
@@ -613,7 +642,7 @@ handle_peer_pull_reply (void *cls, | |||
613 | * This is executed regylary. | 642 | * This is executed regylary. |
614 | */ | 643 | */ |
615 | static void | 644 | static void |
616 | do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 645 | do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
617 | { | 646 | { |
618 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round\n"); | 647 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round\n"); |
619 | 648 | ||