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