-rps doxygen
[oweals/gnunet.git] / src / cadet / cadet_protocol.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001 - 2011 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 /**
22  * @author Bartlomiej Polot
23  * @file cadet/cadet_protocol.h
24  */
25
26 #ifndef CADET_PROTOCOL_H_
27 #define CADET_PROTOCOL_H_
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "cadet.h"
32
33 #ifdef __cplusplus
34
35 struct GNUNET_CADET_TunnelMessage;
36 extern "C"
37 {
38 #if 0
39   /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 /******************************************************************************/
45 /********************      CADET NETWORK MESSAGES     **************************/
46 /******************************************************************************/
47
48 GNUNET_NETWORK_STRUCT_BEGIN
49
50 /**
51  * Message for cadet connection creation.
52  */
53 struct GNUNET_CADET_ConnectionCreate
54 {
55   /**
56    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
57    *
58    * Size: sizeof (struct GNUNET_CADET_ConnectionCreate) +
59    *       path_length * sizeof (struct GNUNET_PeerIdentity)
60    */
61   struct GNUNET_MessageHeader header;
62
63   /**
64    * ID of the connection
65    */
66   struct GNUNET_CADET_Hash cid;
67
68   /**
69    * path_length structs defining the *whole* path from the origin [0] to the
70    * final destination [path_length-1].
71    */
72   /* struct GNUNET_PeerIdentity peers[path_length]; */
73 };
74
75
76 /**
77  * Message for ack'ing a connection
78  */
79 struct GNUNET_CADET_ConnectionACK
80 {
81     /**
82      * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK
83      */
84   struct GNUNET_MessageHeader header;
85
86     /**
87      * ID of the connection.
88      */
89   struct GNUNET_CADET_Hash cid;
90
91 };
92
93
94 /**
95  * Message for encapsulation of a Key eXchange message in a connection.
96  */
97 struct GNUNET_CADET_KX
98 {
99     /**
100      * Type: #GNUNET_MESSAGE_TYPE_CADET_KX.
101      */
102   struct GNUNET_MessageHeader header;
103
104     /**
105      * ID of the connection.
106      */
107   struct GNUNET_CADET_Hash cid;
108
109   /* Specific KX message follows. */
110 };
111
112
113 /**
114  * Flags to be used in GNUNET_CADET_AX_KX.
115  */
116 enum GNUNET_CADET_AX_KX_Flags {
117
118   /**
119    * Should the peer reply with its KX details?
120    */
121   GNUNET_CADET_AX_KX_FLAG_NONE = 0,
122
123   /**
124    * The peer should reply with its KX details?
125    */
126   GNUNET_CADET_AX_KX_FLAG_FORCE_REPLY = 1
127 };
128
129
130 /**
131  * Message for encapsulation of a Key eXchange message in a connection.
132  */
133 struct GNUNET_CADET_AX_KX
134 {
135   /**
136    * Type: #GNUNET_MESSAGE_TYPE_CADET_AX_KX.
137    */
138   struct GNUNET_MessageHeader header;
139
140   /**
141    * Flags for the key exchange in NBO, based on
142    * `enum GNUNET_CADET_AX_KX_Flags`.
143    */
144   uint32_t flags GNUNET_PACKED;
145
146   /**
147    * Sender's ephemeral public ECC key encoded in a
148    * format suitable for network transmission, as created
149    * using 'gcry_sexp_sprint'.
150    */
151   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
152
153   /**
154    * Sender's next ephemeral public ECC key encoded in a
155    * format suitable for network transmission, as created
156    * using 'gcry_sexp_sprint'.
157    */
158   struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
159 };
160
161
162 /**
163  * Axolotl tunnel message.
164  */
165 struct GNUNET_CADET_AX
166 {
167   /**
168    * Type: #GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
169    */
170   struct GNUNET_MessageHeader header;
171
172   /**
173    * ID of the packet (hop by hop).
174    */
175   uint32_t pid GNUNET_PACKED;
176
177   /**
178    * ID of the connection.
179    */
180   struct GNUNET_CADET_Hash cid;
181
182   /**
183    * MAC of the encrypted message, used to verify message integrity.
184    * Everything after this value  will be encrypted with the header key
185    * and authenticated.
186    */
187   struct GNUNET_CADET_Hash hmac;
188
189   /**************** AX_HEADER start ****************/
190
191   /**
192    * Number of messages sent with the current ratchet key.
193    */
194   uint32_t Ns GNUNET_PACKED;
195
196   /**
197    * Number of messages sent with the previous ratchet key.
198    */
199   uint32_t PNs GNUNET_PACKED;
200
201   /**
202    * Current ratchet key.
203    */
204   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
205
206   /**************** AX_HEADER  end  ****************/
207
208   /**
209    * Encrypted content follows.
210    */
211 };
212
213
214 /**
215  * Message to create a Channel.
216  */
217 struct GNUNET_CADET_ChannelCreate
218 {
219   /**
220    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
221    */
222   struct GNUNET_MessageHeader header;
223
224   /**
225    * ID of the channel
226    */
227   CADET_ChannelNumber chid GNUNET_PACKED;
228
229   /**
230    * Destination port.
231    */
232   struct GNUNET_HashCode port;
233
234   /**
235    * Channel options.
236    */
237   uint32_t opt GNUNET_PACKED;
238 };
239
240
241 /**
242  * Message to manage a Channel (ACK, NACK, Destroy).
243  */
244 struct GNUNET_CADET_ChannelManage
245 {
246   /**
247    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
248    */
249   struct GNUNET_MessageHeader header;
250
251   /**
252    * ID of the channel
253    */
254   CADET_ChannelNumber chid GNUNET_PACKED;
255 };
256
257
258 /**
259  * Message for cadet data traffic.
260  */
261 struct GNUNET_CADET_Data
262 {
263   /**
264    * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
265    *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
266    */
267   struct GNUNET_MessageHeader header;
268
269   /**
270    * Unique ID of the payload message
271    */
272   uint32_t mid GNUNET_PACKED;
273
274   /**
275    * ID of the channel
276    */
277   CADET_ChannelNumber chid GNUNET_PACKED;
278
279   /**
280    * Payload follows
281    */
282 };
283
284
285 /**
286  * Message to acknowledge end-to-end data.
287  */
288 struct GNUNET_CADET_DataACK
289 {
290   /**
291    * Type: GNUNET_MESSAGE_TYPE_CADET_DATA_ACK
292    */
293   struct GNUNET_MessageHeader header;
294
295   /**
296    * ID of the channel
297    */
298   CADET_ChannelNumber chid GNUNET_PACKED;
299
300   /**
301    * Bitfield of already-received newer messages
302    * pid +  1 @ LSB
303    * pid + 64 @ MSB
304    */
305   uint64_t futures GNUNET_PACKED;
306
307   /**
308    * Last message ID received.
309    */
310   uint32_t mid GNUNET_PACKED;
311 };
312
313
314 /**
315  * Message to acknowledge cadet encrypted traffic.
316  */
317 struct GNUNET_CADET_ACK
318 {
319   /**
320    * Type: #GNUNET_MESSAGE_TYPE_CADET_ACK
321    */
322   struct GNUNET_MessageHeader header;
323
324   /**
325    * Maximum packet ID authorized.
326    */
327   uint32_t ack GNUNET_PACKED;
328
329   /**
330    * ID of the connection.
331    */
332   struct GNUNET_CADET_Hash cid;
333 };
334
335
336 /**
337  * Message to query a peer about its Flow Control status regarding a tunnel.
338  */
339 struct GNUNET_CADET_Poll
340 {
341   /**
342    * Type: #GNUNET_MESSAGE_TYPE_CADET_POLL
343    */
344   struct GNUNET_MessageHeader header;
345
346   /**
347    * Last packet sent.
348    */
349   uint32_t pid GNUNET_PACKED;
350
351   /**
352    * ID of the connection.
353    */
354   struct GNUNET_CADET_Hash cid;
355
356 };
357
358
359 /**
360  * Message for notifying a disconnection in a path
361  */
362 struct GNUNET_CADET_ConnectionBroken
363 {
364   /**
365    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
366    */
367   struct GNUNET_MessageHeader header;
368
369   /**
370    * ID of the connection.
371    */
372   struct GNUNET_CADET_Hash cid;
373
374   /**
375    * ID of the endpoint
376    */
377   struct GNUNET_PeerIdentity peer1;
378
379   /**
380    * ID of the endpoint
381    */
382   struct GNUNET_PeerIdentity peer2;
383 };
384
385
386 /**
387  * Message to destroy a connection.
388  */
389 struct GNUNET_CADET_ConnectionDestroy
390 {
391   /**
392    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
393    */
394   struct GNUNET_MessageHeader header;
395
396   /**
397    * ID of the connection.
398    */
399   struct GNUNET_CADET_Hash cid;
400 };
401
402
403 GNUNET_NETWORK_STRUCT_END
404
405 #if 0                           /* keep Emacsens' auto-indent happy */
406 {
407 #endif
408 #ifdef __cplusplus
409 }
410 #endif
411
412 /* ifndef CADET_PROTOCOL_H */
413 #endif
414 /* end of cadet_protocol.h */