aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rps/gnunet-service-rps.c21
-rw-r--r--src/rps/gnunet-service-rps_sampler.c29
-rw-r--r--src/rps/gnunet-service-rps_sampler.h10
3 files changed, 36 insertions, 24 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 36bfeba24..1448a046f 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -203,12 +203,6 @@ static uint32_t gossip_list_size;
203 203
204 204
205/** 205/**
206 * The actual size of the sampler
207 */
208static unsigned int sampler_size;
209//size_t sampler_size;
210
211/**
212 * The size of sampler we need to be able to satisfy the client's need of 206 * The size of sampler we need to be able to satisfy the client's need of
213 * random peers. 207 * random peers.
214 */ 208 */
@@ -712,6 +706,7 @@ insert_in_sampler_scheduled (const struct PeerContext *peer_ctx)
712resize_wrapper () 706resize_wrapper ()
713{ 707{
714 uint32_t bigger_size; 708 uint32_t bigger_size;
709 unsigned int sampler_size;
715 710
716 // TODO statistics 711 // TODO statistics
717 712
@@ -721,15 +716,14 @@ resize_wrapper ()
721 bigger_size = sampler_size_est_need; 716 bigger_size = sampler_size_est_need;
722 717
723 // TODO respect the min, max 718 // TODO respect the min, max
719 sampler_size = RPS_sampler_get_size ();
724 if (sampler_size > bigger_size * 4) 720 if (sampler_size > bigger_size * 4)
725 { /* Shrinking */ 721 { /* Shrinking */
726 sampler_size = sampler_size / 2; 722 RPS_sampler_resize (sampler_size / 2);
727 RPS_sampler_resize (sampler_size);
728 } 723 }
729 else if (sampler_size < bigger_size) 724 else if (sampler_size < bigger_size)
730 { /* Growing */ 725 { /* Growing */
731 sampler_size = sampler_size * 2; 726 RPS_sampler_resize (sampler_size * 2);
732 RPS_sampler_resize (sampler_size);
733 } 727 }
734} 728}
735 729
@@ -794,8 +788,8 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
794 //double scale; // TODO this might go gloabal/config 788 //double scale; // TODO this might go gloabal/config
795 789
796 LOG (GNUNET_ERROR_TYPE_DEBUG, 790 LOG (GNUNET_ERROR_TYPE_DEBUG,
797 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %f)\n", 791 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %f)\n",
798 logestimate, std_dev, sampler_size); 792 logestimate, std_dev, RPS_sampler_get_size());
799 //scale = .01; 793 //scale = .01;
800 estimate = GNUNET_NSE_log_estimate_to_n (logestimate); 794 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
801 // GNUNET_NSE_log_estimate_to_n (logestimate); 795 // GNUNET_NSE_log_estimate_to_n (logestimate);
@@ -1402,7 +1396,7 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1402 if (NULL != peer_ctx->send_channel 1396 if (NULL != peer_ctx->send_channel
1403 && ch != peer_ctx->send_channel) 1397 && ch != peer_ctx->send_channel)
1404 GNUNET_CADET_channel_destroy (peer_ctx->send_channel); 1398 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1405 1399
1406 if (NULL != peer_ctx->recv_channel 1400 if (NULL != peer_ctx->recv_channel
1407 && ch != peer_ctx->recv_channel) 1401 && ch != peer_ctx->recv_channel)
1408 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); 1402 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
@@ -1658,7 +1652,6 @@ run (void *cls,
1658 1652
1659 RPS_sampler_init (sampler_size_est_need, max_round_interval, 1653 RPS_sampler_init (sampler_size_est_need, max_round_interval,
1660 insertCB, NULL, removeCB, NULL); 1654 insertCB, NULL, removeCB, NULL);
1661 sampler_size = sampler_size_est_need;
1662 1655
1663 /* Initialise push and pull maps */ 1656 /* Initialise push and pull maps */
1664 push_list = NULL; 1657 push_list = NULL;
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)
315RPS_sampler_elem_create (void) 315RPS_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 */
408unsigned int
409RPS_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
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h
index a7021b4fe..4949ef9c6 100644
--- a/src/rps/gnunet-service-rps_sampler.h
+++ b/src/rps/gnunet-service-rps_sampler.h
@@ -65,6 +65,14 @@ typedef void
65 */ 65 */
66//struct RPS_Sampler; 66//struct RPS_Sampler;
67 67
68/**
69 * Get the size of the sampler.
70 *
71 * @return the size of the sampler
72 */
73unsigned int
74RPS_sampler_get_size ();
75
68 76
69/** 77/**
70 * Grow or shrink the size of the sampler. 78 * Grow or shrink the size of the sampler.
@@ -80,7 +88,7 @@ RPS_sampler_resize (unsigned int new_size);
80 * 88 *
81 * @param init_size the size the sampler is initialised with 89 * @param init_size the size the sampler is initialised with
82 * @param id with which all newly created sampler elements are initialised 90 * @param id with which all newly created sampler elements are initialised
83 * @param ins_cb the callback that will be called on every PeerID that is 91 * @param ins_cb the callback that will be called on every PeerID that is
84 * newly inserted into a sampler element 92 * newly inserted into a sampler element
85 * @param ins_cls the closure given to #ins_cb 93 * @param ins_cls the closure given to #ins_cb
86 * @param rem_cb the callback that will be called on every PeerID that is 94 * @param rem_cb the callback that will be called on every PeerID that is