summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-01-28 16:39:02 +0000
committerBart Polot <bart@net.in.tum.de>2015-01-28 16:39:02 +0000
commitdf3efc93aafc83fadd659ec4b8d49fa9302b0831 (patch)
treebe36562db4d9a1778b66d16e86f0108a95684d01 /src
parent016510f7ddd6de31d6908134c9f3845e1faf2d27 (diff)
- get size direcly from sampler
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;
/**
- * The actual size of the sampler
- */
-static unsigned int sampler_size;
-//size_t sampler_size;
-
-/**
* The size of sampler we need to be able to satisfy the client's need of
* random peers.
*/
@@ -712,6 +706,7 @@ insert_in_sampler_scheduled (const struct PeerContext *peer_ctx)
resize_wrapper ()
{
uint32_t bigger_size;
+ unsigned int sampler_size;
// TODO statistics
@@ -721,15 +716,14 @@ resize_wrapper ()
bigger_size = sampler_size_est_need;
// TODO respect the min, max
+ sampler_size = RPS_sampler_get_size ();
if (sampler_size > bigger_size * 4)
{ /* Shrinking */
- sampler_size = sampler_size / 2;
- RPS_sampler_resize (sampler_size);
+ RPS_sampler_resize (sampler_size / 2);
}
else if (sampler_size < bigger_size)
{ /* Growing */
- sampler_size = sampler_size * 2;
- RPS_sampler_resize (sampler_size);
+ RPS_sampler_resize (sampler_size * 2);
}
}
@@ -794,8 +788,8 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
//double scale; // TODO this might go gloabal/config
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received a ns estimate - logest: %f, std_dev: %f (old_size: %f)\n",
- logestimate, std_dev, sampler_size);
+ "Received a ns estimate - logest: %f, std_dev: %f (old_size: %f)\n",
+ logestimate, std_dev, RPS_sampler_get_size());
//scale = .01;
estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
// GNUNET_NSE_log_estimate_to_n (logestimate);
@@ -1402,7 +1396,7 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
if (NULL != peer_ctx->send_channel
&& ch != peer_ctx->send_channel)
GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
-
+
if (NULL != peer_ctx->recv_channel
&& ch != peer_ctx->recv_channel)
GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
@@ -1658,7 +1652,6 @@ run (void *cls,
RPS_sampler_init (sampler_size_est_need, max_round_interval,
insertCB, NULL, removeCB, NULL);
- sampler_size = sampler_size_est_need;
/* Initialise push and pull maps */
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
* Time of last request.
*/
struct GNUNET_TIME_Absolute last_client_request;
-
+
/**
* Flag that indicates that we are not holding a valid PeerID right now.
*/
@@ -251,7 +251,7 @@ static uint32_t client_get_index;
/**
* Callback to _get_rand_peer() used by _get_n_rand_peers().
*
- * Checks whether all n peers are available. If they are,
+ * Checks whether all n peers are available. If they are,
* give those back.
*/
void
@@ -274,7 +274,7 @@ check_n_peers_ready (void *cls,
"SAMPLER: returning %" PRIX32 " peers to the client\n",
n_peers_cls->num_peers);
n_peers_cls->callback (n_peers_cls->cls, n_peers_cls->ids, n_peers_cls->num_peers);
-
+
GNUNET_free (n_peers_cls);
}
}
@@ -315,7 +315,7 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_el)
RPS_sampler_elem_create (void)
{
struct RPS_SamplerElement *s;
-
+
s = GNUNET_new (struct RPS_SamplerElement);
RPS_sampler_elem_reinit (s);
@@ -352,7 +352,7 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe
&other_hash);
if ( EMPTY == s_elem->is_empty )
- {
+ {
LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Simply accepting (was empty previously).\n",
GNUNET_i2s(other));
s_elem->peer_id = *other;
@@ -400,6 +400,17 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_Pe
s_elem->is_empty = NOT_EMPTY;
}
+/**
+ * Get the size of the sampler.
+ *
+ * @return the size of the sampler
+ */
+unsigned int
+RPS_sampler_get_size ()
+{
+ return sampler->sampler_size;
+}
+
/**
* Grow or shrink the size of the sampler.
@@ -464,7 +475,7 @@ RPS_sampler_resize (unsigned int new_size)
return;
}
- GNUNET_assert(sampler->sampler_size == new_size);
+ GNUNET_assert (sampler->sampler_size == new_size);
LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Finished growing/shrinking.\n"); // remove
}
@@ -473,7 +484,7 @@ RPS_sampler_resize (unsigned int new_size)
* Initialise a tuple of sampler elements.
*
* @param init_size the size the sampler is initialised with
- * @param ins_cb the callback that will be called on every PeerID that is
+ * @param ins_cb the callback that will be called on every PeerID that is
* newly inserted into a sampler element
* @param ins_cls the closure given to #ins_cb
* @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)
count = 0;
for ( i = 0 ; i < sampler->sampler_size ; i++ )
{
- if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&sampler->sampler_elements[i]->peer_id, id)
+ if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&sampler->sampler_elements[i]->peer_id, id)
&& EMPTY != sampler->sampler_elements[i]->is_empty)
count++;
}
@@ -786,7 +797,7 @@ clear_get_peer_tasks (void *cls, const struct GNUNET_HashCode *key, void *value)
GNUNET_SCHEDULER_cancel (task);
GNUNET_CONTAINER_multihashmap_remove (get_peer_tasks, key, value);
-
+
return GNUNET_YES;
}
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
*/
//struct RPS_Sampler;
+/**
+ * Get the size of the sampler.
+ *
+ * @return the size of the sampler
+ */
+unsigned int
+RPS_sampler_get_size ();
+
/**
* Grow or shrink the size of the sampler.
@@ -80,7 +88,7 @@ RPS_sampler_resize (unsigned int new_size);
*
* @param init_size the size the sampler is initialised with
* @param id with which all newly created sampler elements are initialised
- * @param ins_cb the callback that will be called on every PeerID that is
+ * @param ins_cb the callback that will be called on every PeerID that is
* newly inserted into a sampler element
* @param ins_cls the closure given to #ins_cb
* @param rem_cb the callback that will be called on every PeerID that is