aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-01-18 05:06:13 +0000
committerJulius Bünger <buenger@mytum.de>2015-01-18 05:06:13 +0000
commitd9e72f536edc429a375957bcbcc9cc9603ce965b (patch)
tree00f6af64d7fd94f57c24105e5f210bd81be22ed5
parente993426d1447a693c96920beb5bb469f78f1fdae (diff)
downloadgnunet-d9e72f536edc429a375957bcbcc9cc9603ce965b.tar.gz
gnunet-d9e72f536edc429a375957bcbcc9cc9603ce965b.zip
fixed integer sizes and _get_rand_peer()
-rw-r--r--src/rps/gnunet-service-rps.c39
-rw-r--r--src/rps/gnunet-service-rps_sampler.c83
-rw-r--r--src/rps/gnunet-service-rps_sampler.h8
3 files changed, 71 insertions, 59 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 12ad109b4..cbcacb2db 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -349,7 +349,7 @@ in_arr (const struct GNUNET_PeerIdentity *array,
349 struct GNUNET_PeerIdentity * 349 struct GNUNET_PeerIdentity *
350get_rand_peer (const struct GNUNET_PeerIdentity *peer_list, unsigned int list_size) 350get_rand_peer (const struct GNUNET_PeerIdentity *peer_list, unsigned int list_size)
351{ 351{
352 uint64_t r_index; 352 uint32_t r_index;
353 struct GNUNET_PeerIdentity *peer; 353 struct GNUNET_PeerIdentity *peer;
354 354
355 peer = GNUNET_new (struct GNUNET_PeerIdentity); 355 peer = GNUNET_new (struct GNUNET_PeerIdentity);
@@ -448,10 +448,10 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_Peer
448 * Sum all time relatives of an array. 448 * Sum all time relatives of an array.
449 */ 449 */
450 struct GNUNET_TIME_Relative 450 struct GNUNET_TIME_Relative
451T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint64_t arr_size) 451T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
452{ 452{
453 struct GNUNET_TIME_Relative sum; 453 struct GNUNET_TIME_Relative sum;
454 uint64_t i; 454 uint32_t i;
455 455
456 sum = GNUNET_TIME_UNIT_ZERO; 456 sum = GNUNET_TIME_UNIT_ZERO;
457 for ( i = 0 ; i < arr_size ; i++ ) 457 for ( i = 0 ; i < arr_size ; i++ )
@@ -466,7 +466,7 @@ T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint64_t arr_size)
466 * Compute the average of given time relatives. 466 * Compute the average of given time relatives.
467 */ 467 */
468 struct GNUNET_TIME_Relative 468 struct GNUNET_TIME_Relative
469T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint64_t arr_size) 469T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
470{ 470{
471 return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size), arr_size); // FIXME find a way to devide that by arr_size 471 return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size), arr_size); // FIXME find a way to devide that by arr_size
472} 472}
@@ -482,7 +482,7 @@ T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint64_t arr_size)
482 void 482 void
483resize_wrapper () 483resize_wrapper ()
484{ 484{
485 uint64_t bigger_size; 485 uint32_t bigger_size;
486 486
487 // TODO statistics 487 // TODO statistics
488 488
@@ -541,8 +541,9 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestima
541 * Sends those to the requesting client. 541 * Sends those to the requesting client.
542 */ 542 */
543void client_respond (void *cls, 543void client_respond (void *cls,
544 struct GNUNET_PeerIdentity *ids, uint64_t num_peers) 544 struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
545{ 545{
546 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIX32 " peers\n", num_peers);
546 struct GNUNET_MQ_Envelope *ev; 547 struct GNUNET_MQ_Envelope *ev;
547 struct GNUNET_RPS_CS_ReplyMessage *out_msg; 548 struct GNUNET_RPS_CS_ReplyMessage *out_msg;
548 struct GNUNET_SERVER_Client *client; 549 struct GNUNET_SERVER_Client *client;
@@ -553,7 +554,7 @@ void client_respond (void *cls,
553 ev = GNUNET_MQ_msg_extra (out_msg, 554 ev = GNUNET_MQ_msg_extra (out_msg,
554 num_peers * sizeof (struct GNUNET_PeerIdentity), 555 num_peers * sizeof (struct GNUNET_PeerIdentity),
555 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); 556 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY);
556 out_msg->num_peers = GNUNET_htonll (num_peers); 557 out_msg->num_peers = htonl (num_peers);
557 558
558 memcpy (&out_msg[1], 559 memcpy (&out_msg[1],
559 ids, 560 ids,
@@ -583,10 +584,8 @@ handle_client_request (void *cls,
583 struct GNUNET_SERVER_Client *client, 584 struct GNUNET_SERVER_Client *client,
584 const struct GNUNET_MessageHeader *message) 585 const struct GNUNET_MessageHeader *message)
585{ 586{
586 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested (a) random peer(s).\n");
587
588 struct GNUNET_RPS_CS_RequestMessage *msg; 587 struct GNUNET_RPS_CS_RequestMessage *msg;
589 uint64_t num_peers; 588 uint32_t num_peers;
590 struct GNUNET_TIME_Relative max_round_duration; 589 struct GNUNET_TIME_Relative max_round_duration;
591 590
592 591
@@ -618,6 +617,8 @@ handle_client_request (void *cls,
618 617
619 num_peers = ntohl (msg->num_peers); 618 num_peers = ntohl (msg->num_peers);
620 619
620 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIX32 " random peer(s).\n", num_peers);
621
621 RPS_sampler_get_n_rand_peers (client_respond, client, num_peers); 622 RPS_sampler_get_n_rand_peers (client_respond, client, num_peers);
622 623
623 GNUNET_SERVER_receive_done (client, 624 GNUNET_SERVER_receive_done (client,
@@ -639,7 +640,7 @@ handle_client_seed (void *cls,
639{ 640{
640 struct GNUNET_RPS_CS_SeedMessage *in_msg; 641 struct GNUNET_RPS_CS_SeedMessage *in_msg;
641 struct GNUNET_PeerIdentity *peers; 642 struct GNUNET_PeerIdentity *peers;
642 uint64_t i; 643 uint32_t i;
643 644
644 if (sizeof (struct GNUNET_RPS_CS_SeedMessage) < ntohs (message->size)) 645 if (sizeof (struct GNUNET_RPS_CS_SeedMessage) < ntohs (message->size))
645 { 646 {
@@ -732,7 +733,7 @@ handle_peer_pull_request (void *cls,
732 ev = GNUNET_MQ_msg_extra (out_msg, 733 ev = GNUNET_MQ_msg_extra (out_msg,
733 gossip_list_size * sizeof (struct GNUNET_PeerIdentity), 734 gossip_list_size * sizeof (struct GNUNET_PeerIdentity),
734 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); 735 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY);
735 //out_msg->num_peers = GNUNET_htonll (gossip_list_size); 736 //out_msg->num_peers = htonl (gossip_list_size);
736 out_msg->num_peers = htonl (gossip_list_size); 737 out_msg->num_peers = htonl (gossip_list_size);
737 memcpy (&out_msg[1], gossip_list, 738 memcpy (&out_msg[1], gossip_list,
738 gossip_list_size * sizeof (struct GNUNET_PeerIdentity)); 739 gossip_list_size * sizeof (struct GNUNET_PeerIdentity));
@@ -763,7 +764,7 @@ handle_peer_pull_reply (void *cls,
763 764
764 struct GNUNET_RPS_P2P_PullReplyMessage *in_msg; 765 struct GNUNET_RPS_P2P_PullReplyMessage *in_msg;
765 struct GNUNET_PeerIdentity *peers; 766 struct GNUNET_PeerIdentity *peers;
766 uint64_t i; 767 uint32_t i;
767 768
768 if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size)) 769 if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size))
769 { 770 {
@@ -805,7 +806,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
805{ 806{
806 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round\n"); 807 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round\n");
807 808
808 uint64_t i; 809 uint32_t i;
809 //unsigned int *n_arr; 810 //unsigned int *n_arr;
810 unsigned int n_peers; /* Number of peers we send pushes/pulls to */ 811 unsigned int n_peers; /* Number of peers we send pushes/pulls to */
811 struct GNUNET_MQ_Envelope *ev; 812 struct GNUNET_MQ_Envelope *ev;
@@ -865,7 +866,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
865 866
866 867
867 /* Update gossip list */ 868 /* Update gossip list */
868 uint64_t r_index; 869 uint32_t r_index;
869 870
870 if ( push_list_size <= alpha * gossip_list_size && 871 if ( push_list_size <= alpha * gossip_list_size &&
871 push_list_size != 0 && 872 push_list_size != 0 &&
@@ -873,8 +874,8 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
873 { 874 {
874 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the gossip list. ()\n"); 875 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the gossip list. ()\n");
875 876
876 uint64_t first_border; 877 uint32_t first_border;
877 uint64_t second_border; 878 uint32_t second_border;
878 879
879 GNUNET_array_grow (gossip_list, gossip_list_size, sampler_size_est_need); 880 GNUNET_array_grow (gossip_list, gossip_list_size, sampler_size_est_need);
880 881
@@ -1081,6 +1082,8 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1081 1082
1082 if ( NULL != peer_ctx->from_channel) 1083 if ( NULL != peer_ctx->from_channel)
1083 GNUNET_CADET_channel_destroy (peer_ctx->from_channel); 1084 GNUNET_CADET_channel_destroy (peer_ctx->from_channel);
1085
1086 // call _peermap_remove_all()?
1084 1087
1085 return GNUNET_YES; 1088 return GNUNET_YES;
1086} 1089}
@@ -1098,7 +1101,7 @@ shutdown_task (void *cls,
1098{ 1101{
1099 LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n"); 1102 LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
1100 1103
1101 uint64_t num_peers; 1104 uint32_t num_peers;
1102 1105
1103 if ( NULL != do_round_task ) 1106 if ( NULL != do_round_task )
1104 { 1107 {
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index 0d131e198..ac7e8203a 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -121,13 +121,6 @@ struct RPS_Sampler
121 struct RPS_SamplerElement **sampler_elements; 121 struct RPS_SamplerElement **sampler_elements;
122 122
123 /** 123 /**
124 * Index to a sampler element.
125 *
126 * Gets cycled on every hist_request.
127 */
128 uint64_t sampler_elem_index;
129
130 /**
131 * Max time a round takes 124 * Max time a round takes
132 * 125 *
133 * Used in the context of RPS 126 * Used in the context of RPS
@@ -163,12 +156,12 @@ struct RPS_GetNRandPeersReadyCls
163 /** 156 /**
164 * Number of peers we are waiting for. 157 * Number of peers we are waiting for.
165 */ 158 */
166 uint64_t num_peers; 159 uint32_t num_peers;
167 160
168 /** 161 /**
169 * Number of peers we currently have. 162 * Number of peers we currently have.
170 */ 163 */
171 uint64_t cur_num_peers; 164 uint32_t cur_num_peers;
172 165
173 /** 166 /**
174 * Pointer to the array holding the ids. 167 * Pointer to the array holding the ids.
@@ -252,7 +245,7 @@ static size_t max_size;
252/** 245/**
253 * Inedex to the sampler element that is the next to be returned 246 * Inedex to the sampler element that is the next to be returned
254 */ 247 */
255static uint64_t client_get_index; 248static uint32_t client_get_index;
256 249
257 250
258/** 251/**
@@ -270,15 +263,15 @@ RPS_sampler_get_n_rand_peers_ready_cb (void *cls,
270 n_peers_cls = (struct RPS_GetNRandPeersReadyCls *) cls; 263 n_peers_cls = (struct RPS_GetNRandPeersReadyCls *) cls;
271 264
272 LOG (GNUNET_ERROR_TYPE_DEBUG, 265 LOG (GNUNET_ERROR_TYPE_DEBUG,
273 "SAMPLER: Got %" PRIX64 "th of %" PRIX64 " peers\n", 266 "SAMPLER: Got %" PRIX32 "th of %" PRIX32 " peers\n",
274 n_peers_cls->cur_num_peers, n_peers_cls->num_peers); 267 n_peers_cls->cur_num_peers, n_peers_cls->num_peers);
275 268
276 if (n_peers_cls->num_peers == n_peers_cls->cur_num_peers) 269 if (n_peers_cls->num_peers - 1 == n_peers_cls->cur_num_peers)
277 { /* All peers are ready -- return those to the client */ 270 { /* All peers are ready -- return those to the client */
278 GNUNET_assert (NULL != n_peers_cls->callback); 271 GNUNET_assert (NULL != n_peers_cls->callback);
279 272
280 LOG (GNUNET_ERROR_TYPE_DEBUG, 273 LOG (GNUNET_ERROR_TYPE_DEBUG,
281 "SAMPLER: returning %" PRIX64 " peers to the client\n", 274 "SAMPLER: returning %" PRIX32 " peers to the client\n",
282 n_peers_cls->num_peers); 275 n_peers_cls->num_peers);
283 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);
284 277
@@ -423,7 +416,7 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe
423RPS_sampler_resize (unsigned int new_size) 416RPS_sampler_resize (unsigned int new_size)
424{ 417{
425 unsigned int old_size; 418 unsigned int old_size;
426 uint64_t i; 419 uint32_t i;
427 struct RPS_SamplerElement **rem_list; 420 struct RPS_SamplerElement **rem_list;
428 421
429 // TODO check min and max size 422 // TODO check min and max size
@@ -446,7 +439,7 @@ RPS_sampler_resize (unsigned int new_size)
446 439
447 for (i = 0 ; i < old_size - new_size ; i++) 440 for (i = 0 ; i < old_size - new_size ; i++)
448 {/* Remove unneeded rest */ 441 {/* Remove unneeded rest */
449 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ". sampler\n", i); 442 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX32 ". sampler\n", i);
450 if (NULL != sampler->remove_cb) 443 if (NULL != sampler->remove_cb)
451 sampler->remove_cb (sampler->remove_cls, &rem_list[i]->peer_id); 444 sampler->remove_cb (sampler->remove_cls, &rem_list[i]->peer_id);
452 GNUNET_free (rem_list[i]); 445 GNUNET_free (rem_list[i]);
@@ -467,7 +460,7 @@ RPS_sampler_resize (unsigned int new_size)
467 if (NULL != sampler->insert_cb) 460 if (NULL != sampler->insert_cb)
468 sampler->insert_cb (sampler->insert_cls, &sampler->sampler_elements[i]->peer_id); 461 sampler->insert_cb (sampler->insert_cls, &sampler->sampler_elements[i]->peer_id);
469 LOG (GNUNET_ERROR_TYPE_DEBUG, 462 LOG (GNUNET_ERROR_TYPE_DEBUG,
470 "SAMPLER: Added %" PRIX64 ". sampler, now pointing to %p, contains %s\n", 463 "SAMPLER: Added %" PRIX32 ". sampler, now pointing to %p, contains %s\n",
471 i, &sampler->sampler_elements[i], GNUNET_i2s (&sampler->sampler_elements[i]->peer_id)); 464 i, &sampler->sampler_elements[i], GNUNET_i2s (&sampler->sampler_elements[i]->peer_id));
472 } 465 }
473 } 466 }
@@ -502,7 +495,7 @@ RPS_sampler_init (size_t init_size,
502 RPS_sampler_remove_cb rem_cb, void *rem_cls) 495 RPS_sampler_remove_cb rem_cb, void *rem_cls)
503{ 496{
504 //struct RPS_Sampler *sampler; 497 //struct RPS_Sampler *sampler;
505 //uint64_t i; 498 //uint32_t i;
506 499
507 /* Initialise context around extended sampler */ 500 /* Initialise context around extended sampler */
508 min_size = 10; // TODO make input to _samplers_init() 501 min_size = 10; // TODO make input to _samplers_init()
@@ -536,7 +529,7 @@ RPS_sampler_init (size_t init_size,
536 void 529 void
537RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id) 530RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id)
538{ 531{
539 uint64_t i; 532 uint32_t i;
540 533
541 for ( i = 0 ; i < sampler->sampler_size ; i++ ) 534 for ( i = 0 ; i < sampler->sampler_size ; i++ )
542 RPS_sampler_elem_next (sampler->sampler_elements[i], id, 535 RPS_sampler_elem_next (sampler->sampler_elements[i], id,
@@ -555,7 +548,7 @@ RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id)
555 void 548 void
556RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id) 549RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id)
557{ 550{
558 uint64_t i; 551 uint32_t i;
559 552
560 for ( i = 0 ; i < sampler->sampler_size ; i++ ) 553 for ( i = 0 ; i < sampler->sampler_size ; i++ )
561 { 554 {
@@ -578,7 +571,7 @@ RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id)
578 const struct GNUNET_PeerIdentity * 571 const struct GNUNET_PeerIdentity *
579RPS_sampler_get_rand_peer_ () 572RPS_sampler_get_rand_peer_ ()
580{ 573{
581 uint64_t r_index; 574 uint32_t r_index;
582 const struct GNUNET_PeerIdentity *peer; // do we have to malloc that? 575 const struct GNUNET_PeerIdentity *peer; // do we have to malloc that?
583 576
584 // TODO implement extra logic 577 // TODO implement extra logic
@@ -611,7 +604,7 @@ RPS_sampler_get_rand_peer_ ()
611 * Only used internally 604 * Only used internally
612 */ 605 */
613 const struct GNUNET_PeerIdentity * 606 const struct GNUNET_PeerIdentity *
614RPS_sampler_get_n_rand_peers_ (uint64_t n) 607RPS_sampler_get_n_rand_peers_ (uint32_t n)
615{ 608{
616 if ( 0 == sampler->sampler_size ) 609 if ( 0 == sampler->sampler_size )
617 { 610 {
@@ -624,7 +617,7 @@ RPS_sampler_get_n_rand_peers_ (uint64_t n)
624 // TODO check if we have too much (distinct) sampled peers 617 // TODO check if we have too much (distinct) sampled peers
625 // If we are not ready yet maybe schedule for later 618 // If we are not ready yet maybe schedule for later
626 struct GNUNET_PeerIdentity *peers; 619 struct GNUNET_PeerIdentity *peers;
627 uint64_t i; 620 uint32_t i;
628 621
629 peers = GNUNET_malloc (n * sizeof(struct GNUNET_PeerIdentity)); 622 peers = GNUNET_malloc (n * sizeof(struct GNUNET_PeerIdentity));
630 623
@@ -654,23 +647,41 @@ RPS_sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext
654 struct RPS_SamplerElement *s_elem; 647 struct RPS_SamplerElement *s_elem;
655 struct GNUNET_TIME_Relative last_request_diff; 648 struct GNUNET_TIME_Relative last_request_diff;
656 struct GNUNET_HashCode *hash; 649 struct GNUNET_HashCode *hash;
650 uint32_t tmp_client_get_index;
657 //struct GNUNET_TIME_Relative inv_last_request_diff; 651 //struct GNUNET_TIME_Relative inv_last_request_diff;
658 652
659 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Single peer was requested\n"); 653 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Single peer was requested\n");
660 654
661 gpc = (struct GetPeerCls *) cls; 655 gpc = (struct GetPeerCls *) cls;
662 hash = GNUNET_new (struct GNUNET_HashCode); 656 hash = GNUNET_new (struct GNUNET_HashCode);
657 if (0 < client_get_index)
658 tmp_client_get_index = client_get_index - 1;
659 else
660 tmp_client_get_index = sampler->sampler_size - 1;
661
662 LOG (GNUNET_ERROR_TYPE_DEBUG,
663 "SAMPLER: scheduling for later if index reaches %" PRIX32 " (sampler size: %" PRIX32 ".\n",
664 tmp_client_get_index, sampler->sampler_size);
663 665
664 do 666 do
665 { /* Get first non empty sampler */ 667 { /* Get first non empty sampler */
666 // TODO schedule for later if all samplers are empty 668 if (tmp_client_get_index == client_get_index)
669 {
670 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: reached tmp_index %" PRIX32 ".\n", client_get_index);
671 gpc->get_peer_task = GNUNET_SCHEDULER_add_delayed (sampler->max_round_interval,
672 &RPS_sampler_get_rand_peer,
673 cls);
674 return;
675 }
676
667 *gpc->id = sampler->sampler_elements[client_get_index]->peer_id; 677 *gpc->id = sampler->sampler_elements[client_get_index]->peer_id;
668 678
669 RPS_sampler_elem_reinit (sampler->sampler_elements[client_get_index]); 679 RPS_sampler_elem_reinit (sampler->sampler_elements[client_get_index]);
670 if ( client_get_index == sampler->sampler_size ) 680 if ( client_get_index == sampler->sampler_size - 1 )
671 client_get_index = 0; 681 client_get_index = 0;
672 else 682 else
673 client_get_index++; 683 client_get_index++;
684 LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: incremented index to %" PRIX32 ".\n", client_get_index);
674 } while (EMPTY == sampler->sampler_elements[client_get_index]->is_empty); 685 } while (EMPTY == sampler->sampler_elements[client_get_index]->is_empty);
675 686
676 s_elem = sampler->sampler_elements[client_get_index]; 687 s_elem = sampler->sampler_elements[client_get_index];
@@ -698,7 +709,7 @@ RPS_sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext
698 // TODO add other reasons to wait here 709 // TODO add other reasons to wait here
699 } 710 }
700 711
701 GNUNET_CRYPTO_hash (gpc->get_peer_task, sizeof (struct GNUNET_SCHEDULER_Task *), hash); 712 GNUNET_CRYPTO_hash (&gpc->get_peer_task, sizeof (struct GNUNET_SCHEDULER_Task *), hash);
702 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (get_peer_tasks, hash, gpc->get_peer_task)) 713 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (get_peer_tasks, hash, gpc->get_peer_task))
703 LOG (GNUNET_ERROR_TYPE_WARNING, "SAMPLER: Key to remove is not in the hashmap\n"); 714 LOG (GNUNET_ERROR_TYPE_WARNING, "SAMPLER: Key to remove is not in the hashmap\n");
704 GNUNET_free (gpc->get_peer_task); 715 GNUNET_free (gpc->get_peer_task);
@@ -722,7 +733,7 @@ RPS_sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext
722 */ 733 */
723 void 734 void
724RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb, 735RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
725 void *cls, uint64_t num_peers) 736 void *cls, uint32_t num_peers)
726{ 737{
727 if ( 0 == sampler->sampler_size ) 738 if ( 0 == sampler->sampler_size )
728 { 739 {
@@ -734,35 +745,33 @@ RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
734 { 745 {
735 // TODO check if we have too much (distinct) sampled peers 746 // TODO check if we have too much (distinct) sampled peers
736 // If we are not ready yet maybe schedule for later 747 // If we are not ready yet maybe schedule for later
737 struct GNUNET_PeerIdentity *peers; 748 uint32_t i;
738 uint64_t i;
739 struct RPS_GetNRandPeersReadyCls *cb_cls; 749 struct RPS_GetNRandPeersReadyCls *cb_cls;
740 struct GetPeerCls *gpc; 750 struct GetPeerCls *gpc;
741 struct GNUNET_HashCode *hash; 751 struct GNUNET_HashCode *hash;
742 752
743 peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
744 hash = GNUNET_new (struct GNUNET_HashCode); 753 hash = GNUNET_new (struct GNUNET_HashCode);
745 754
746 cb_cls = GNUNET_new (struct RPS_GetNRandPeersReadyCls); 755 cb_cls = GNUNET_new (struct RPS_GetNRandPeersReadyCls);
747 cb_cls->num_peers = num_peers; 756 cb_cls->num_peers = num_peers;
748 cb_cls->cur_num_peers = 0; 757 cb_cls->cur_num_peers = 0;
749 cb_cls->ids = peers; 758 cb_cls->ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
750 cb_cls->callback = cb; 759 cb_cls->callback = cb;
751 cb_cls->cls = cls; 760 cb_cls->cls = cls;
752 761
753 LOG (GNUNET_ERROR_TYPE_DEBUG, 762 LOG (GNUNET_ERROR_TYPE_DEBUG,
754 "SAMPLER: Scheduling requests for %" PRIX64 " peers\n", num_peers); 763 "SAMPLER: Scheduling requests for %" PRIX32 " peers\n", num_peers);
755 764
756 for ( i = 0 ; i < num_peers ; i++ ) 765 for ( i = 0 ; i < num_peers ; i++ )
757 { 766 {
758 gpc = GNUNET_new (struct GetPeerCls); 767 gpc = GNUNET_new (struct GetPeerCls);
759 gpc->cb = RPS_sampler_get_n_rand_peers_ready_cb; 768 gpc->cb = RPS_sampler_get_n_rand_peers_ready_cb;
760 gpc->cb_cls = cb_cls; 769 gpc->cb_cls = cb_cls;
761 gpc->id = &peers[i]; 770 gpc->id = &cb_cls->ids[i];
762 771
763 // maybe add a little delay 772 // maybe add a little delay
764 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&RPS_sampler_get_rand_peer, gpc); 773 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&RPS_sampler_get_rand_peer, gpc);
765 GNUNET_CRYPTO_hash (gpc->get_peer_task, sizeof (struct GNUNET_SCHEDULER_Task *), hash); 774 GNUNET_CRYPTO_hash (&gpc->get_peer_task, sizeof (struct GNUNET_SCHEDULER_Task *), hash);
766 (void) GNUNET_CONTAINER_multihashmap_put (get_peer_tasks, hash, gpc->get_peer_task, 775 (void) GNUNET_CONTAINER_multihashmap_put (get_peer_tasks, hash, gpc->get_peer_task,
767 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 776 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
768 //RPS_sampler_get_rand_peer (RPS_sampler_get_n_rand_peers_ready_cb, 777 //RPS_sampler_get_rand_peer (RPS_sampler_get_n_rand_peers_ready_cb,
@@ -779,11 +788,11 @@ RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
779 * 788 *
780 * @return the number of occurrences of id. 789 * @return the number of occurrences of id.
781 */ 790 */
782 uint64_t 791 uint32_t
783RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id) 792RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id)
784{ 793{
785 uint64_t count; 794 uint32_t count;
786 uint64_t i; 795 uint32_t i;
787 796
788 count = 0; 797 count = 0;
789 for ( i = 0 ; i < sampler->sampler_size ; i++ ) 798 for ( i = 0 ; i < sampler->sampler_size ; i++ )
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h
index 41afe8da9..451d3cdb0 100644
--- a/src/rps/gnunet-service-rps_sampler.h
+++ b/src/rps/gnunet-service-rps_sampler.h
@@ -57,7 +57,7 @@ typedef void
57 */ 57 */
58 typedef void 58 typedef void
59(*RPS_sampler_n_rand_peers_ready_cb) (void *cls, 59(*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
60 struct GNUNET_PeerIdentity *ids, uint64_t num_peers); 60 struct GNUNET_PeerIdentity *ids, uint32_t num_peers);
61 61
62 62
63/** 63/**
@@ -124,7 +124,7 @@ RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id);
124 * Only used internally 124 * Only used internally
125 */ 125 */
126 const struct GNUNET_PeerIdentity * 126 const struct GNUNET_PeerIdentity *
127RPS_sampler_get_n_rand_peers_ (uint64_t n); 127RPS_sampler_get_n_rand_peers_ (uint32_t n);
128 128
129 129
130/** 130/**
@@ -140,7 +140,7 @@ RPS_sampler_get_n_rand_peers_ (uint64_t n);
140 */ 140 */
141 void 141 void
142RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb, 142RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
143 void *cls, uint64_t num_peers); 143 void *cls, uint32_t num_peers);
144 144
145 145
146/** 146/**
@@ -150,7 +150,7 @@ RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
150 * 150 *
151 * @return the number of occurrences of id. 151 * @return the number of occurrences of id.
152 */ 152 */
153 uint64_t 153 uint32_t
154RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id); 154RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id);
155 155
156 156