aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_sampler.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-02-07 16:19:34 +0000
committerJulius Bünger <buenger@mytum.de>2015-02-07 16:19:34 +0000
commit9faea17ef30144323b311e282238f5caaabe451e (patch)
treeb66df9c6bff36959b44889f18a5414dae2e0df66 /src/rps/gnunet-service-rps_sampler.c
parentb85b68adb5960859e735319eb27a0d1594020d52 (diff)
downloadgnunet-9faea17ef30144323b311e282238f5caaabe451e.tar.gz
gnunet-9faea17ef30144323b311e282238f5caaabe451e.zip
distinct samplers for client and Brahms protocol
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r--src/rps/gnunet-service-rps_sampler.c157
1 files changed, 94 insertions, 63 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index 92826d875..ceb3dacd1 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -199,6 +199,11 @@ struct GetPeerCls
199 struct GetPeerCls *prev; 199 struct GetPeerCls *prev;
200 200
201 /** 201 /**
202 * The sampler this function operates on.
203 */
204 struct RPS_Sampler *sampler;
205
206 /**
202 * The task for this function. 207 * The task for this function.
203 */ 208 */
204 struct GNUNET_SCHEDULER_Task *get_peer_task; 209 struct GNUNET_SCHEDULER_Task *get_peer_task;
@@ -220,10 +225,10 @@ struct GetPeerCls
220}; 225};
221 226
222 227
223/** 228///**
224 * Global sampler variable. 229// * Global sampler variable.
225 */ 230// */
226struct RPS_Sampler *sampler; 231//struct RPS_Sampler *sampler;
227 232
228 233
229/** 234/**
@@ -331,12 +336,17 @@ RPS_sampler_elem_create (void)
331 336
332 337
333/** 338/**
334 * Input an PeerID into the given sampler. 339 * Input an PeerID into the given sampler element.
340 *
341 * @param sampler the sampler the @a s_elem belongs to.
342 * Needed to know the
335 */ 343 */
336 static void 344static void
337RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_PeerIdentity *other, 345RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
338 RPS_sampler_insert_cb insert_cb, void *insert_cls, 346 struct RPS_Sampler *sampler,
339 RPS_sampler_remove_cb remove_cb, void *remove_cls) 347 const struct GNUNET_PeerIdentity *other,
348 RPS_sampler_insert_cb insert_cb, void *insert_cls,
349 RPS_sampler_remove_cb remove_cb, void *remove_cls)
340{ 350{
341 struct GNUNET_HashCode other_hash; 351 struct GNUNET_HashCode other_hash;
342 352
@@ -363,8 +373,8 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe
363 s_elem->peer_id = *other; 373 s_elem->peer_id = *other;
364 s_elem->peer_id_hash = other_hash; 374 s_elem->peer_id_hash = other_hash;
365 375
366 if (NULL != sampler->insert_cb) 376 if (NULL != insert_cb)
367 sampler->insert_cb (sampler->insert_cls, &(s_elem->peer_id)); 377 insert_cb (insert_cls, sampler, &(s_elem->peer_id));
368 378
369 s_elem->num_change++; 379 s_elem->num_change++;
370 } 380 }
@@ -375,21 +385,21 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe
375 LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n", 385 LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n",
376 GNUNET_i2s (&s_elem->peer_id)); 386 GNUNET_i2s (&s_elem->peer_id));
377 387
378 if ( NULL != sampler->remove_cb ) 388 if ( NULL != remove_cb )
379 { 389 {
380 LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing old PeerID %s with the remove callback.\n", 390 LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing old PeerID %s with the remove callback.\n",
381 GNUNET_i2s (&s_elem->peer_id)); 391 GNUNET_i2s (&s_elem->peer_id));
382 sampler->remove_cb (sampler->remove_cls, &s_elem->peer_id); 392 remove_cb (remove_cls, sampler, &s_elem->peer_id);
383 } 393 }
384 394
385 s_elem->peer_id = *other; 395 s_elem->peer_id = *other;
386 s_elem->peer_id_hash = other_hash; 396 s_elem->peer_id_hash = other_hash;
387 397
388 if ( NULL != sampler->insert_cb ) 398 if ( NULL != insert_cb )
389 { 399 {
390 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inserting new PeerID %s with the insert callback.\n", 400 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inserting new PeerID %s with the insert callback.\n",
391 GNUNET_i2s (&s_elem->peer_id)); 401 GNUNET_i2s (&s_elem->peer_id));
392 sampler->insert_cb(sampler->insert_cls, &s_elem->peer_id); 402 insert_cb (insert_cls, sampler, &s_elem->peer_id);
393 } 403 }
394 404
395 s_elem->num_change++; 405 s_elem->num_change++;
@@ -405,13 +415,15 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe
405 s_elem->is_empty = NOT_EMPTY; 415 s_elem->is_empty = NOT_EMPTY;
406} 416}
407 417
418
408/** 419/**
409 * Get the size of the sampler. 420 * Get the size of the sampler.
410 * 421 *
422 * @param sampler the sampler to return the size of.
411 * @return the size of the sampler 423 * @return the size of the sampler
412 */ 424 */
413unsigned int 425unsigned int
414RPS_sampler_get_size () 426RPS_sampler_get_size (struct RPS_Sampler *sampler)
415{ 427{
416 return sampler->sampler_size; 428 return sampler->sampler_size;
417} 429}
@@ -420,10 +432,11 @@ RPS_sampler_get_size ()
420/** 432/**
421 * Grow or shrink the size of the sampler. 433 * Grow or shrink the size of the sampler.
422 * 434 *
435 * @param sampler the sampler to resize.
423 * @param new_size the new size of the sampler 436 * @param new_size the new size of the sampler
424 */ 437 */
425static void 438static void
426sampler_resize (unsigned int new_size) 439sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
427{ 440{
428 unsigned int old_size; 441 unsigned int old_size;
429 uint32_t i; 442 uint32_t i;
@@ -451,7 +464,7 @@ sampler_resize (unsigned int new_size)
451 {/* Remove unneeded rest */ 464 {/* Remove unneeded rest */
452 LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing %" PRIX32 ". sampler\n", i); 465 LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing %" PRIX32 ". sampler\n", i);
453 if (NULL != sampler->remove_cb) 466 if (NULL != sampler->remove_cb)
454 sampler->remove_cb (sampler->remove_cls, &rem_list[i]->peer_id); 467 sampler->remove_cb (sampler->remove_cls, sampler, &rem_list[i]->peer_id);
455 GNUNET_free (rem_list[i]); 468 GNUNET_free (rem_list[i]);
456 } 469 }
457 GNUNET_free (rem_list); 470 GNUNET_free (rem_list);
@@ -468,7 +481,7 @@ sampler_resize (unsigned int new_size)
468 { /* Add new sampler elements */ 481 { /* Add new sampler elements */
469 sampler->sampler_elements[i] = RPS_sampler_elem_create (); 482 sampler->sampler_elements[i] = RPS_sampler_elem_create ();
470 if (NULL != sampler->insert_cb) 483 if (NULL != sampler->insert_cb)
471 sampler->insert_cb (sampler->insert_cls, &sampler->sampler_elements[i]->peer_id); 484 sampler->insert_cb (sampler->insert_cls, sampler, &sampler->sampler_elements[i]->peer_id);
472 LOG (GNUNET_ERROR_TYPE_DEBUG, 485 LOG (GNUNET_ERROR_TYPE_DEBUG,
473 "Added %" PRIX32 ". sampler, now pointing to %p, contains %s\n", 486 "Added %" PRIX32 ". sampler, now pointing to %p, contains %s\n",
474 i, &sampler->sampler_elements[i], GNUNET_i2s (&sampler->sampler_elements[i]->peer_id)); 487 i, &sampler->sampler_elements[i], GNUNET_i2s (&sampler->sampler_elements[i]->peer_id));
@@ -488,25 +501,27 @@ sampler_resize (unsigned int new_size)
488/** 501/**
489 * Grow or shrink the size of the sampler. 502 * Grow or shrink the size of the sampler.
490 * 503 *
504 * @param sampler the sampler to resize.
491 * @param new_size the new size of the sampler 505 * @param new_size the new size of the sampler
492 */ 506 */
493void 507void
494RPS_sampler_resize (unsigned int new_size) 508RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
495{ 509{
496 GNUNET_assert (0 < new_size); 510 GNUNET_assert (0 < new_size);
497 sampler_resize (new_size); 511 sampler_resize (sampler, new_size);
498} 512}
499 513
500 514
501/** 515/**
502 * Empty the sampler. 516 * Empty the sampler.
503 * 517 *
518 * @param sampler the sampler to empty.
504 * @param new_size the new size of the sampler 519 * @param new_size the new size of the sampler
505 */ 520 */
506static void 521static void
507sampler_empty () 522sampler_empty (struct RPS_Sampler *sampler)
508{ 523{
509 sampler_resize (0); 524 sampler_resize (sampler, 0);
510} 525}
511 526
512 527
@@ -520,14 +535,15 @@ sampler_empty ()
520 * @param rem_cb the callback that will be called on every PeerID that is 535 * @param rem_cb the callback that will be called on every PeerID that is
521 * removed from a sampler element 536 * removed from a sampler element
522 * @param rem_cls the closure given to #rem_cb 537 * @param rem_cls the closure given to #rem_cb
538 * @return a handle to a sampler that consists of sampler elements.
523 */ 539 */
524 void 540struct RPS_Sampler *
525RPS_sampler_init (size_t init_size, 541RPS_sampler_init (size_t init_size,
526 struct GNUNET_TIME_Relative max_round_interval, 542 struct GNUNET_TIME_Relative max_round_interval,
527 RPS_sampler_insert_cb ins_cb, void *ins_cls, 543 RPS_sampler_insert_cb ins_cb, void *ins_cls,
528 RPS_sampler_remove_cb rem_cb, void *rem_cls) 544 RPS_sampler_remove_cb rem_cb, void *rem_cls)
529{ 545{
530 //struct RPS_Sampler *sampler; 546 struct RPS_Sampler *sampler;
531 //uint32_t i; 547 //uint32_t i;
532 548
533 /* Initialise context around extended sampler */ 549 /* Initialise context around extended sampler */
@@ -544,26 +560,30 @@ RPS_sampler_init (size_t init_size,
544 sampler->remove_cls = rem_cls; 560 sampler->remove_cls = rem_cls;
545 //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); 561 //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
546 //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); 562 //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
547 RPS_sampler_resize (init_size); 563 RPS_sampler_resize (sampler, init_size);
548 564
549 client_get_index = 0; 565 client_get_index = 0;
550 566
551 //GNUNET_assert (init_size == sampler->sampler_size); 567 //GNUNET_assert (init_size == sampler->sampler_size);
568 return sampler;
552} 569}
553 570
554 571
555/** 572/**
556 * A fuction to update every sampler in the given list 573 * A fuction to update every sampler in the given list
557 * 574 *
575 * @param sampler the sampler to update.
558 * @param id the PeerID that is put in the sampler 576 * @param id the PeerID that is put in the sampler
559 */ 577 */
560 void 578 void
561RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id) 579RPS_sampler_update (struct RPS_Sampler *sampler,
580 const struct GNUNET_PeerIdentity *id)
562{ 581{
563 uint32_t i; 582 uint32_t i;
564 583
565 for ( i = 0 ; i < sampler->sampler_size ; i++ ) 584 for ( i = 0 ; i < sampler->sampler_size ; i++ )
566 RPS_sampler_elem_next (sampler->sampler_elements[i], id, 585 RPS_sampler_elem_next (sampler->sampler_elements[i],
586 sampler, id,
567 sampler->insert_cb, sampler->insert_cls, 587 sampler->insert_cb, sampler->insert_cls,
568 sampler->remove_cb, sampler->remove_cls); 588 sampler->remove_cb, sampler->remove_cls);
569} 589}
@@ -574,10 +594,12 @@ RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id)
574 * 594 *
575 * Used to get rid of a PeerID. 595 * Used to get rid of a PeerID.
576 * 596 *
597 * @param sampler the sampler to reinitialise a sampler element in.
577 * @param id the id of the sampler elements to update. 598 * @param id the id of the sampler elements to update.
578 */ 599 */
579 void 600 void
580RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id) 601RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
602 const struct GNUNET_PeerIdentity *id)
581{ 603{
582 uint32_t i; 604 uint32_t i;
583 605
@@ -614,10 +636,10 @@ sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
614 * Choose the r_index of the peer we want to return 636 * Choose the r_index of the peer we want to return
615 * at random from the interval of the gossip list 637 * at random from the interval of the gossip list
616 */ 638 */
617 r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, 639 r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
618 sampler->sampler_size); 640 gpc->sampler->sampler_size);
619 641
620 if ( EMPTY == sampler->sampler_elements[r_index]->is_empty ) 642 if ( EMPTY == gpc->sampler->sampler_elements[r_index]->is_empty )
621 { 643 {
622 gpc->get_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 644 gpc->get_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
623 GNUNET_TIME_UNIT_SECONDS, 645 GNUNET_TIME_UNIT_SECONDS,
@@ -627,7 +649,7 @@ sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
627 return; 649 return;
628 } 650 }
629 651
630 *gpc->id = sampler->sampler_elements[r_index]->peer_id; 652 *gpc->id = gpc->sampler->sampler_elements[r_index]->peer_id;
631 653
632 gpc->cont (gpc->cont_cls, gpc->id); 654 gpc->cont (gpc->cont_cls, gpc->id);
633 GNUNET_free (gpc); 655 GNUNET_free (gpc);
@@ -639,8 +661,6 @@ sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
639 * 661 *
640 * We might want to reinitialise this sampler after giving the 662 * We might want to reinitialise this sampler after giving the
641 * corrsponding peer to the client. 663 * corrsponding peer to the client.
642 *
643 * @return a random PeerID of the PeerIDs previously put into the sampler.
644 */ 664 */
645static void 665static void
646sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 666sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -663,60 +683,65 @@ sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
663 if (0 < client_get_index) 683 if (0 < client_get_index)
664 tmp_client_get_index = client_get_index - 1; 684 tmp_client_get_index = client_get_index - 1;
665 else 685 else
666 tmp_client_get_index = sampler->sampler_size - 1; 686 tmp_client_get_index = gpc->sampler->sampler_size - 1;
667 687
668 LOG (GNUNET_ERROR_TYPE_DEBUG, 688 LOG (GNUNET_ERROR_TYPE_DEBUG,
669 "scheduling for later if index reaches %" PRIX32 " (sampler size: %" PRIX32 ").\n", 689 "sched for later if index reaches %" PRIX32 " (sampler size: %" PRIX32 ").\n",
670 tmp_client_get_index, sampler->sampler_size); 690 tmp_client_get_index, gpc->sampler->sampler_size);
671 691
672 do 692 do
673 { /* Get first non empty sampler */ 693 { /* Get first non empty sampler */
674 if (tmp_client_get_index == client_get_index) 694 if (tmp_client_get_index == client_get_index)
675 { 695 {
676 LOG (GNUNET_ERROR_TYPE_DEBUG, "reached tmp_index %" PRIX32 ".\n", client_get_index); 696 LOG (GNUNET_ERROR_TYPE_DEBUG, "reached tmp_index %" PRIX32 ".\n",
697 client_get_index);
677 GNUNET_assert (NULL == gpc->get_peer_task); 698 GNUNET_assert (NULL == gpc->get_peer_task);
678 gpc->get_peer_task = GNUNET_SCHEDULER_add_delayed (sampler->max_round_interval, 699 gpc->get_peer_task =
679 &sampler_get_rand_peer, 700 GNUNET_SCHEDULER_add_delayed (gpc->sampler->max_round_interval,
680 cls); 701 &sampler_get_rand_peer, cls);
681 return; 702 return;
682 } 703 }
683 704
684 tmp_id = sampler->sampler_elements[client_get_index]->peer_id; 705 tmp_id = gpc->sampler->sampler_elements[client_get_index]->peer_id;
685 RPS_sampler_elem_reinit (sampler->sampler_elements[client_get_index]); 706 RPS_sampler_elem_reinit (gpc->sampler->sampler_elements[client_get_index]);
686 RPS_sampler_elem_next (sampler->sampler_elements[client_get_index], &tmp_id, 707 RPS_sampler_elem_next (gpc->sampler->sampler_elements[client_get_index],
687 NULL, NULL, NULL, NULL); 708 gpc->sampler, &tmp_id, NULL, NULL, NULL, NULL);
688 709
689 /* Cycle the #client_get_index one step further */ 710 /* Cycle the #client_get_index one step further */
690 if ( client_get_index == sampler->sampler_size - 1 ) 711 if ( client_get_index == gpc->sampler->sampler_size - 1 )
691 client_get_index = 0; 712 client_get_index = 0;
692 else 713 else
693 client_get_index++; 714 client_get_index++;
694 715
695 LOG (GNUNET_ERROR_TYPE_DEBUG, "incremented index to %" PRIX32 ".\n", client_get_index); 716 LOG (GNUNET_ERROR_TYPE_DEBUG, "incremented index to %" PRIX32 ".\n",
696 } while (EMPTY == sampler->sampler_elements[client_get_index]->is_empty); 717 client_get_index);
718 } while (EMPTY == gpc->sampler->sampler_elements[client_get_index]->is_empty);
697 719
698 s_elem = sampler->sampler_elements[client_get_index]; 720 s_elem = gpc->sampler->sampler_elements[client_get_index];
699 *gpc->id = s_elem->peer_id; 721 *gpc->id = s_elem->peer_id;
700 722
701 /* Check whether we may use this sampler to give it back to the client */ 723 /* Check whether we may use this sampler to give it back to the client */
702 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) 724 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us)
703 { 725 {
704 last_request_diff = GNUNET_TIME_absolute_get_difference (s_elem->last_client_request, 726 last_request_diff =
705 GNUNET_TIME_absolute_get ()); 727 GNUNET_TIME_absolute_get_difference (s_elem->last_client_request,
706 /* We're not going to give it back now if it was already requested by a client this round */ 728 GNUNET_TIME_absolute_get ());
707 if (last_request_diff.rel_value_us < sampler->max_round_interval.rel_value_us) 729 /* We're not going to give it back now if it was
730 * already requested by a client this round */
731 if (last_request_diff.rel_value_us < gpc->sampler->max_round_interval.rel_value_us)
708 { 732 {
709 LOG (GNUNET_ERROR_TYPE_DEBUG, 733 LOG (GNUNET_ERROR_TYPE_DEBUG,
710 "Last client request on this sampler was less than max round interval ago -- scheduling for later\n"); 734 "Last client request on this sampler was less than max round interval ago -- scheduling for later\n");
711 ///* How many time remains untile the next round has started? */ 735 ///* How many time remains untile the next round has started? */
712 //inv_last_request_diff = GNUNET_TIME_absolute_get_difference (last_request_diff, 736 //inv_last_request_diff =
713 // sampler->max_round_interval); 737 // GNUNET_TIME_absolute_get_difference (last_request_diff,
738 // sampler->max_round_interval);
714 // add a little delay 739 // add a little delay
715 /* Schedule it one round later */ 740 /* Schedule it one round later */
716 GNUNET_assert (NULL == gpc->get_peer_task); 741 GNUNET_assert (NULL == gpc->get_peer_task);
717 gpc->get_peer_task = GNUNET_SCHEDULER_add_delayed (sampler->max_round_interval, 742 gpc->get_peer_task =
718 &sampler_get_rand_peer, 743 GNUNET_SCHEDULER_add_delayed (gpc->sampler->max_round_interval,
719 cls); 744 &sampler_get_rand_peer, cls);
720 return; 745 return;
721 } 746 }
722 // TODO add other reasons to wait here 747 // TODO add other reasons to wait here
@@ -736,6 +761,7 @@ sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
736 * corrsponding peer to the client. 761 * corrsponding peer to the client.
737 * Random with or without consumption? 762 * Random with or without consumption?
738 * 763 *
764 * @param sampler the sampler to get peers from.
739 * @param cb callback that will be called once the ids are ready. 765 * @param cb callback that will be called once the ids are ready.
740 * @param cls closure given to @a cb 766 * @param cls closure given to @a cb
741 * @param for_client #GNUNET_YES if result is used for client, 767 * @param for_client #GNUNET_YES if result is used for client,
@@ -743,7 +769,8 @@ sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
743 * @param num_peers the number of peers requested 769 * @param num_peers the number of peers requested
744 */ 770 */
745 void 771 void
746RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb, 772RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
773 RPS_sampler_n_rand_peers_ready_cb cb,
747 void *cls, uint32_t num_peers, int for_client) 774 void *cls, uint32_t num_peers, int for_client)
748{ 775{
749 GNUNET_assert (0 != sampler->sampler_size); 776 GNUNET_assert (0 != sampler->sampler_size);
@@ -766,6 +793,7 @@ RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
766 for ( i = 0 ; i < num_peers ; i++ ) 793 for ( i = 0 ; i < num_peers ; i++ )
767 { 794 {
768 gpc = GNUNET_new (struct GetPeerCls); 795 gpc = GNUNET_new (struct GetPeerCls);
796 gpc->sampler = sampler;
769 gpc->cont = check_n_peers_ready; 797 gpc->cont = check_n_peers_ready;
770 gpc->cont_cls = cb_cls; 798 gpc->cont_cls = cb_cls;
771 gpc->id = &cb_cls->ids[i]; 799 gpc->id = &cb_cls->ids[i];
@@ -786,12 +814,14 @@ RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
786/** 814/**
787 * Counts how many Samplers currently hold a given PeerID. 815 * Counts how many Samplers currently hold a given PeerID.
788 * 816 *
817 * @param sampler the sampler to count ids in.
789 * @param id the PeerID to count. 818 * @param id the PeerID to count.
790 * 819 *
791 * @return the number of occurrences of id. 820 * @return the number of occurrences of id.
792 */ 821 */
793 uint32_t 822 uint32_t
794RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id) 823RPS_sampler_count_id (struct RPS_Sampler *sampler,
824 const struct GNUNET_PeerIdentity *id)
795{ 825{
796 uint32_t count; 826 uint32_t count;
797 uint32_t i; 827 uint32_t i;
@@ -811,7 +841,7 @@ RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id)
811 * Cleans the sampler. 841 * Cleans the sampler.
812 */ 842 */
813 void 843 void
814RPS_sampler_destroy () 844RPS_sampler_destroy (struct RPS_Sampler *sampler)
815{ 845{
816 struct GetPeerCls *i; 846 struct GetPeerCls *i;
817 847
@@ -822,7 +852,8 @@ RPS_sampler_destroy ()
822 GNUNET_free (i); 852 GNUNET_free (i);
823 } 853 }
824 854
825 sampler_empty (); 855 sampler_empty (sampler);
856 GNUNET_free (sampler);
826} 857}
827 858
828/* end of gnunet-service-rps.c */ 859/* end of gnunet-service-rps.c */