RECLAIM/OIDC: code cleanup
[oweals/gnunet.git] / src / include / gnunet_rps_service.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 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  * @author Julius Bünger
23  *
24  * @file
25  * API to the rps service
26  *
27  * @defgroup rps  RPS service
28  * Random Peer Sampling
29  * @{
30  */
31 #ifndef GNUNET_RPS_SERVICE_H
32 #define GNUNET_RPS_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 /**
43  * Version of the rps API.
44  */
45 #define GNUNET_RPS_VERSION 0x00000000
46
47 /**
48  * Handle for the random peer sampling service
49  */
50 struct GNUNET_RPS_Handle;
51
52 /**
53  * Handle for one request to the rps service
54  */
55 struct GNUNET_RPS_Request_Handle;
56
57 /**
58  * Callback called when requested random peers are available.
59  *
60  * @param cls the closure given with the request
61  * @param num_peers the number of peers returned
62  * @param peers array with num_peers PeerIDs
63  */
64 typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
65     uint64_t num_peers,
66     const struct GNUNET_PeerIdentity *peers);
67
68
69 /**
70  * Callback called when requested random peer with additional information is
71  * available.
72  *
73  * @param cls the closure given with the request
74  * @param peer The Peer ID
75  * @param probability The probability with which all elements have been observed
76  * @param num_observed Number of IDs this sampler has observed
77  */
78 typedef void (* GNUNET_RPS_NotifyReadySingleInfoCB) (void *cls,
79     const struct GNUNET_PeerIdentity *peer,
80     double probability,
81     uint32_t num_observed);
82
83
84 /**
85  * Connect to the rps service
86  *
87  * @param cfg configuration to use
88  * @return handle to the rps service
89  */
90 struct GNUNET_RPS_Handle *
91 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
92
93
94 /**
95  * @brief Start a sub with the given shared value
96  *
97  * @param h Handle to rps
98  * @param shared_value The shared value that defines the members of the sub (-group)
99  */
100 void
101 GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h,
102                       const char *shared_value);
103
104
105 /**
106  * @brief Stop a sub with the given shared value
107  *
108  * @param h Handle to rps
109  * @param shared_value The shared value that defines the members of the sub (-group)
110  */
111 void
112 GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h,
113                      const char *shared_value);
114
115
116 /**
117  * Request n random peers.
118  *
119  * This does exacly the same as GNUNET_RPS_request_peers_single_call
120  * but needs a GNUNET_RPS_Handle.
121  * This exists only for other parts of GNUnet that expect having to
122  * (dis)connect from/to a service.
123  *
124  * @param h handle to the rps service
125  * @param n number of random peers to return
126  * @param ready_cb the callback to be called when the peers are available
127  * @param cls a closure that will be given to the callback
128  * @return handle to this request
129  */
130 struct GNUNET_RPS_Request_Handle *
131 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
132                           GNUNET_RPS_NotifyReadyCB ready_cb,
133                           void *cls);
134
135
136 /**
137  * Request one random peer, getting additional information.
138  *
139  * @param rps_handle handle to the rps service
140  * @param ready_cb the callback called when the peers are available
141  * @param cls closure given to the callback
142  * @return a handle to cancel this request
143  */
144 struct GNUNET_RPS_Request_Handle_Single_Info *
145 GNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle,
146                               GNUNET_RPS_NotifyReadySingleInfoCB ready_cb,
147                               void *cls);
148
149
150 /**
151  * Seed rps service with peerIDs.
152  *
153  * @param h handle to the rps service
154  * @param n number of peers to seed
155  * @param ids the ids of the peers seeded
156  */
157 void
158 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
159                      const struct GNUNET_PeerIdentity * ids);
160
161 /**
162  * Cancle an issued request.
163  *
164  * @param rh handle of the pending request to be canceled
165  */
166 void
167 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
168
169
170 /**
171  * Cancle an issued single info request.
172  *
173  * @param rhs request handle of request to cancle
174  */
175 void
176 GNUNET_RPS_request_single_info_cancel (
177     struct GNUNET_RPS_Request_Handle_Single_Info *rhs);
178
179
180 #if ENABLE_MALICIOUS
181 /**
182  * Turn RPS service to act malicious.
183  *
184  * @param h handle to the rps service
185  * @param type which type of malicious peer to turn to.
186  *             0 Don't act malicious at all
187  *             1 Try to maximise representation
188  *             2 Try to partition the network
189  *               (isolate one peer from the rest)
190  * @param n number of @a ids
191  * @param ids the ids of the malicious peers
192  *            if @type is 2 the last id is the id of the
193  *            peer to be isolated from the rest
194  */
195   void
196 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
197                           uint32_t type,
198                           uint32_t num_peers,
199                           const struct GNUNET_PeerIdentity *ids,
200                           const struct GNUNET_PeerIdentity *target_peer);
201 #endif /* ENABLE_MALICIOUS */
202
203 /* Get internals for debugging/profiling purposes */
204
205 /**
206  * Request updates of view
207  *
208  * @param rps_handle handle to the rps service
209  * @param num_req_peers number of peers we want to receive
210  *        (0 for infinite updates)
211  * @param cls a closure that will be given to the callback
212  * @param ready_cb the callback called when the peers are available
213  */
214 void
215 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
216                          uint32_t num_updates,
217                          GNUNET_RPS_NotifyReadyCB view_update_cb,
218                          void *cls);
219
220
221 /**
222  * Request biased stream of peers that are being put into the sampler
223  *
224  * @param rps_handle handle to the rps service
225  * @param cls a closure that will be given to the callback
226  * @param ready_cb the callback called when the peers are available
227  */
228 struct GNUNET_RPS_StreamRequestHandle *
229 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
230                            GNUNET_RPS_NotifyReadyCB stream_input_cb,
231                            void *cls);
232
233
234 /**
235  * @brief Cancel a specific request for updates from the biased peer stream
236  *
237  * @param srh The request handle to cancel
238  */
239 void
240 GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh);
241
242
243 /**
244  * Disconnect from the rps service
245  *
246  * @param h the handle to the rps service
247  */
248   void
249 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
250
251
252 #if 0                           /* keep Emacsens' auto-indent happy */
253 {
254 #endif
255 #ifdef __cplusplus
256 }
257 #endif
258
259 #endif
260
261 /** @} */  /* end of group */