summaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_sampler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r--src/rps/gnunet-service-rps_sampler.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index a3f778979..7573fd4eb 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -37,7 +37,7 @@
#include "rps-test_util.h"
-#define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "rps-sampler", __VA_ARGS__)
// multiple 'clients'?
@@ -68,7 +68,8 @@ typedef void
*
* Meant to be an entry in an DLL.
*/
-struct SamplerNotifyUpdateCTX {
+struct SamplerNotifyUpdateCTX
+{
/**
* @brief The Callback to call on updates
*/
@@ -106,13 +107,14 @@ typedef void
* Only used internally
*/
static void
-sampler_get_rand_peer(void *cls);
+sampler_get_rand_peer (void *cls);
/**
* Closure to _get_n_rand_peers_ready_cb()
*/
-struct RPS_SamplerRequestHandle {
+struct RPS_SamplerRequestHandle
+{
/**
* DLL
*/
@@ -159,7 +161,7 @@ struct RPS_SamplerRequestHandle {
///**
// * Global sampler variable.
// */
-//struct RPS_Sampler *sampler;
+// struct RPS_Sampler *sampler;
/**
@@ -175,7 +177,7 @@ static size_t max_size;
/**
* The size the extended sampler elements currently have.
*/
-//static size_t extra_size;
+// static size_t extra_size;
/**
* Inedex to the sampler element that is the next to be returned
@@ -191,8 +193,8 @@ static uint32_t client_get_index;
* @return a handle to a sampler that consists of sampler elements.
*/
struct RPS_Sampler *
-RPS_sampler_init(size_t init_size,
- struct GNUNET_TIME_Relative max_round_interval)
+RPS_sampler_init (size_t init_size,
+ struct GNUNET_TIME_Relative max_round_interval)
{
struct RPS_Sampler *sampler;
@@ -200,17 +202,17 @@ RPS_sampler_init(size_t init_size,
min_size = 10; // TODO make input to _samplers_init()
max_size = 1000; // TODO make input to _samplers_init()
- sampler = GNUNET_new(struct RPS_Sampler);
+ sampler = GNUNET_new (struct RPS_Sampler);
sampler->max_round_interval = max_round_interval;
sampler->get_peers = sampler_get_rand_peer;
- //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
- //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
- RPS_sampler_resize(sampler, init_size);
+ // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
+ // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
+ RPS_sampler_resize (sampler, init_size);
client_get_index = 0;
- //GNUNET_assert (init_size == sampler->sampler_size);
+ // GNUNET_assert (init_size == sampler->sampler_size);
return sampler;
}
@@ -222,7 +224,7 @@ RPS_sampler_init(size_t init_size,
* Only used internally
*/
static void
-sampler_get_rand_peer(void *cls)
+sampler_get_rand_peer (void *cls)
{
struct GetPeerCls *gpc = cls;
uint32_t r_index;
@@ -236,28 +238,29 @@ sampler_get_rand_peer(void *cls)
* Choose the r_index of the peer we want to return
* at random from the interval of the gossip list
*/
- r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG,
- sampler->sampler_size);
+ r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
+ sampler->sampler_size);
if (EMPTY == sampler->sampler_elements[r_index]->is_empty)
- {
- //LOG (GNUNET_ERROR_TYPE_DEBUG,
- // "Not returning randomly selected, empty PeerID. - Rescheduling.\n");
-
- gpc->notify_ctx =
- sampler_notify_on_update(sampler,
- &sampler_get_rand_peer,
- gpc);
- return;
- }
-
- GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head,
- gpc->req_handle->gpc_tail,
- gpc);
+ {
+ // LOG (GNUNET_ERROR_TYPE_DEBUG,
+ // "Not returning randomly selected, empty PeerID. - Rescheduling.\n");
+
+ gpc->notify_ctx =
+ sampler_notify_on_update (sampler,
+ &sampler_get_rand_peer,
+ gpc);
+ return;
+ }
+
+ GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head,
+ gpc->req_handle->gpc_tail,
+ gpc);
*gpc->id = sampler->sampler_elements[r_index]->peer_id;
- gpc->cont(gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers);
+ gpc->cont (gpc->cont_cls, gpc->id, 0,
+ sampler->sampler_elements[r_index]->num_peers);
- GNUNET_free(gpc);
+ GNUNET_free (gpc);
}