- compiler warning
[oweals/gnunet.git] / src / rps / gnunet-service-rps_sampler.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C)
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file rps/gnunet-service-rps_sampler.h
23  * @brief sampler implementation
24  * @author Julius Bünger
25  */
26
27 #ifndef RPS_SAMPLER_H
28 #define RPS_SAMPLER_H
29 #include <inttypes.h>
30
31
32 /**
33  * A sampler sampling a stream of PeerIDs.
34  */
35 struct RPS_Sampler;
36
37 /**
38  * A handle to cancel a request.
39  */
40 struct RPS_SamplerRequestHandle;
41
42
43 /**
44  * Callback that is called from _get_n_rand_peers() when the PeerIDs are ready.
45  *
46  * @param cls the closure given alongside this function.
47  * @param ids the PeerIDs that were returned
48  *        to be freed
49  */
50   typedef void
51 (*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
52     struct GNUNET_PeerIdentity *ids, uint32_t num_peers);
53
54
55 /**
56  * Get the size of the sampler.
57  *
58  * @param sampler the sampler to return the size of.
59  * @return the size of the sampler
60  */
61 unsigned int
62 RPS_sampler_get_size (struct RPS_Sampler *sampler);
63
64
65 /**
66  * Grow or shrink the size of the sampler.
67  *
68  * @param sampler the sampler to resize.
69  * @param new_size the new size of the sampler (not 0)
70  */
71 void
72 RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
73
74
75 /**
76  * Initialise a tuple of samplers.
77  *
78  * @param init_size the size the sampler is initialised with
79  * @param max_round_interval maximum time a round takes
80  * @return a handle to a sampler that consists of sampler elements.
81  */
82 struct RPS_Sampler *
83 RPS_sampler_init (size_t init_size,
84     struct GNUNET_TIME_Relative max_round_interval);
85
86
87 /**
88  * Initialise a modified tuple of sampler elements.
89  *
90  * @param init_size the size the sampler is initialised with
91  * @param max_round_interval maximum time a round takes
92  * @return a handle to a sampler that consists of sampler elements.
93  */
94 struct RPS_Sampler *
95 RPS_sampler_mod_init (size_t init_size,
96                       struct GNUNET_TIME_Relative max_round_interval);
97
98
99 /**
100  * A fuction to update every sampler in the given list
101  *
102  * @param sampler the sampler to update.
103  * @param id the PeerID that is put in the sampler
104  */
105   void
106 RPS_sampler_update (struct RPS_Sampler *sampler,
107                     const struct GNUNET_PeerIdentity *id);
108
109
110 /**
111  * Reinitialise all previously initialised sampler elements with the given
112  * value.
113  *
114  * Used to get rid of a PeerID.
115  *
116  * @param sampler the sampler to reinitialise a sampler in.
117  * @param id the id of the samplers to update.
118  */
119   void
120 RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
121                                    const struct GNUNET_PeerIdentity *id);
122
123
124 /**
125  * Get n random peers out of the sampled peers.
126  *
127  * We might want to reinitialise this sampler after giving the
128  * corrsponding peer to the client.
129  * Random with or without consumption?
130  *
131  * @param sampler the sampler to get peers from.
132  * @param cb callback that will be called once the ids are ready.
133  * @param cls closure given to @a cb
134  * @param for_client #GNUNET_YES if result is used for client,
135  *                   #GNUNET_NO if used internally
136  * @param num_peers the number of peers requested
137  */
138 struct RPS_SamplerRequestHandle *
139 RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
140                               RPS_sampler_n_rand_peers_ready_cb cb,
141                               void *cls, uint32_t num_peers);
142
143 /**
144  * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb.
145  *
146  * @param req_handle the handle to the request
147  */
148 void
149 RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
150
151
152 /**
153  * Counts how many Samplers currently hold a given PeerID.
154  *
155  * @param sampler the sampler to cound ids in.
156  * @param id the PeerID to count.
157  *
158  * @return the number of occurrences of id.
159  */
160   uint32_t
161 RPS_sampler_count_id (struct RPS_Sampler *sampler,
162                       const struct GNUNET_PeerIdentity *id);
163
164
165 /**
166  * Cleans the samplers.
167  *
168  * @param sampler the sampler to destroy.
169  */
170   void
171 RPS_sampler_destroy (struct RPS_Sampler *sampler);
172
173 #endif
174 /* end of gnunet-service-rps.c */