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