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