-skeletons for transport-ng
[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  * Message transmitted with the signed ephemeral key of a peer.  The
164  * session key is then derived from the two ephemeral keys (ECDHE).
165  *
166  * As far as possible, same as CORE's EphemeralKeyMessage.
167  */
168 struct GNUNET_CADET_KX_Ephemeral
169 {
170
171   /**
172    * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL.
173    */
174   struct GNUNET_MessageHeader header;
175
176   /**
177    * Status of the sender (should be in "enum PeerStateMachine"), nbo.
178    */
179   int32_t sender_status GNUNET_PACKED;
180
181   /**
182    * An ECC signature of the 'origin' asserting the validity of
183    * the given ephemeral key.
184    */
185   struct GNUNET_CRYPTO_EddsaSignature signature;
186
187   /**
188    * Information about what is being signed.
189    */
190   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
191
192   /**
193    * At what time was this key created (beginning of validity).
194    */
195   struct GNUNET_TIME_AbsoluteNBO creation_time;
196
197   /**
198    * When does the given ephemeral key expire (end of validity).
199    */
200   struct GNUNET_TIME_AbsoluteNBO expiration_time;
201
202   /**
203    * Ephemeral public ECC key (always for NIST P-521) encoded in a format
204    * suitable for network transmission as created using 'gcry_sexp_sprint'.
205    */
206   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
207
208   /**
209    * Public key of the signing peer
210    * (persistent version, not the ephemeral public key).
211    */
212   struct GNUNET_PeerIdentity origin_identity;
213
214   /**
215    * Seed for the IV of nonce.
216    */
217   uint32_t iv GNUNET_PACKED;
218
219   /**
220    * Nonce to check liveness of peer.
221    */
222   uint32_t nonce GNUNET_PACKED;
223 };
224
225
226 /**
227  * Response to a PING.  Includes data from the original PING.
228  */
229 struct GNUNET_CADET_KX_Pong
230 {
231   /**
232    * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_PONG.
233    */
234   struct GNUNET_MessageHeader header;
235
236   /**
237    * Seed for the IV
238    */
239   uint32_t iv GNUNET_PACKED;
240
241   /**
242    * Same nonce as in the reve.
243    */
244   uint32_t nonce GNUNET_PACKED;
245 };
246
247
248 /**
249  * Tunnel(ed) message.
250  */
251 struct GNUNET_CADET_Encrypted
252 {
253   /**
254    * Type: GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED
255    */
256   struct GNUNET_MessageHeader header;
257
258   /**
259    * ID of the connection.
260    */
261   struct GNUNET_CADET_Hash cid;
262
263   /**
264    * ID of the packet (hop by hop).
265    */
266   uint32_t pid GNUNET_PACKED;
267
268   /**
269    * Number of hops to live.
270    */
271   uint32_t ttl GNUNET_PACKED;
272
273   /**
274    * Initialization Vector for payload encryption.
275    */
276   uint32_t iv GNUNET_PACKED;
277
278   /**
279    * MAC of the encrypted message, used to verify message integrity.
280    * Everything after this value  will be encrypted and authenticated.
281    */
282   struct GNUNET_CADET_Hash hmac;
283
284   /**
285    * Encrypted content follows.
286    */
287 };
288
289
290 /**
291  * Axolotl tunnel message.
292  */
293 struct GNUNET_CADET_AX
294 {
295   /**
296    * Type: GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
297    */
298   struct GNUNET_MessageHeader header;
299
300   /**
301    * ID of the connection.
302    */
303   struct GNUNET_CADET_Hash cid;
304
305   /**
306    * ID of the packet (hop by hop).
307    */
308   uint32_t pid GNUNET_PACKED;
309
310   /**
311    * Reserved field for 64b alignment.
312    */
313   uint32_t reserved GNUNET_PACKED;
314
315   /**
316    * MAC of the encrypted message, used to verify message integrity.
317    * Everything after this value  will be encrypted with the header key
318    * and authenticated.
319    */
320   struct GNUNET_CADET_Hash hmac;
321
322   /**************** AX_HEADER start ****************/
323
324   /**
325    * Number of messages sent with the current ratchet key.
326    */
327   uint32_t Ns;
328
329   /**
330    * Number of messages sent with the previous ratchet key.
331    */
332   uint32_t PNs;
333
334   /**
335    * Current ratchet key.
336    */
337   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
338
339   /**************** AX_HEADER  end  ****************/
340
341   /**
342    * Encrypted content follows.
343    */
344 };
345
346
347 /**
348  * Message to create a Channel.
349  */
350 struct GNUNET_CADET_ChannelCreate
351 {
352   /**
353    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
354    */
355   struct GNUNET_MessageHeader header;
356
357   /**
358    * ID of the channel
359    */
360   CADET_ChannelNumber chid GNUNET_PACKED;
361
362   /**
363    * Destination port.
364    */
365   uint32_t port GNUNET_PACKED;
366
367   /**
368    * Channel options.
369    */
370   uint32_t opt GNUNET_PACKED;
371 };
372
373
374 /**
375  * Message to manage a Channel (ACK, NACK, Destroy).
376  */
377 struct GNUNET_CADET_ChannelManage
378 {
379   /**
380    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
381    */
382   struct GNUNET_MessageHeader header;
383
384   /**
385    * ID of the channel
386    */
387   CADET_ChannelNumber chid GNUNET_PACKED;
388 };
389
390
391 /**
392  * Message for cadet data traffic.
393  */
394 struct GNUNET_CADET_Data
395 {
396     /**
397      * Type: GNUNET_MESSAGE_TYPE_CADET_UNICAST,
398      *       GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
399      */
400   struct GNUNET_MessageHeader header;
401
402     /**
403      * Unique ID of the payload message
404      */
405   uint32_t mid GNUNET_PACKED;
406
407     /**
408      * ID of the channel
409      */
410   CADET_ChannelNumber chid GNUNET_PACKED;
411
412     /**
413      * Payload follows
414      */
415 };
416
417
418 /**
419  * Message to acknowledge end-to-end data.
420  */
421 struct GNUNET_CADET_DataACK
422 {
423   /**
424    * Type: GNUNET_MESSAGE_TYPE_CADET_DATA_ACK
425    */
426   struct GNUNET_MessageHeader header;
427
428   /**
429    * ID of the channel
430    */
431   CADET_ChannelNumber chid GNUNET_PACKED;
432
433   /**
434    * Bitfield of already-received newer messages
435    * pid +  1 @ LSB
436    * pid + 64 @ MSB
437    */
438   uint64_t futures GNUNET_PACKED;
439
440   /**
441    * Last message ID received.
442    */
443   uint32_t mid GNUNET_PACKED;
444 };
445
446
447 /**
448  * Message to acknowledge cadet encrypted traffic.
449  */
450 struct GNUNET_CADET_ACK
451 {
452     /**
453      * Type: GNUNET_MESSAGE_TYPE_CADET_ACK
454      */
455   struct GNUNET_MessageHeader header;
456
457     /**
458      * Maximum packet ID authorized.
459      */
460   uint32_t ack GNUNET_PACKED;
461
462     /**
463      * ID of the connection.
464      */
465   struct GNUNET_CADET_Hash cid;
466 };
467
468
469 /**
470  * Message to query a peer about its Flow Control status regarding a tunnel.
471  */
472 struct GNUNET_CADET_Poll
473 {
474     /**
475      * Type: GNUNET_MESSAGE_TYPE_CADET_POLL
476      */
477   struct GNUNET_MessageHeader header;
478
479     /**
480      * Last packet sent.
481      */
482   uint32_t pid GNUNET_PACKED;
483
484     /**
485      * ID of the connection.
486      */
487   struct GNUNET_CADET_Hash cid;
488
489 };
490
491
492 /**
493  * Message for notifying a disconnection in a path
494  */
495 struct GNUNET_CADET_ConnectionBroken
496 {
497     /**
498      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
499      */
500   struct GNUNET_MessageHeader header;
501
502     /**
503      * ID of the connection.
504      */
505   struct GNUNET_CADET_Hash cid;
506
507     /**
508      * ID of the endpoint
509      */
510   struct GNUNET_PeerIdentity peer1;
511
512     /**
513      * ID of the endpoint
514      */
515   struct GNUNET_PeerIdentity peer2;
516 };
517
518
519 /**
520  * Message to destroy a connection.
521  */
522 struct GNUNET_CADET_ConnectionDestroy
523 {
524     /**
525      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
526      */
527   struct GNUNET_MessageHeader header;
528
529     /**
530      * ID of the connection.
531      */
532   struct GNUNET_CADET_Hash cid;
533 };
534
535
536 GNUNET_NETWORK_STRUCT_END
537
538 #if 0                           /* keep Emacsens' auto-indent happy */
539 {
540 #endif
541 #ifdef __cplusplus
542 }
543 #endif
544
545 /* ifndef CADET_PROTOCOL_H */
546 #endif
547 /* end of cadet_protocol.h */