d4cf60856f8ebcde791490d8560a7ae976d04f2a
[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 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
16 /**
17  * @author Julius Bünger
18  *
19  * @file
20  * API to the rps service
21  *
22  * @defgroup rps  RPS service
23  * Random Peer Sampling
24  * @{
25  */
26 #ifndef GNUNET_RPS_SERVICE_H
27 #define GNUNET_RPS_SERVICE_H
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #if 0                           /* keep Emacsens' auto-indent happy */
33 }
34 #endif
35 #endif
36
37 /**
38  * Version of the rps API.
39  */
40 #define GNUNET_RPS_VERSION 0x00000000
41
42 /**
43  * Handle for the random peer sampling service
44  */
45 struct GNUNET_RPS_Handle;
46
47 /**
48  * Handle for one request to the rps service
49  */
50 struct GNUNET_RPS_Request_Handle;
51
52 /**
53  * Callback called when requested random peers are available.
54  *
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
58  */
59 typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
60     uint64_t num_peers,
61     const struct GNUNET_PeerIdentity *peers);
62
63 /**
64  * Callback called when view was updated
65  *
66  * @param num_peers the number of peers returned
67  * @param peers array with num_peers PeerIDs
68  */
69 typedef void (* GNUNET_RPS_ViewUpdateCB) (void *cls,
70     uint64_t num_peers,
71     const struct GNUNET_PeerIdentity *peers);
72
73 /**
74  * Connect to the rps service
75  *
76  * @param cfg configuration to use
77  * @return handle to the rps service
78  */
79   struct GNUNET_RPS_Handle *
80 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
81
82 /**
83  * Request n random peers.
84  *
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.
89  *
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
95  */
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,
99                           void *cls);
100
101 /**
102  * Seed rps service with peerIDs.
103  *
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
107  */
108   void
109 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
110                      const struct GNUNET_PeerIdentity * ids);
111
112 /**
113  * Cancle an issued request.
114  *
115  * @param rh handle of the pending request to be canceled
116  */
117   void
118 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
119
120
121 #ifdef ENABLE_MALICIOUS
122 /**
123  * Turn RPS service to act malicious.
124  *
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
135  */
136   void
137 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
138                           uint32_t type,
139                           uint32_t num_peers,
140                           const struct GNUNET_PeerIdentity *ids,
141                           const struct GNUNET_PeerIdentity *target_peer);
142 #endif /* ENABLE_MALICIOUS */
143
144 /* Get internals for debugging/profiling purposes */
145
146 /**
147  * Request updates of view
148  *
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
154  */
155 void
156 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
157                          uint32_t num_updates,
158                          GNUNET_RPS_ViewUpdateCB view_update_cb,
159                          void *cls);
160
161 /**
162  * Disconnect from the rps service
163  *
164  * @param h the handle to the rps service
165  */
166   void
167 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
168
169
170 #if 0                           /* keep Emacsens' auto-indent happy */
171 {
172 #endif
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif
178
179 /** @} */  /* end of group */