2 This file is part of GNUnet.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file rps/gnunet-service-rps_sampler.h
23 * @brief sampler implementation
24 * @author Julius Bünger
33 * A sampler sampling a stream of PeerIDs.
39 * Callback that is called from _get_n_rand_peers() when the PeerIDs are ready.
41 * @param cls the closure given alongside this function.
42 * @param ids the PeerIDs that were returned
46 (*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
47 struct GNUNET_PeerIdentity *ids, uint32_t num_peers);
51 * Get the size of the sampler.
53 * @param sampler the sampler to return the size of.
54 * @return the size of the sampler
57 RPS_sampler_get_size (struct RPS_Sampler *sampler);
61 * Grow or shrink the size of the sampler.
63 * @param sampler the sampler to resize.
64 * @param new_size the new size of the sampler (not 0)
67 RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
71 * Initialise a tuple of samplers.
73 * @param init_size the size the sampler is initialised with
74 * @param id with which all newly created sampler elements are initialised
75 * @param ins_cb the callback that will be called on every PeerID that is
76 * newly inserted into a sampler element
77 * @param ins_cls the closure given to #ins_cb
78 * @param rem_cb the callback that will be called on every PeerID that is
79 * removed from a sampler element
80 * @param rem_cls the closure given to #rem_cb
81 * @return a handle to a sampler that consists of sampler elements.
84 RPS_sampler_init (size_t init_size,
85 struct GNUNET_TIME_Relative max_round_interval);
89 * A fuction to update every sampler in the given list
91 * @param sampler the sampler to update.
92 * @param id the PeerID that is put in the sampler
95 RPS_sampler_update (struct RPS_Sampler *sampler,
96 const struct GNUNET_PeerIdentity *id);
100 * Reinitialise all previously initialised sampler elements with the given
103 * Used to get rid of a PeerID.
105 * @param sampler the sampler to reinitialise a sampler in.
106 * @param id the id of the samplers to update.
109 RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
110 const struct GNUNET_PeerIdentity *id);
114 * Get n random peers out of the sampled peers.
116 * We might want to reinitialise this sampler after giving the
117 * corrsponding peer to the client.
118 * Random with or without consumption?
120 * @param sampler the sampler to get peers from.
121 * @param cb callback that will be called once the ids are ready.
122 * @param cls closure given to @a cb
123 * @param for_client #GNUNET_YES if result is used for client,
124 * #GNUNET_NO if used internally
125 * @param num_peers the number of peers requested
128 RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
129 RPS_sampler_n_rand_peers_ready_cb cb,
130 void *cls, uint32_t num_peers, int for_client);
134 * Counts how many Samplers currently hold a given PeerID.
136 * @param sampler the sampler to cound ids in.
137 * @param id the PeerID to count.
139 * @return the number of occurrences of id.
142 RPS_sampler_count_id (struct RPS_Sampler *sampler,
143 const struct GNUNET_PeerIdentity *id);
147 * Cleans the samplers.
149 * @param sampler the sampler to destroy.
152 RPS_sampler_destroy (struct RPS_Sampler *sampler);
155 /* end of gnunet-service-rps.c */