aboutsummaryrefslogtreecommitdiff
path: root/src/contrib/service/rps/rps-sampler_client.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/service/rps/rps-sampler_client.h')
-rw-r--r--src/contrib/service/rps/rps-sampler_client.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/src/contrib/service/rps/rps-sampler_client.h b/src/contrib/service/rps/rps-sampler_client.h
new file mode 100644
index 000000000..7a674371d
--- /dev/null
+++ b/src/contrib/service/rps/rps-sampler_client.h
@@ -0,0 +1,156 @@
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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file rps/rps-sampler_client.h
23 * @brief client sampler implementation
24 * @author Julius Bünger
25 */
26
27#ifndef RPS_SAMPLER_CLIENT_H
28#define RPS_SAMPLER_CLIENT_H
29#include <inttypes.h>
30#include "rps-sampler_common.h"
31
32
33/**
34 * A sampler sampling a stream of PeerIDs.
35 */
36struct RPS_Sampler;
37
38/**
39 * A handle to cancel a request.
40 */
41struct RPS_SamplerRequestHandle;
42
43/**
44 * Closure to _get_rand_peer_info()
45 */
46struct RPS_SamplerRequestHandleSingleInfo;
47
48
49/**
50 * Get the size of the sampler.
51 *
52 * @param sampler the sampler to return the size of.
53 * @return the size of the sampler
54 */
55unsigned int
56RPS_sampler_get_size (struct RPS_Sampler *sampler);
57
58
59/**
60 * Grow or shrink the size of the sampler.
61 *
62 * @param sampler the sampler to resize.
63 * @param new_size the new size of the sampler (not 0)
64 */
65void
66RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
67
68
69/**
70 * Initialise a modified tuple of sampler elements.
71 *
72 * @param init_size the size the sampler is initialised with
73 * @param max_round_interval maximum time a round takes
74 * @return a handle to a sampler that consists of sampler elements.
75 */
76struct RPS_Sampler *
77RPS_sampler_mod_init (size_t init_size,
78 struct GNUNET_TIME_Relative max_round_interval);
79
80
81/**
82 * Update every sampler element of this sampler with given peer
83 *
84 * @param sampler the sampler to update.
85 * @param id the PeerID that is put in the sampler
86 */
87void
88RPS_sampler_update (struct RPS_Sampler *sampler,
89 const struct GNUNET_PeerIdentity *id);
90
91
92/**
93 * Reinitialise all previously initialised sampler elements with the given
94 * value.
95 *
96 * Used to get rid of a PeerID.
97 *
98 * @param sampler the sampler to reinitialise a sampler in.
99 * @param id the id of the samplers to update.
100 */
101void
102RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
103 const struct GNUNET_PeerIdentity *id);
104
105
106/**
107 * Get n random peers out of the sampled peers.
108 *
109 * We might want to reinitialise this sampler after giving the
110 * corrsponding peer to the client.
111 * Random with or without consumption?
112 *
113 * @param sampler the sampler to get peers from.
114 * @param cb callback that will be called once the ids are ready.
115 * @param cls closure given to @a cb
116 * @param num_peers the number of peers requested
117 */
118struct RPS_SamplerRequestHandle *
119RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
120 uint32_t num_peers,
121 RPS_sampler_n_rand_peers_ready_cb cb,
122 void *cls);
123
124
125/**
126 * Cancel a request issued through #RPS_sampler_n_rand_peers_ready_cb.
127 *
128 * @param req_handle the handle to the request
129 */
130void
131RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
132
133
134/**
135 * Counts how many Samplers currently hold a given PeerID.
136 *
137 * @param sampler the sampler to count ids in.
138 * @param id the PeerID to count.
139 *
140 * @return the number of occurrences of id.
141 */
142uint32_t
143RPS_sampler_count_id (struct RPS_Sampler *sampler,
144 const struct GNUNET_PeerIdentity *id);
145
146
147/**
148 * Cleans the samplers.
149 *
150 * @param sampler the sampler to destroy.
151 */
152void
153RPS_sampler_destroy (struct RPS_Sampler *sampler);
154
155#endif /* RPS_SAMPLER_CLIENT_H */
156/* end of gnunet-service-rps.c */