-Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api
[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 /***********************************************************************
221  * Defines from old gnunet-service-rps_peers.h
222 ***********************************************************************/
223
224 /**
225  * Different flags indicating the status of another peer.
226  */
227 enum Peers_PeerFlags
228 {
229   /**
230    * If we are waiting for a reply from that peer (sent a pull request).
231    */
232   Peers_PULL_REPLY_PENDING   = 0x01,
233
234   /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
235   /* IN_OWN_SAMPLER_LIST  = 0x04, unneeded? */
236   /* IN_OWN_GOSSIP_LIST   = 0x08, unneeded? */
237
238   /**
239    * We set this bit when we know the peer is online.
240    */
241   Peers_ONLINE               = 0x20,
242
243   /**
244    * We set this bit when we are going to destroy the channel to this peer.
245    * When cleanup_channel is called, we know that we wanted to destroy it.
246    * Otherwise the channel to the other peer was destroyed.
247    */
248   Peers_TO_DESTROY           = 0x40,
249 };
250
251 /**
252  * Keep track of the status of a channel.
253  *
254  * This is needed in order to know what to do with a channel when it's
255  * destroyed.
256  */
257 enum Peers_ChannelFlags
258 {
259   /**
260    * We destroyed the channel because the other peer established a second one.
261    */
262   Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
263
264   /**
265    * The channel was removed because it was not needed any more. This should be
266    * the sending channel.
267    */
268   Peers_CHANNEL_CLEAN = 0x2,
269
270   /**
271    * We destroyed the channel because the other peer established a second one.
272    */
273   Peers_CHANNEL_DESTROING = 0x4,
274 };
275
276
277 /**
278  * @brief The role of a channel. Sending or receiving.
279  */
280 enum Peers_ChannelRole
281 {
282   /**
283    * Channel is used for sending
284    */
285   Peers_CHANNEL_ROLE_SENDING   = 0x01,
286
287   /**
288    * Channel is used for receiving
289    */
290   Peers_CHANNEL_ROLE_RECEIVING = 0x02,
291 };
292
293 /**
294  * @brief Functions of this type can be used to be stored at a peer for later execution.
295  *
296  * @param cls closure
297  * @param peer peer to execute function on
298  */
299 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
300
301 /**
302  * @brief Iterator over valid peers.
303  *
304  * @param cls closure
305  * @param peer current public peer id
306  * @return #GNUNET_YES if we should continue to
307  *         iterate,
308  *         #GNUNET_NO if not.
309  */
310 typedef int
311 (*PeersIterator) (void *cls,
312                   const struct GNUNET_PeerIdentity *peer);
313
314
315 GNUNET_NETWORK_STRUCT_END