schedule some requests for later
[oweals/gnunet.git] / src / rps / gnunet-service-rps_sampler.h
1 /*
2      This file is part of GNUnet.
3      (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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, 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  * Callback that is called when a new PeerID is inserted into a sampler.
33  *
34  * @param cls the closure given alongside this function.
35  * @param id the PeerID that is inserted
36  */
37 typedef void
38 (*RPS_sampler_insert_cb) (void *cls,
39     const struct GNUNET_PeerIdentity *id);
40
41 /**
42  * Callback that is called when a new PeerID is removed from a sampler.
43  *
44  * @param cls the closure given alongside this function.
45  * @param id the PeerID that is removed
46  */
47 typedef void
48 (*RPS_sampler_remove_cb) (void *cls,
49     const struct GNUNET_PeerIdentity *id);
50
51 /**
52  * Callback that is called from _get_n_rand_peers() when the PeerIDs are ready.
53  *
54  * @param cls the closure given alongside this function.
55  * @param ids the PeerIDs that were returned
56  *        to be freed
57  */
58   typedef void
59 (*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
60     struct GNUNET_PeerIdentity *ids, uint64_t num_peers);
61
62
63 /**
64  * A sampler sampling a stream of PeerIDs.
65  */
66 //struct RPS_Sampler;
67
68
69 /**
70  * Grow or shrink the size of the sampler.
71  *
72  * @param new_size the new size of the sampler
73  */
74   void
75 RPS_sampler_resize (unsigned int new_size);
76
77
78 /**
79  * Initialise a tuple of samplers.
80  *
81  * @param init_size the size the sampler is initialised with
82  * @param id with which all newly created sampler elements are initialised
83  * @param ins_cb the callback that will be called on every PeerID that is 
84  *               newly inserted into a sampler element
85  * @param ins_cls the closure given to #ins_cb
86  * @param rem_cb the callback that will be called on every PeerID that is
87  *               removed from a sampler element
88  * @param rem_cls the closure given to #rem_cb
89  */
90   void
91 RPS_sampler_init (size_t init_size,
92     const struct GNUNET_PeerIdentity *id,
93     struct GNUNET_TIME_Relative max_round_interval,
94     RPS_sampler_insert_cb ins_cb, void *ins_cls,
95     RPS_sampler_remove_cb rem_cb, void *rem_cls);
96
97
98 /**
99  * A fuction to update every sampler in the given list
100  *
101  * @param id the PeerID that is put in the sampler
102  */
103   void
104 RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id);
105
106
107 /**
108  * Reinitialise all previously initialised sampler elements with the given value.
109  *
110  * Used to get rid of a PeerID.
111  *
112  * @param id the id of the samplers to update.
113  */
114   void
115 RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id);
116
117
118 /**
119  * Get n random peers out of the sampled peers.
120  *
121  * We might want to reinitialise this sampler after giving the
122  * corrsponding peer to the client.
123  * Random with or without consumption?
124  * Only used internally
125  */
126   const struct GNUNET_PeerIdentity *
127 RPS_sampler_get_n_rand_peers_ (uint64_t n);
128
129
130 /**
131  * Get n random peers out of the sampled peers.
132  *
133  * We might want to reinitialise this sampler after giving the
134  * corrsponding peer to the client.
135  * Random with or without consumption?
136  *
137  * @param cb callback that will be called once the ids are ready.
138  * @param cls closure given to @a cb
139  * @param num_peers the number of peers requested
140  */
141     void
142 RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
143     void *cls, uint64_t num_peers);
144
145
146 /**
147  * Counts how many Samplers currently hold a given PeerID.
148  *
149  * @param id the PeerID to count.
150  *
151  * @return the number of occurrences of id.
152  */
153   uint64_t
154 RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id);
155
156
157 /**
158  * Cleans the samplers.
159  */
160   void
161 RPS_sampler_destroy ();
162
163 #endif
164 /* end of gnunet-service-rps.c */