fix bad free
[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
19 /**
20  * @author Julius Bünger
21  *
22  * @file
23  * API to the rps service
24  *
25  * @defgroup rps  RPS service
26  * Random Peer Sampling
27  * @{
28  */
29 #ifndef GNUNET_RPS_SERVICE_H
30 #define GNUNET_RPS_SERVICE_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 /**
41  * Version of the rps API.
42  */
43 #define GNUNET_RPS_VERSION 0x00000000
44
45 /**
46  * Handle for the random peer sampling service
47  */
48 struct GNUNET_RPS_Handle;
49
50 /**
51  * Handle for one request to the rps service
52  */
53 struct GNUNET_RPS_Request_Handle;
54
55 /**
56  * Callback called when requested random peers are available.
57  *
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
61  */
62 typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
63     uint64_t num_peers,
64     const struct GNUNET_PeerIdentity *peers);
65
66 /**
67  * Callback called when view was updated
68  *
69  * @param num_peers the number of peers returned
70  * @param peers array with num_peers PeerIDs
71  */
72 typedef void (* GNUNET_RPS_ViewUpdateCB) (void *cls,
73     uint64_t num_peers,
74     const struct GNUNET_PeerIdentity *peers);
75
76 /**
77  * Connect to the rps service
78  *
79  * @param cfg configuration to use
80  * @return handle to the rps service
81  */
82   struct GNUNET_RPS_Handle *
83 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
84
85 /**
86  * Request n random peers.
87  *
88  * This does exacly the same as GNUNET_RPS_request_peers_single_call
89  * but needs a GNUNET_RPS_Handle.
90  * This exists only for other parts of GNUnet that expect having to
91  * (dis)connect from/to a service.
92  *
93  * @param h handle to the rps service
94  * @param n number of random peers to return
95  * @param ready_cb the callback to be called when the peers are available
96  * @param cls a closure that will be given to the callback
97  * @return handle to this request
98  */
99   struct GNUNET_RPS_Request_Handle *
100 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
101                           GNUNET_RPS_NotifyReadyCB ready_cb,
102                           void *cls);
103
104 /**
105  * Seed rps service with peerIDs.
106  *
107  * @param h handle to the rps service
108  * @param n number of peers to seed
109  * @param ids the ids of the peers seeded
110  */
111   void
112 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
113                      const struct GNUNET_PeerIdentity * ids);
114
115 /**
116  * Cancle an issued request.
117  *
118  * @param rh handle of the pending request to be canceled
119  */
120   void
121 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
122
123
124 #ifdef ENABLE_MALICIOUS
125 /**
126  * Turn RPS service to act malicious.
127  *
128  * @param h handle to the rps service
129  * @param type which type of malicious peer to turn to.
130  *             0 Don't act malicious at all
131  *             1 Try to maximise representation
132  *             2 Try to partition the network
133  *               (isolate one peer from the rest)
134  * @param n number of @a ids
135  * @param ids the ids of the malicious peers
136  *            if @type is 2 the last id is the id of the
137  *            peer to be isolated from the rest
138  */
139   void
140 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
141                           uint32_t type,
142                           uint32_t num_peers,
143                           const struct GNUNET_PeerIdentity *ids,
144                           const struct GNUNET_PeerIdentity *target_peer);
145 #endif /* ENABLE_MALICIOUS */
146
147 /* Get internals for debugging/profiling purposes */
148
149 /**
150  * Request updates of view
151  *
152  * @param rps_handle handle to the rps service
153  * @param num_req_peers number of peers we want to receive
154  *        (0 for infinite updates)
155  * @param cls a closure that will be given to the callback
156  * @param ready_cb the callback called when the peers are available
157  */
158 void
159 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
160                          uint32_t num_updates,
161                          GNUNET_RPS_ViewUpdateCB view_update_cb,
162                          void *cls);
163
164 /**
165  * Disconnect from the rps service
166  *
167  * @param h the handle to the rps service
168  */
169   void
170 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
171
172
173 #if 0                           /* keep Emacsens' auto-indent happy */
174 {
175 #endif
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif
181
182 /** @} */  /* end of group */