update velocity always at the end of iteration
[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
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       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       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
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 RPS service to request random peer(s).
66  */
67 struct GNUNET_RPS_CS_RequestMessage
68 {
69   /**
70    * Header including size and type in NBO
71    */
72   struct GNUNET_MessageHeader header;
73
74   /**
75    * Identifyer of the message.
76    */
77   uint32_t id GNUNET_PACKED;
78
79   /**
80    * Number of random peer requested
81    */
82   uint32_t num_peers GNUNET_PACKED;
83 };
84
85 /**
86  * Message from RPS service to client to reply with random peer(s).
87  */
88 struct GNUNET_RPS_CS_ReplyMessage
89 {
90   /**
91    * Type is #GNUNET_MESSAGE_TYPE_RPS_CS_REPLY.
92    */
93   struct GNUNET_MessageHeader header;
94
95   /**
96    * Identifyer of the message.
97    */
98   uint32_t id GNUNET_PACKED;
99
100   /**
101    * Number of random peer replied
102    */
103   uint32_t num_peers GNUNET_PACKED;
104
105   /* Followed by num_peers * GNUNET_PeerIdentity */
106 };
107
108 /**
109  * Message from client to RPS service to cancel request.
110  */
111 struct GNUNET_RPS_CS_RequestCancelMessage
112 {
113   /**
114    * Header including size and type in NBO
115    */
116   struct GNUNET_MessageHeader header;
117
118   /**
119    * Identifyer of the message.
120    */
121   uint32_t id GNUNET_PACKED;
122 };
123
124 /**
125  * Message from client to service with seed of peers.
126  */
127 struct GNUNET_RPS_CS_SeedMessage
128 {
129   /**
130    * Header including size and type in NBO
131    */
132   struct GNUNET_MessageHeader header;
133
134   /**
135    * Number of peers
136    */
137   uint32_t num_peers GNUNET_PACKED;
138
139   /* Followed by num_peers * GNUNET_PeerIdentity */
140 };
141
142 #ifdef ENABLE_MALICIOUS
143 /**
144  * Message from client to service to turn service malicious.
145  */
146 struct GNUNET_RPS_CS_ActMaliciousMessage
147 {
148   /**
149    * Header including size and type in NBO
150    */
151   struct GNUNET_MessageHeader header;
152
153   /**
154    * If the type is 2 this is the attacked peer,
155    * empty otherwise.
156    */
157   struct GNUNET_PeerIdentity attacked_peer;
158
159   /**
160    * Type of malicious behaviour.
161    *
162    * 0 No malicious bahaviour at all
163    * 1 Try to maximise representation
164    * 2 Try to partition the network
165    */
166   uint32_t type GNUNET_PACKED;
167
168   /**
169    * Number of peers
170    */
171   uint32_t num_peers GNUNET_PACKED;
172
173   /* Followed by num_peers * GNUNET_PeerIdentity when the type of malicious
174      behaviour is 1 */
175 };
176 #endif /* ENABLE_MALICIOUS */
177
178
179 /* Debug messages */
180
181 /**
182  * Message from client to service indicating that
183  * clients wants to get updates of the view
184  */
185 struct GNUNET_RPS_CS_DEBUG_ViewRequest
186 {
187   /**
188    * Header including size and type in NBO
189    */
190   struct GNUNET_MessageHeader header;
191
192   /**
193    * Number of updates
194    * 0 for sending updates until cancellation
195    */
196   uint32_t num_updates GNUNET_PACKED;
197 };
198
199 /**
200  * Message from service to client containing current update of view
201  */
202 struct GNUNET_RPS_CS_DEBUG_ViewReply
203 {
204   /**
205    * Header including size and type in NBO
206    */
207   struct GNUNET_MessageHeader header;
208
209   /**
210    * Identifyer of the message.
211    */
212   uint32_t id GNUNET_PACKED;
213
214   /**
215    * Number of peers in the view
216    */
217   uint64_t num_peers GNUNET_PACKED;
218 };
219   /* Followed by num_peers * GNUNET_PeerIdentity */
220
221
222 /***********************************************************************
223  * Defines from old gnunet-service-rps_peers.h
224 ***********************************************************************/
225
226 /**
227  * Different flags indicating the status of another peer.
228  */
229 enum Peers_PeerFlags
230 {
231   /**
232    * If we are waiting for a reply from that peer (sent a pull request).
233    */
234   Peers_PULL_REPLY_PENDING   = 0x01,
235
236   /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
237   /* IN_OWN_SAMPLER_LIST  = 0x04, unneeded? */
238   /* IN_OWN_GOSSIP_LIST   = 0x08, unneeded? */
239
240   /**
241    * We set this bit when we know the peer is online.
242    */
243   Peers_ONLINE               = 0x20,
244
245   /**
246    * We set this bit when we are going to destroy the channel to this peer.
247    * When cleanup_channel is called, we know that we wanted to destroy it.
248    * Otherwise the channel to the other peer was destroyed.
249    */
250   Peers_TO_DESTROY           = 0x40,
251 };
252
253 /**
254  * Keep track of the status of a channel.
255  *
256  * This is needed in order to know what to do with a channel when it's
257  * destroyed.
258  */
259 enum Peers_ChannelFlags
260 {
261   /**
262    * We destroyed the channel because the other peer established a second one.
263    */
264   Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
265
266   /**
267    * The channel was removed because it was not needed any more. This should be
268    * the sending channel.
269    */
270   Peers_CHANNEL_CLEAN = 0x2,
271
272   /**
273    * We destroyed the channel because the other peer established a second one.
274    */
275   Peers_CHANNEL_DESTROING = 0x4,
276 };
277
278
279 /**
280  * @brief The role of a channel. Sending or receiving.
281  */
282 enum Peers_ChannelRole
283 {
284   /**
285    * Channel is used for sending
286    */
287   Peers_CHANNEL_ROLE_SENDING   = 0x01,
288
289   /**
290    * Channel is used for receiving
291    */
292   Peers_CHANNEL_ROLE_RECEIVING = 0x02,
293 };
294
295 /**
296  * @brief Functions of this type can be used to be stored at a peer for later execution.
297  *
298  * @param cls closure
299  * @param peer peer to execute function on
300  */
301 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
302
303 /**
304  * @brief Iterator over valid peers.
305  *
306  * @param cls closure
307  * @param peer current public peer id
308  * @return #GNUNET_YES if we should continue to
309  *         iterate,
310  *         #GNUNET_NO if not.
311  */
312 typedef int
313 (*PeersIterator) (void *cls,
314                   const struct GNUNET_PeerIdentity *peer);
315
316
317 GNUNET_NETWORK_STRUCT_END