Add API call to receive unbiased peer stream for debugging and profiling
[oweals/gnunet.git] / src / rps / rps.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2013 GNUnet e.V.
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  * @file rps/rps.h
20  * @brief example IPC messages between RPS API and GNS service
21  * @author Julius Bünger
22  */
23
24 #include "gnunet_rps_service.h"
25
26 /**
27  * Mesh port used by RPS.
28  */
29 #define GNUNET_RPS_CADET_PORT 31337
30
31
32 GNUNET_NETWORK_STRUCT_BEGIN
33
34 /***********************************************************************
35  * P2P Messages
36 ***********************************************************************/
37
38 /**
39  * P2P Message to send PeerIDs to other peer.
40  */
41 struct GNUNET_RPS_P2P_PullReplyMessage
42 {
43   /**
44    * Header including size and type in NBO
45    */
46   struct GNUNET_MessageHeader header;
47
48   /**
49    * Number of PeerIDs sent
50    */
51   uint32_t num_peers GNUNET_PACKED;
52
53   /* Followed by num_peers * GNUNET_PeerIdentity */
54 };
55
56
57
58 /***********************************************************************
59  * Client-Service Messages
60 ***********************************************************************/
61
62 /**
63  * Message from client to RPS service to request random peer(s).
64  */
65 struct GNUNET_RPS_CS_RequestMessage
66 {
67   /**
68    * Header including size and type in NBO
69    */
70   struct GNUNET_MessageHeader header;
71
72   /**
73    * Identifyer of the message.
74    */
75   uint32_t id GNUNET_PACKED;
76
77   /**
78    * Number of random peer requested
79    */
80   uint32_t num_peers GNUNET_PACKED;
81 };
82
83 /**
84  * Message from RPS service to client to reply with random peer(s).
85  */
86 struct GNUNET_RPS_CS_ReplyMessage
87 {
88   /**
89    * Type is #GNUNET_MESSAGE_TYPE_RPS_CS_REPLY.
90    */
91   struct GNUNET_MessageHeader header;
92
93   /**
94    * Identifyer of the message.
95    */
96   uint32_t id GNUNET_PACKED;
97
98   /**
99    * Number of random peer replied
100    */
101   uint32_t num_peers GNUNET_PACKED;
102
103   /* Followed by num_peers * GNUNET_PeerIdentity */
104 };
105
106 /**
107  * Message from client to RPS service to cancel request.
108  */
109 struct GNUNET_RPS_CS_RequestCancelMessage
110 {
111   /**
112    * Header including size and type in NBO
113    */
114   struct GNUNET_MessageHeader header;
115
116   /**
117    * Identifyer of the message.
118    */
119   uint32_t id GNUNET_PACKED;
120 };
121
122 /**
123  * Message from client to service with seed of peers.
124  */
125 struct GNUNET_RPS_CS_SeedMessage
126 {
127   /**
128    * Header including size and type in NBO
129    */
130   struct GNUNET_MessageHeader header;
131
132   /**
133    * Number of peers
134    */
135   uint32_t num_peers GNUNET_PACKED;
136
137   /* Followed by num_peers * GNUNET_PeerIdentity */
138 };
139
140 #ifdef ENABLE_MALICIOUS
141 /**
142  * Message from client to service to turn service malicious.
143  */
144 struct GNUNET_RPS_CS_ActMaliciousMessage
145 {
146   /**
147    * Header including size and type in NBO
148    */
149   struct GNUNET_MessageHeader header;
150
151   /**
152    * If the type is 2 this is the attacked peer,
153    * empty otherwise.
154    */
155   struct GNUNET_PeerIdentity attacked_peer;
156
157   /**
158    * Type of malicious behaviour.
159    *
160    * 0 No malicious bahaviour at all
161    * 1 Try to maximise representation
162    * 2 Try to partition the network
163    */
164   uint32_t type GNUNET_PACKED;
165
166   /**
167    * Number of peers
168    */
169   uint32_t num_peers GNUNET_PACKED;
170
171   /* Followed by num_peers * GNUNET_PeerIdentity when the type of malicious
172      behaviour is 1 */
173 };
174 #endif /* ENABLE_MALICIOUS */
175
176
177 /* Debug messages */
178
179 /**
180  * Message from client to service indicating that
181  * clients wants to get updates of the view
182  */
183 struct GNUNET_RPS_CS_DEBUG_ViewRequest
184 {
185   /**
186    * Header including size and type in NBO
187    */
188   struct GNUNET_MessageHeader header;
189
190   /**
191    * Number of updates
192    * 0 for sending updates until cancellation
193    */
194   uint32_t num_updates GNUNET_PACKED;
195 };
196
197 /**
198  * Message from service to client containing current update of view
199  */
200 struct GNUNET_RPS_CS_DEBUG_ViewReply
201 {
202   /**
203    * Header including size and type in NBO
204    */
205   struct GNUNET_MessageHeader header;
206
207   /**
208    * Identifyer of the message.
209    */
210   uint32_t id GNUNET_PACKED;
211
212   /**
213    * Number of peers in the view
214    */
215   uint64_t num_peers GNUNET_PACKED;
216 };
217   /* Followed by num_peers * GNUNET_PeerIdentity */
218
219 /**
220  * Message from client to service indicating that
221  * clients wants to get stream of biased peers
222  */
223 struct GNUNET_RPS_CS_DEBUG_StreamRequest
224 {
225   /**
226    * Header including size and type in NBO
227    */
228   struct GNUNET_MessageHeader header;
229
230   /**
231    * Number of peers
232    * 0 for sending updates until cancellation
233    */
234   uint32_t num_peers GNUNET_PACKED;
235 };
236
237 /**
238  * Message from service to client containing peer from biased stream
239  */
240 struct GNUNET_RPS_CS_DEBUG_StreamReply
241 {
242   /**
243    * Header including size and type in NBO
244    */
245   struct GNUNET_MessageHeader header;
246
247   /**
248    * Identifyer of the message.
249    */
250   uint32_t id GNUNET_PACKED;
251
252   /**
253    * @brief The peer of the biased stream
254    */
255   struct GNUNET_PeerIdentity peer;
256
257   // TODO maybe source of peer (pull/push list, peerinfo, ...)
258 };
259
260 GNUNET_NETWORK_STRUCT_END
261
262 /***********************************************************************
263  * Defines from old gnunet-service-rps_peers.h
264 ***********************************************************************/
265
266 /**
267  * Different flags indicating the status of another peer.
268  */
269 enum Peers_PeerFlags
270 {
271   /**
272    * If we are waiting for a reply from that peer (sent a pull request).
273    */
274   Peers_PULL_REPLY_PENDING   = 0x01,
275
276   /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
277   /* IN_OWN_SAMPLER_LIST  = 0x04, unneeded? */
278   /* IN_OWN_GOSSIP_LIST   = 0x08, unneeded? */
279
280   /**
281    * We set this bit when we know the peer is online.
282    */
283   Peers_ONLINE               = 0x20,
284
285   /**
286    * We set this bit when we are going to destroy the channel to this peer.
287    * When cleanup_channel is called, we know that we wanted to destroy it.
288    * Otherwise the channel to the other peer was destroyed.
289    */
290   Peers_TO_DESTROY           = 0x40,
291 };
292
293 /**
294  * Keep track of the status of a channel.
295  *
296  * This is needed in order to know what to do with a channel when it's
297  * destroyed.
298  */
299 enum Peers_ChannelFlags
300 {
301   /**
302    * We destroyed the channel because the other peer established a second one.
303    */
304   Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
305
306   /**
307    * The channel was removed because it was not needed any more. This should be
308    * the sending channel.
309    */
310   Peers_CHANNEL_CLEAN = 0x2,
311
312   /**
313    * We destroyed the channel because the other peer established a second one.
314    */
315   Peers_CHANNEL_DESTROING = 0x4,
316 };
317
318
319 /**
320  * @brief The role of a channel. Sending or receiving.
321  */
322 enum Peers_ChannelRole
323 {
324   /**
325    * Channel is used for sending
326    */
327   Peers_CHANNEL_ROLE_SENDING   = 0x01,
328
329   /**
330    * Channel is used for receiving
331    */
332   Peers_CHANNEL_ROLE_RECEIVING = 0x02,
333 };
334
335 /**
336  * @brief Functions of this type can be used to be stored at a peer for later execution.
337  *
338  * @param cls closure
339  * @param peer peer to execute function on
340  */
341 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
342
343 /**
344  * @brief Iterator over valid peers.
345  *
346  * @param cls closure
347  * @param peer current public peer id
348  * @return #GNUNET_YES if we should continue to
349  *         iterate,
350  *         #GNUNET_NO if not.
351  */
352 typedef int
353 (*PeersIterator) (void *cls,
354                   const struct GNUNET_PeerIdentity *peer);
355
356
357 /**
358  * Handle to the statistics service.
359  */
360 extern struct GNUNET_STATISTICS_Handle *stats;
361