aboutsummaryrefslogtreecommitdiff
path: root/src/rps/rps-sampler_client.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/rps-sampler_client.h')
-rw-r--r--src/rps/rps-sampler_client.h150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/rps/rps-sampler_client.h b/src/rps/rps-sampler_client.h
new file mode 100644
index 000000000..fd0538efa
--- /dev/null
+++ b/src/rps/rps-sampler_client.h
@@ -0,0 +1,150 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C)
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @file rps/rps-sampler_client.h
21 * @brief client sampler implementation
22 * @author Julius Bünger
23 */
24
25#ifndef RPS_SAMPLER_CLIENT_H
26#define RPS_SAMPLER_CLIENT_H
27#include <inttypes.h>
28#include "rps-sampler_common.h"
29
30
31/**
32 * A sampler sampling a stream of PeerIDs.
33 */
34struct RPS_Sampler;
35
36/**
37 * A handle to cancel a request.
38 */
39struct RPS_SamplerRequestHandle;
40
41
42/**
43 * Get the size of the sampler.
44 *
45 * @param sampler the sampler to return the size of.
46 * @return the size of the sampler
47 */
48unsigned int
49RPS_sampler_get_size (struct RPS_Sampler *sampler);
50
51
52/**
53 * Grow or shrink the size of the sampler.
54 *
55 * @param sampler the sampler to resize.
56 * @param new_size the new size of the sampler (not 0)
57 */
58void
59RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
60
61
62/**
63 * Initialise a modified tuple of sampler elements.
64 *
65 * @param init_size the size the sampler is initialised with
66 * @param max_round_interval maximum time a round takes
67 * @return a handle to a sampler that consists of sampler elements.
68 */
69struct RPS_Sampler *
70RPS_sampler_mod_init (size_t init_size,
71 struct GNUNET_TIME_Relative max_round_interval);
72
73
74/**
75 * Update every sampler element of this sampler with given peer
76 *
77 * @param sampler the sampler to update.
78 * @param id the PeerID that is put in the sampler
79 */
80 void
81RPS_sampler_update (struct RPS_Sampler *sampler,
82 const struct GNUNET_PeerIdentity *id);
83
84
85/**
86 * Reinitialise all previously initialised sampler elements with the given
87 * value.
88 *
89 * Used to get rid of a PeerID.
90 *
91 * @param sampler the sampler to reinitialise a sampler in.
92 * @param id the id of the samplers to update.
93 */
94 void
95RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
96 const struct GNUNET_PeerIdentity *id);
97
98
99/**
100 * Get n random peers out of the sampled peers.
101 *
102 * We might want to reinitialise this sampler after giving the
103 * corrsponding peer to the client.
104 * Random with or without consumption?
105 *
106 * @param sampler the sampler to get peers from.
107 * @param cb callback that will be called once the ids are ready.
108 * @param cls closure given to @a cb
109 * @param for_client #GNUNET_YES if result is used for client,
110 * #GNUNET_NO if used internally
111 * @param num_peers the number of peers requested
112 */
113struct RPS_SamplerRequestHandle *
114RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
115 uint32_t num_peers,
116 RPS_sampler_n_rand_peers_ready_cb cb,
117 void *cls);
118
119/**
120 * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb.
121 *
122 * @param req_handle the handle to the request
123 */
124void
125RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
126
127
128/**
129 * Counts how many Samplers currently hold a given PeerID.
130 *
131 * @param sampler the sampler to cound ids in.
132 * @param id the PeerID to count.
133 *
134 * @return the number of occurrences of id.
135 */
136 uint32_t
137RPS_sampler_count_id (struct RPS_Sampler *sampler,
138 const struct GNUNET_PeerIdentity *id);
139
140
141/**
142 * Cleans the samplers.
143 *
144 * @param sampler the sampler to destroy.
145 */
146 void
147RPS_sampler_destroy (struct RPS_Sampler *sampler);
148
149#endif /* RPS_SAMPLER_CLIENT_H */
150/* end of gnunet-service-rps.c */