fix enable_malicous check
[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  * Connect to the rps service
71  *
72  * @param cfg configuration to use
73  * @return handle to the rps service
74  */
75   struct GNUNET_RPS_Handle *
76 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
77
78
79 /**
80  * @brief Start a sub with the given shared value
81  *
82  * @param h Handle to rps
83  * @param shared_value The shared value that defines the members of the sub (-gorup)
84  */
85 void
86 GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h,
87                       const char *shared_value);
88
89
90 /**
91  * @brief Stop a sub with the given shared value
92  *
93  * @param h Handle to rps
94  * @param shared_value The shared value that defines the members of the sub (-gorup)
95  */
96 void
97 GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h,
98                      const char *shared_value);
99
100
101 /**
102  * Request n random peers.
103  *
104  * This does exacly the same as GNUNET_RPS_request_peers_single_call
105  * but needs a GNUNET_RPS_Handle.
106  * This exists only for other parts of GNUnet that expect having to
107  * (dis)connect from/to a service.
108  *
109  * @param h handle to the rps service
110  * @param n number of random peers to return
111  * @param ready_cb the callback to be called when the peers are available
112  * @param cls a closure that will be given to the callback
113  * @return handle to this request
114  */
115   struct GNUNET_RPS_Request_Handle *
116 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
117                           GNUNET_RPS_NotifyReadyCB ready_cb,
118                           void *cls);
119
120 /**
121  * Seed rps service with peerIDs.
122  *
123  * @param h handle to the rps service
124  * @param n number of peers to seed
125  * @param ids the ids of the peers seeded
126  */
127   void
128 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
129                      const struct GNUNET_PeerIdentity * ids);
130
131 /**
132  * Cancle an issued request.
133  *
134  * @param rh handle of the pending request to be canceled
135  */
136   void
137 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
138
139
140 #if ENABLE_MALICIOUS
141 /**
142  * Turn RPS service to act malicious.
143  *
144  * @param h handle to the rps service
145  * @param type which type of malicious peer to turn to.
146  *             0 Don't act malicious at all
147  *             1 Try to maximise representation
148  *             2 Try to partition the network
149  *               (isolate one peer from the rest)
150  * @param n number of @a ids
151  * @param ids the ids of the malicious peers
152  *            if @type is 2 the last id is the id of the
153  *            peer to be isolated from the rest
154  */
155   void
156 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
157                           uint32_t type,
158                           uint32_t num_peers,
159                           const struct GNUNET_PeerIdentity *ids,
160                           const struct GNUNET_PeerIdentity *target_peer);
161 #endif /* ENABLE_MALICIOUS */
162
163 /* Get internals for debugging/profiling purposes */
164
165 /**
166  * Request updates of view
167  *
168  * @param rps_handle handle to the rps service
169  * @param num_req_peers number of peers we want to receive
170  *        (0 for infinite updates)
171  * @param cls a closure that will be given to the callback
172  * @param ready_cb the callback called when the peers are available
173  */
174 void
175 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
176                          uint32_t num_updates,
177                          GNUNET_RPS_NotifyReadyCB view_update_cb,
178                          void *cls);
179
180
181 /**
182  * Request biased stream of peers that are being put into the sampler
183  *
184  * @param rps_handle handle to the rps service
185  * @param cls a closure that will be given to the callback
186  * @param ready_cb the callback called when the peers are available
187  */
188 struct GNUNET_RPS_StreamRequestHandle *
189 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
190                            GNUNET_RPS_NotifyReadyCB stream_input_cb,
191                            void *cls);
192
193
194 /**
195  * @brief Cancel a specific request for updates from the biased peer stream
196  *
197  * @param srh The request handle to cancel
198  */
199 void
200 GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh);
201
202
203 /**
204  * Disconnect from the rps service
205  *
206  * @param h the handle to the rps service
207  */
208   void
209 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
210
211
212 #if 0                           /* keep Emacsens' auto-indent happy */
213 {
214 #endif
215 #ifdef __cplusplus
216 }
217 #endif
218
219 #endif
220
221 /** @} */  /* end of group */