From 2f61fb7ffc7232c69e66a13c956892d6f6d13081 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Sat, 23 May 2015 23:34:23 +0000 Subject: -better splitted brahms sampler and modified one --- src/rps/gnunet-service-rps.c | 14 ++--- src/rps/gnunet-service-rps_sampler.c | 109 +++++++++++++++++++++++------------ src/rps/gnunet-service-rps_sampler.h | 22 ++++--- 3 files changed, 92 insertions(+), 53 deletions(-) (limited to 'src/rps') diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index b8bfe8f9e..c77e8eddf 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -1281,8 +1281,8 @@ void client_respond (void *cls, */ static void handle_client_request (void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { struct GNUNET_RPS_CS_RequestMessage *msg; uint32_t num_peers; @@ -1316,8 +1316,7 @@ handle_client_request (void *cls, RPS_sampler_get_n_rand_peers (client_sampler, client_respond, reply_cls, - num_peers, - GNUNET_YES); + num_peers); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -2069,8 +2068,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) RPS_sampler_get_n_rand_peers (prot_sampler, hist_update, NULL, - 1, - GNUNET_NO); + 1); num_hist_update_tasks++; // TODO change the peer_flags accordingly } @@ -2551,8 +2549,8 @@ run (void *cls, half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5); max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval); - prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); - client_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); + prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); + client_sampler = RPS_sampler_mod_init (sampler_size_est_need, max_round_interval); /* 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 5ea728628..a0624c942 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c @@ -111,6 +111,35 @@ struct RPS_SamplerElement #endif /* TO_FILE */ }; +/** + * Type of function used to differentiate between modified and not modified + * Sampler. + */ +typedef void +(*RPS_get_peers_type) (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc); + +/** + * Get one random peer out of the sampled peers. + * + * We might want to reinitialise this sampler after giving the + * corrsponding peer to the client. + * Only used internally + */ +static void +sampler_get_rand_peer2 (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc); + +/** + * Get one random peer out of the sampled peers. + * + * We might want to reinitialise this sampler after giving the + * corrsponding peer to the client. + */ +static void +sampler_get_rand_peer (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc); + /** * Sampler with its own array of SamplerElements @@ -129,12 +158,18 @@ struct RPS_Sampler struct RPS_SamplerElement **sampler_elements; /** - * Max time a round takes + * Maximum time a round takes * * Used in the context of RPS */ struct GNUNET_TIME_Relative max_round_interval; + /** + * Stores the function to return peers. Which one it is depends on whether + * the Sampler is the modified one or not. + */ + RPS_get_peers_type get_peers; + #ifdef TO_FILE /** * File name to log to @@ -182,7 +217,7 @@ struct NRandPeersReadyCls */ typedef void (*RPS_sampler_rand_peer_ready_cont) (void *cls, - const struct GNUNET_PeerIdentity *id); + const struct GNUNET_PeerIdentity *id); /** * Closure for #sampler_get_rand_peer() @@ -634,12 +669,7 @@ sampler_empty (struct RPS_Sampler *sampler) * 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 - * 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 - * removed from a sampler element - * @param rem_cls the closure given to #rem_cb + * @param max_round_interval maximum time a round takes * @return a handle to a sampler that consists of sampler elements. */ struct RPS_Sampler * @@ -647,7 +677,6 @@ RPS_sampler_init (size_t init_size, struct GNUNET_TIME_Relative max_round_interval) { struct RPS_Sampler *sampler; - //uint32_t i; /* Initialise context around extended sampler */ min_size = 10; // TODO make input to _samplers_init() @@ -667,6 +696,7 @@ RPS_sampler_init (size_t init_size, sampler->sampler_size = 0; sampler->sampler_elements = NULL; 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); @@ -677,6 +707,33 @@ RPS_sampler_init (size_t init_size, return sampler; } +/** + * Initialise a modified tuple of sampler elements. + * + * @param init_size the size the sampler is initialised with + * @param max_round_interval maximum time a round takes + * @return a handle to a sampler that consists of sampler elements. + */ +struct RPS_Sampler * +RPS_sampler_mod_init (size_t init_size, + struct GNUNET_TIME_Relative max_round_interval) +{ + struct RPS_Sampler *sampler; + + sampler = RPS_sampler_init (init_size, max_round_interval); + sampler->get_peers = sampler_get_rand_peer2; + + #ifdef TO_FILE + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Initialised modified sampler %s\n", + sampler->file_name); + to_file (sampler->file_name, + "This is a modified sampler"); + #endif /* TO_FILE */ + + return sampler; +} + /** * A fuction to update every sampler in the given list @@ -738,7 +795,8 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, * Only used internally */ static void -sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +sampler_get_rand_peer2 (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GetPeerCls *gpc = cls; uint32_t r_index; @@ -779,7 +837,8 @@ sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc * corrsponding peer to the client. */ static void -sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +sampler_get_rand_peer (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GetPeerCls *gpc = cls; struct GNUNET_PeerIdentity tmp_id; @@ -893,7 +952,7 @@ sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) void RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, RPS_sampler_n_rand_peers_ready_cb cb, - void *cls, uint32_t num_peers, int for_client) + void *cls, uint32_t num_peers) { GNUNET_assert (0 != sampler->sampler_size); @@ -909,25 +968,6 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, cb_cls->callback = cb; cb_cls->cls = cls; - #ifdef TO_FILE - if (GNUNET_NO == for_client) - { - to_file (sampler->file_name, - "This sampler is probably for Brahms itself"); - } - else if (GNUNET_YES == for_client) - { - to_file (sampler->file_name, - "This sampler is probably for the client"); - } - else - { - to_file (sampler->file_name, - "This shouldn't happen: for_client is %i", - for_client); - } - #endif /* TO_FILE */ - LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling requests for %" PRIu32 " peers\n", num_peers); @@ -940,12 +980,7 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, gpc->id = &cb_cls->ids[i]; // maybe add a little delay - if (GNUNET_YES == for_client) - gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&sampler_get_rand_peer, gpc); - else if (GNUNET_NO == for_client) - gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&sampler_get_rand_peer2, gpc); - else - GNUNET_assert (0); + gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, gpc); GNUNET_CONTAINER_DLL_insert (gpc_head, gpc_tail, gpc); } diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h index 708de6980..3b4584d87 100644 --- a/src/rps/gnunet-service-rps_sampler.h +++ b/src/rps/gnunet-service-rps_sampler.h @@ -71,13 +71,7 @@ RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); * Initialise a tuple of samplers. * * @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 - * 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 - * removed from a sampler element - * @param rem_cls the closure given to #rem_cb + * @param max_round_interval maximum time a round takes * @return a handle to a sampler that consists of sampler elements. */ struct RPS_Sampler * @@ -85,6 +79,18 @@ RPS_sampler_init (size_t init_size, struct GNUNET_TIME_Relative max_round_interval); +/** + * Initialise a modified tuple of sampler elements. + * + * @param init_size the size the sampler is initialised with + * @param max_round_interval maximum time a round takes + * @return a handle to a sampler that consists of sampler elements. + */ +struct RPS_Sampler * +RPS_sampler_mod_init (size_t init_size, + struct GNUNET_TIME_Relative max_round_interval); + + /** * A fuction to update every sampler in the given list * @@ -127,7 +133,7 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, void RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, RPS_sampler_n_rand_peers_ready_cb cb, - void *cls, uint32_t num_peers, int for_client); + void *cls, uint32_t num_peers); /** -- cgit v1.2.3