Merge branch 'master' of git+ssh://gnunet.org/gnunet
[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 /* Debug messages */
118
119 /**
120  * Message from client to service indicating that
121  * clients wants to get updates of the view
122  */
123 struct GNUNET_RPS_CS_DEBUG_ViewRequest
124 {
125   /**
126    * Header including size and type in NBO
127    */
128   struct GNUNET_MessageHeader header;
129
130   /**
131    * Number of updates
132    * 0 for sending updates until cancellation
133    */
134   uint32_t num_updates GNUNET_PACKED;
135 };
136
137 /**
138  * Message from service to client containing current update of view
139  */
140 struct GNUNET_RPS_CS_DEBUG_ViewReply
141 {
142   /**
143    * Header including size and type in NBO
144    */
145   struct GNUNET_MessageHeader header;
146
147   /**
148    * Identifyer of the message.
149    */
150   uint32_t id GNUNET_PACKED;
151
152   /**
153    * Number of peers in the view
154    */
155   uint64_t num_peers GNUNET_PACKED;
156 };
157   /* Followed by num_peers * GNUNET_PeerIdentity */
158
159 /**
160  * Message from client to service indicating that
161  * clients wants to get stream of biased peers
162  */
163 struct GNUNET_RPS_CS_DEBUG_StreamRequest
164 {
165   /**
166    * Header including size and type in NBO
167    */
168   struct GNUNET_MessageHeader header;
169 };
170
171 /**
172  * Message from service to client containing peer from biased stream
173  */
174 struct GNUNET_RPS_CS_DEBUG_StreamReply
175 {
176   /**
177    * Header including size and type in NBO
178    */
179   struct GNUNET_MessageHeader header;
180
181   /**
182    * Number of peers
183    */
184   uint64_t num_peers GNUNET_PACKED;
185
186   // TODO maybe source of peer (pull/push list, peerinfo, ...)
187
188   /* Followed by num_peers * GNUNET_PeerIdentity */
189 };
190
191 GNUNET_NETWORK_STRUCT_END
192
193 /***********************************************************************
194  * Defines from old gnunet-service-rps_peers.h
195 ***********************************************************************/
196
197 /**
198  * Different flags indicating the status of another peer.
199  */
200 enum Peers_PeerFlags
201 {
202   /**
203    * If we are waiting for a reply from that peer (sent a pull request).
204    */
205   Peers_PULL_REPLY_PENDING   = 0x01,
206
207   /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
208   /* IN_OWN_SAMPLER_LIST  = 0x04, unneeded? */
209   /* IN_OWN_GOSSIP_LIST   = 0x08, unneeded? */
210
211   /**
212    * We set this bit when we know the peer is online.
213    */
214   Peers_ONLINE               = 0x20,
215
216   /**
217    * We set this bit when we are going to destroy the channel to this peer.
218    * When cleanup_channel is called, we know that we wanted to destroy it.
219    * Otherwise the channel to the other peer was destroyed.
220    */
221   Peers_TO_DESTROY           = 0x40,
222 };
223
224 /**
225  * Keep track of the status of a channel.
226  *
227  * This is needed in order to know what to do with a channel when it's
228  * destroyed.
229  */
230 enum Peers_ChannelFlags
231 {
232   /**
233    * We destroyed the channel because the other peer established a second one.
234    */
235   Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
236
237   /**
238    * The channel was removed because it was not needed any more. This should be
239    * the sending channel.
240    */
241   Peers_CHANNEL_CLEAN = 0x2,
242
243   /**
244    * We destroyed the channel because the other peer established a second one.
245    */
246   Peers_CHANNEL_DESTROING = 0x4,
247 };
248
249
250 /**
251  * @brief The role of a channel. Sending or receiving.
252  */
253 enum Peers_ChannelRole
254 {
255   /**
256    * Channel is used for sending
257    */
258   Peers_CHANNEL_ROLE_SENDING   = 0x01,
259
260   /**
261    * Channel is used for receiving
262    */
263   Peers_CHANNEL_ROLE_RECEIVING = 0x02,
264 };
265
266 /**
267  * @brief Functions of this type can be used to be stored at a peer for later execution.
268  *
269  * @param cls closure
270  * @param peer peer to execute function on
271  */
272 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
273
274 /**
275  * @brief Iterator over valid peers.
276  *
277  * @param cls closure
278  * @param peer current public peer id
279  * @return #GNUNET_YES if we should continue to
280  *         iterate,
281  *         #GNUNET_NO if not.
282  */
283 typedef int
284 (*PeersIterator) (void *cls,
285                   const struct GNUNET_PeerIdentity *peer);
286
287
288 /**
289  * Handle to the statistics service.
290  */
291 extern struct GNUNET_STATISTICS_Handle *stats;
292