2 This file is part of GNUnet
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.
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.
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/>.
20 * @author Julius Bünger
23 * API to the rps service
25 * @defgroup rps RPS service
26 * Random Peer Sampling
29 #ifndef GNUNET_RPS_SERVICE_H
30 #define GNUNET_RPS_SERVICE_H
35 #if 0 /* keep Emacsens' auto-indent happy */
41 * Version of the rps API.
43 #define GNUNET_RPS_VERSION 0x00000000
46 * Handle for the random peer sampling service
48 struct GNUNET_RPS_Handle;
51 * Handle for one request to the rps service
53 struct GNUNET_RPS_Request_Handle;
56 * Callback called when requested random peers are available.
58 * @param cls the closure given with the request
59 * @param num_peers the number of peers returned
60 * @param peers array with num_peers PeerIDs
62 typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
64 const struct GNUNET_PeerIdentity *peers);
67 * Callback called when view was updated
69 * @param num_peers the number of peers returned
70 * @param peers array with num_peers PeerIDs
72 typedef void (* GNUNET_RPS_ViewUpdateCB) (void *cls,
74 const struct GNUNET_PeerIdentity *peers);
77 * Callback called when a peer from the biased stream was received
79 * @param peer The received peer
81 typedef void (* GNUNET_RPS_StreamInputCB) (void *cls,
82 const struct GNUNET_PeerIdentity *peer);
85 * Connect to the rps service
87 * @param cfg configuration to use
88 * @return handle to the rps service
90 struct GNUNET_RPS_Handle *
91 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
94 * Request n random peers.
96 * This does exacly the same as GNUNET_RPS_request_peers_single_call
97 * but needs a GNUNET_RPS_Handle.
98 * This exists only for other parts of GNUnet that expect having to
99 * (dis)connect from/to a service.
101 * @param h handle to the rps service
102 * @param n number of random peers to return
103 * @param ready_cb the callback to be called when the peers are available
104 * @param cls a closure that will be given to the callback
105 * @return handle to this request
107 struct GNUNET_RPS_Request_Handle *
108 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
109 GNUNET_RPS_NotifyReadyCB ready_cb,
113 * Seed rps service with peerIDs.
115 * @param h handle to the rps service
116 * @param n number of peers to seed
117 * @param ids the ids of the peers seeded
120 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
121 const struct GNUNET_PeerIdentity * ids);
124 * Cancle an issued request.
126 * @param rh handle of the pending request to be canceled
129 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
132 #ifdef ENABLE_MALICIOUS
134 * Turn RPS service to act malicious.
136 * @param h handle to the rps service
137 * @param type which type of malicious peer to turn to.
138 * 0 Don't act malicious at all
139 * 1 Try to maximise representation
140 * 2 Try to partition the network
141 * (isolate one peer from the rest)
142 * @param n number of @a ids
143 * @param ids the ids of the malicious peers
144 * if @type is 2 the last id is the id of the
145 * peer to be isolated from the rest
148 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
151 const struct GNUNET_PeerIdentity *ids,
152 const struct GNUNET_PeerIdentity *target_peer);
153 #endif /* ENABLE_MALICIOUS */
155 /* Get internals for debugging/profiling purposes */
158 * Request updates of view
160 * @param rps_handle handle to the rps service
161 * @param num_req_peers number of peers we want to receive
162 * (0 for infinite updates)
163 * @param cls a closure that will be given to the callback
164 * @param ready_cb the callback called when the peers are available
167 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
168 uint32_t num_updates,
169 GNUNET_RPS_ViewUpdateCB view_update_cb,
174 * Request biased stream of peers that are being put into the sampler
176 * @param rps_handle handle to the rps service
177 * @param num_req_peers number of peers we want to receive
178 * (0 for infinite updates)
179 * @param cls a closure that will be given to the callback
180 * @param ready_cb the callback called when the peers are available
183 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
184 uint32_t num_updates,
185 GNUNET_RPS_StreamInputCB stream_input_cb,
190 * Disconnect from the rps service
192 * @param h the handle to the rps service
195 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
198 #if 0 /* keep Emacsens' auto-indent happy */
207 /** @} */ /* end of group */