diff options
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index d6a9db4db..01d8aa748 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -82,7 +82,7 @@ struct RPS_SamplerElement | |||
82 | * Time of last request. | 82 | * Time of last request. |
83 | */ | 83 | */ |
84 | struct GNUNET_TIME_Absolute last_client_request; | 84 | struct GNUNET_TIME_Absolute last_client_request; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Flag that indicates that we are not holding a valid PeerID right now. | 87 | * Flag that indicates that we are not holding a valid PeerID right now. |
88 | */ | 88 | */ |
@@ -251,7 +251,7 @@ static uint32_t client_get_index; | |||
251 | /** | 251 | /** |
252 | * Callback to _get_rand_peer() used by _get_n_rand_peers(). | 252 | * Callback to _get_rand_peer() used by _get_n_rand_peers(). |
253 | * | 253 | * |
254 | * Checks whether all n peers are available. If they are, | 254 | * Checks whether all n peers are available. If they are, |
255 | * give those back. | 255 | * give those back. |
256 | */ | 256 | */ |
257 | void | 257 | void |
@@ -274,7 +274,7 @@ check_n_peers_ready (void *cls, | |||
274 | "SAMPLER: returning %" PRIX32 " peers to the client\n", | 274 | "SAMPLER: returning %" PRIX32 " peers to the client\n", |
275 | n_peers_cls->num_peers); | 275 | n_peers_cls->num_peers); |
276 | n_peers_cls->callback (n_peers_cls->cls, n_peers_cls->ids, n_peers_cls->num_peers); | 276 | n_peers_cls->callback (n_peers_cls->cls, n_peers_cls->ids, n_peers_cls->num_peers); |
277 | 277 | ||
278 | GNUNET_free (n_peers_cls); | 278 | GNUNET_free (n_peers_cls); |
279 | } | 279 | } |
280 | } | 280 | } |
@@ -315,7 +315,7 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_el) | |||
315 | RPS_sampler_elem_create (void) | 315 | RPS_sampler_elem_create (void) |
316 | { | 316 | { |
317 | struct RPS_SamplerElement *s; | 317 | struct RPS_SamplerElement *s; |
318 | 318 | ||
319 | s = GNUNET_new (struct RPS_SamplerElement); | 319 | s = GNUNET_new (struct RPS_SamplerElement); |
320 | 320 | ||
321 | RPS_sampler_elem_reinit (s); | 321 | RPS_sampler_elem_reinit (s); |
@@ -352,7 +352,7 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe | |||
352 | &other_hash); | 352 | &other_hash); |
353 | 353 | ||
354 | if ( EMPTY == s_elem->is_empty ) | 354 | if ( EMPTY == s_elem->is_empty ) |
355 | { | 355 | { |
356 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Simply accepting (was empty previously).\n", | 356 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Simply accepting (was empty previously).\n", |
357 | GNUNET_i2s(other)); | 357 | GNUNET_i2s(other)); |
358 | s_elem->peer_id = *other; | 358 | s_elem->peer_id = *other; |
@@ -400,6 +400,17 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe | |||
400 | s_elem->is_empty = NOT_EMPTY; | 400 | s_elem->is_empty = NOT_EMPTY; |
401 | } | 401 | } |
402 | 402 | ||
403 | /** | ||
404 | * Get the size of the sampler. | ||
405 | * | ||
406 | * @return the size of the sampler | ||
407 | */ | ||
408 | unsigned int | ||
409 | RPS_sampler_get_size () | ||
410 | { | ||
411 | return sampler->sampler_size; | ||
412 | } | ||
413 | |||
403 | 414 | ||
404 | /** | 415 | /** |
405 | * Grow or shrink the size of the sampler. | 416 | * Grow or shrink the size of the sampler. |
@@ -464,7 +475,7 @@ RPS_sampler_resize (unsigned int new_size) | |||
464 | return; | 475 | return; |
465 | } | 476 | } |
466 | 477 | ||
467 | GNUNET_assert(sampler->sampler_size == new_size); | 478 | GNUNET_assert (sampler->sampler_size == new_size); |
468 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Finished growing/shrinking.\n"); // remove | 479 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Finished growing/shrinking.\n"); // remove |
469 | } | 480 | } |
470 | 481 | ||
@@ -473,7 +484,7 @@ RPS_sampler_resize (unsigned int new_size) | |||
473 | * Initialise a tuple of sampler elements. | 484 | * Initialise a tuple of sampler elements. |
474 | * | 485 | * |
475 | * @param init_size the size the sampler is initialised with | 486 | * @param init_size the size the sampler is initialised with |
476 | * @param ins_cb the callback that will be called on every PeerID that is | 487 | * @param ins_cb the callback that will be called on every PeerID that is |
477 | * newly inserted into a sampler element | 488 | * newly inserted into a sampler element |
478 | * @param ins_cls the closure given to #ins_cb | 489 | * @param ins_cls the closure given to #ins_cb |
479 | * @param rem_cb the callback that will be called on every PeerID that is | 490 | * @param rem_cb the callback that will be called on every PeerID that is |
@@ -766,7 +777,7 @@ RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id) | |||
766 | count = 0; | 777 | count = 0; |
767 | for ( i = 0 ; i < sampler->sampler_size ; i++ ) | 778 | for ( i = 0 ; i < sampler->sampler_size ; i++ ) |
768 | { | 779 | { |
769 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&sampler->sampler_elements[i]->peer_id, id) | 780 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&sampler->sampler_elements[i]->peer_id, id) |
770 | && EMPTY != sampler->sampler_elements[i]->is_empty) | 781 | && EMPTY != sampler->sampler_elements[i]->is_empty) |
771 | count++; | 782 | count++; |
772 | } | 783 | } |
@@ -786,7 +797,7 @@ clear_get_peer_tasks (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
786 | GNUNET_SCHEDULER_cancel (task); | 797 | GNUNET_SCHEDULER_cancel (task); |
787 | 798 | ||
788 | GNUNET_CONTAINER_multihashmap_remove (get_peer_tasks, key, value); | 799 | GNUNET_CONTAINER_multihashmap_remove (get_peer_tasks, key, value); |
789 | 800 | ||
790 | return GNUNET_YES; | 801 | return GNUNET_YES; |
791 | } | 802 | } |
792 | 803 | ||