616eabdac1b13240df64df3190e7d0434c719713
[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 service with seed of peers.
64  */
65 struct GNUNET_RPS_CS_SeedMessage
66 {
67   /**
68    * Header including size and type in NBO
69    */
70   struct GNUNET_MessageHeader header;
71
72   /**
73    * Number of peers
74    */
75   uint32_t num_peers GNUNET_PACKED;
76
77   /* Followed by num_peers * GNUNET_PeerIdentity */
78 };
79
80 #ifdef ENABLE_MALICIOUS
81 /**
82  * Message from client to service to turn service malicious.
83  */
84 struct GNUNET_RPS_CS_ActMaliciousMessage
85 {
86   /**
87    * Header including size and type in NBO
88    */
89   struct GNUNET_MessageHeader header;
90
91   /**
92    * If the type is 2 this is the attacked peer,
93    * empty otherwise.
94    */
95   struct GNUNET_PeerIdentity attacked_peer;
96
97   /**
98    * Type of malicious behaviour.
99    *
100    * 0 No malicious bahaviour at all
101    * 1 Try to maximise representation
102    * 2 Try to partition the network
103    */
104   uint32_t type GNUNET_PACKED;
105
106   /**
107    * Number of peers
108    */
109   uint32_t num_peers GNUNET_PACKED;
110
111   /* Followed by num_peers * GNUNET_PeerIdentity when the type of malicious
112      behaviour is 1 */
113 };
114 #endif /* ENABLE_MALICIOUS */
115
116
117 /**
118  * Message from client to service telling it to start a new sub
119  */
120 struct GNUNET_RPS_CS_SubStartMessage
121 {
122   /**
123    * Header including size and type in NBO
124    */
125   struct GNUNET_MessageHeader header;
126
127   /**
128    * For alignment.
129    */
130   uint32_t reserved GNUNET_PACKED;
131
132   /**
133    * Mean interval between two rounds
134    */
135   struct GNUNET_TIME_RelativeNBO round_interval;
136
137   /**
138    * Length of the shared value represented as string.
139    */
140   struct GNUNET_HashCode hash GNUNET_PACKED;
141 };
142
143
144 /**
145  * Message from client to service telling it to stop a new sub
146  */
147 struct GNUNET_RPS_CS_SubStopMessage
148 {
149   /**
150    * Header including size and type in NBO
151    */
152   struct GNUNET_MessageHeader header;
153
154   /**
155    * Length of the shared value represented as string.
156    */
157   struct GNUNET_HashCode hash GNUNET_PACKED;
158 };
159
160
161 /* Debug messages */
162
163 /**
164  * Message from client to service indicating that
165  * clients wants to get updates of the view
166  */
167 struct GNUNET_RPS_CS_DEBUG_ViewRequest
168 {
169   /**
170    * Header including size and type in NBO
171    */
172   struct GNUNET_MessageHeader header;
173
174   /**
175    * Number of updates
176    * 0 for sending updates until cancellation
177    */
178   uint32_t num_updates GNUNET_PACKED;
179 };
180
181 /**
182  * Message from service to client containing current update of view
183  */
184 struct GNUNET_RPS_CS_DEBUG_ViewReply
185 {
186   /**
187    * Header including size and type in NBO
188    */
189   struct GNUNET_MessageHeader header;
190
191   /**
192    * Identifyer of the message.
193    */
194   uint32_t id GNUNET_PACKED;
195
196   /**
197    * Number of peers in the view
198    */
199   uint64_t num_peers GNUNET_PACKED;
200 };
201   /* Followed by num_peers * GNUNET_PeerIdentity */
202
203 /**
204  * Message from client to service indicating that
205  * clients wants to get stream of biased peers
206  */
207 struct GNUNET_RPS_CS_DEBUG_StreamRequest
208 {
209   /**
210    * Header including size and type in NBO
211    */
212   struct GNUNET_MessageHeader header;
213 };
214
215 /**
216  * Message from service to client containing peer from biased stream
217  */
218 struct GNUNET_RPS_CS_DEBUG_StreamReply
219 {
220   /**
221    * Header including size and type in NBO
222    */
223   struct GNUNET_MessageHeader header;
224
225   /**
226    * Number of peers
227    */
228   uint64_t num_peers GNUNET_PACKED;
229
230   // TODO maybe source of peer (pull/push list, peerinfo, ...)
231
232   /* Followed by num_peers * GNUNET_PeerIdentity */
233 };
234
235 GNUNET_NETWORK_STRUCT_END
236
237 /***********************************************************************
238  * Defines from old gnunet-service-rps_peers.h
239 ***********************************************************************/
240
241 /**
242  * Different flags indicating the status of another peer.
243  */
244 enum Peers_PeerFlags
245 {
246   /**
247    * If we are waiting for a reply from that peer (sent a pull request).
248    */
249   Peers_PULL_REPLY_PENDING   = 0x01,
250
251   /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
252   /* IN_OWN_SAMPLER_LIST  = 0x04, unneeded? */
253   /* IN_OWN_GOSSIP_LIST   = 0x08, unneeded? */
254
255   /**
256    * We set this bit when we know the peer is online.
257    */
258   Peers_ONLINE               = 0x20,
259
260   /**
261    * We set this bit when we are going to destroy the channel to this peer.
262    * When cleanup_channel is called, we know that we wanted to destroy it.
263    * Otherwise the channel to the other peer was destroyed.
264    */
265   Peers_TO_DESTROY           = 0x40,
266 };
267
268 /**
269  * Keep track of the status of a channel.
270  *
271  * This is needed in order to know what to do with a channel when it's
272  * destroyed.
273  */
274 enum Peers_ChannelFlags
275 {
276   /**
277    * We destroyed the channel because the other peer established a second one.
278    */
279   Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
280
281   /**
282    * The channel was removed because it was not needed any more. This should be
283    * the sending channel.
284    */
285   Peers_CHANNEL_CLEAN = 0x2,
286
287   /**
288    * We destroyed the channel because the other peer established a second one.
289    */
290   Peers_CHANNEL_DESTROING = 0x4,
291 };
292
293
294 /**
295  * @brief The role of a channel. Sending or receiving.
296  */
297 enum Peers_ChannelRole
298 {
299   /**
300    * Channel is used for sending
301    */
302   Peers_CHANNEL_ROLE_SENDING   = 0x01,
303
304   /**
305    * Channel is used for receiving
306    */
307   Peers_CHANNEL_ROLE_RECEIVING = 0x02,
308 };
309
310 /**
311  * @brief Functions of this type can be used to be stored at a peer for later execution.
312  *
313  * @param cls closure
314  * @param peer peer to execute function on
315  */
316 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
317
318 /**
319  * @brief Iterator over valid peers.
320  *
321  * @param cls closure
322  * @param peer current public peer id
323  * @return #GNUNET_YES if we should continue to
324  *         iterate,
325  *         #GNUNET_NO if not.
326  */
327 typedef int
328 (*PeersIterator) (void *cls,
329                   const struct GNUNET_PeerIdentity *peer);
330
331
332 /**
333  * Handle to the statistics service.
334  */
335 extern struct GNUNET_STATISTICS_Handle *stats;
336