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