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 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.
17 * @author Julius Bünger
20 * API to the rps service
22 * @defgroup rps RPS service
23 * Random Peer Sampling
26 #ifndef GNUNET_RPS_SERVICE_H
27 #define GNUNET_RPS_SERVICE_H
32 #if 0 /* keep Emacsens' auto-indent happy */
38 * Version of the rps API.
40 #define GNUNET_RPS_VERSION 0x00000000
43 * Handle for the random peer sampling service
45 struct GNUNET_RPS_Handle;
48 * Handle for one request to the rps service
50 struct GNUNET_RPS_Request_Handle;
53 * Callback called when requested random peers are available.
55 * @param cls the closure given with the request
56 * @param num_peers the number of peers returned
57 * @param peers array with num_peers PeerIDs
59 typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
61 const struct GNUNET_PeerIdentity *peers);
64 * Callback called when view was updated
66 * @param num_peers the number of peers returned
67 * @param peers array with num_peers PeerIDs
69 typedef void (* GNUNET_RPS_ViewUpdateCB) (void *cls,
71 const struct GNUNET_PeerIdentity *peers);
74 * Connect to the rps service
76 * @param cfg configuration to use
77 * @return handle to the rps service
79 struct GNUNET_RPS_Handle *
80 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
83 * Request n random peers.
85 * This does exacly the same as GNUNET_RPS_request_peers_single_call
86 * but needs a GNUNET_RPS_Handle.
87 * This exists only for other parts of GNUnet that expect having to
88 * (dis)connect from/to a service.
90 * @param h handle to the rps service
91 * @param n number of random peers to return
92 * @param ready_cb the callback to be called when the peers are available
93 * @param cls a closure that will be given to the callback
94 * @return handle to this request
96 struct GNUNET_RPS_Request_Handle *
97 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
98 GNUNET_RPS_NotifyReadyCB ready_cb,
102 * Seed rps service with peerIDs.
104 * @param h handle to the rps service
105 * @param n number of peers to seed
106 * @param ids the ids of the peers seeded
109 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
110 const struct GNUNET_PeerIdentity * ids);
113 * Cancle an issued request.
115 * @param rh handle of the pending request to be canceled
118 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
121 #ifdef ENABLE_MALICIOUS
123 * Turn RPS service to act malicious.
125 * @param h handle to the rps service
126 * @param type which type of malicious peer to turn to.
127 * 0 Don't act malicious at all
128 * 1 Try to maximise representation
129 * 2 Try to partition the network
130 * (isolate one peer from the rest)
131 * @param n number of @a ids
132 * @param ids the ids of the malicious peers
133 * if @type is 2 the last id is the id of the
134 * peer to be isolated from the rest
137 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
140 const struct GNUNET_PeerIdentity *ids,
141 const struct GNUNET_PeerIdentity *target_peer);
142 #endif /* ENABLE_MALICIOUS */
144 /* Get internals for debugging/profiling purposes */
147 * Request updates of view
149 * @param rps_handle handle to the rps service
150 * @param num_req_peers number of peers we want to receive
151 * (0 for infinite updates)
152 * @param cls a closure that will be given to the callback
153 * @param ready_cb the callback called when the peers are available
156 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
157 uint32_t num_updates,
158 GNUNET_RPS_ViewUpdateCB view_update_cb,
162 * Disconnect from the rps service
164 * @param h the handle to the rps service
167 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
170 #if 0 /* keep Emacsens' auto-indent happy */
179 /** @} */ /* end of group */