X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Frps%2Fgnunet-service-rps_sampler.h;h=83705b013722256f9e49ffe472e01912b10710f1;hb=155b8c7cd322add8dad4924da358688eeb035ec2;hp=41afe8da99552ba6be24f854368c0badec8ce3ce;hpb=42efb9525e1ed4a389b9bbd2c2ef9900e6f7f7a6;p=oweals%2Fgnunet.git diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h index 41afe8da9..83705b013 100644 --- a/src/rps/gnunet-service-rps_sampler.h +++ b/src/rps/gnunet-service-rps_sampler.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) + Copyright (C) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @@ -28,25 +28,12 @@ #define RPS_SAMPLER_H #include -/** - * Callback that is called when a new PeerID is inserted into a sampler. - * - * @param cls the closure given alongside this function. - * @param id the PeerID that is inserted - */ -typedef void -(*RPS_sampler_insert_cb) (void *cls, - const struct GNUNET_PeerIdentity *id); /** - * Callback that is called when a new PeerID is removed from a sampler. - * - * @param cls the closure given alongside this function. - * @param id the PeerID that is removed + * A sampler sampling a stream of PeerIDs. */ -typedef void -(*RPS_sampler_remove_cb) (void *cls, - const struct GNUNET_PeerIdentity *id); +struct RPS_Sampler; + /** * Callback that is called from _get_n_rand_peers() when the PeerIDs are ready. @@ -57,74 +44,76 @@ typedef void */ typedef void (*RPS_sampler_n_rand_peers_ready_cb) (void *cls, - struct GNUNET_PeerIdentity *ids, uint64_t num_peers); + struct GNUNET_PeerIdentity *ids, uint32_t num_peers); /** - * A sampler sampling a stream of PeerIDs. + * Get the size of the sampler. + * + * @param sampler the sampler to return the size of. + * @return the size of the sampler */ -//struct RPS_Sampler; +unsigned int +RPS_sampler_get_size (struct RPS_Sampler *sampler); /** * Grow or shrink the size of the sampler. * - * @param new_size the new size of the sampler + * @param sampler the sampler to resize. + * @param new_size the new size of the sampler (not 0) */ - void -RPS_sampler_resize (unsigned int new_size); +void +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. */ - void +struct RPS_Sampler * RPS_sampler_init (size_t init_size, - const struct GNUNET_PeerIdentity *id, - struct GNUNET_TIME_Relative max_round_interval, - RPS_sampler_insert_cb ins_cb, void *ins_cls, - RPS_sampler_remove_cb rem_cb, void *rem_cls); + 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 * + * @param sampler the sampler to update. * @param id the PeerID that is put in the sampler */ void -RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id); +RPS_sampler_update (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** - * Reinitialise all previously initialised sampler elements with the given value. + * Reinitialise all previously initialised sampler elements with the given + * value. * * Used to get rid of a PeerID. * + * @param sampler the sampler to reinitialise a sampler in. * @param id the id of the samplers to update. */ void -RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id); - - -/** - * Get n random peers out of the sampled peers. - * - * We might want to reinitialise this sampler after giving the - * corrsponding peer to the client. - * Random with or without consumption? - * Only used internally - */ - const struct GNUNET_PeerIdentity * -RPS_sampler_get_n_rand_peers_ (uint64_t n); +RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** @@ -134,31 +123,39 @@ RPS_sampler_get_n_rand_peers_ (uint64_t n); * corrsponding peer to the client. * Random with or without consumption? * + * @param sampler the sampler to get peers from. * @param cb callback that will be called once the ids are ready. * @param cls closure given to @a cb + * @param for_client #GNUNET_YES if result is used for client, + * #GNUNET_NO if used internally * @param num_peers the number of peers requested */ void -RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb, - void *cls, uint64_t num_peers); +RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, + RPS_sampler_n_rand_peers_ready_cb cb, + void *cls, uint32_t num_peers); /** * Counts how many Samplers currently hold a given PeerID. * + * @param sampler the sampler to cound ids in. * @param id the PeerID to count. * * @return the number of occurrences of id. */ - uint64_t -RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id); + uint32_t +RPS_sampler_count_id (struct RPS_Sampler *sampler, + const struct GNUNET_PeerIdentity *id); /** * Cleans the samplers. + * + * @param sampler the sampler to destroy. */ void -RPS_sampler_destroy (); +RPS_sampler_destroy (struct RPS_Sampler *sampler); #endif /* end of gnunet-service-rps.c */