24145a0081036b00786a32f221b5ebc9300e0882
[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 /******************************************************************************/
52 /*****************************   CONNECTION  **********************************/
53 /******************************************************************************/
54
55
56 /**
57  * Message for cadet connection creation.
58  */
59 struct GNUNET_CADET_ConnectionCreateMessage
60 {
61   /**
62    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
63    *
64    * Size: sizeof (struct GNUNET_CADET_ConnectionCreateMessage) +
65    *       path_length * sizeof (struct GNUNET_PeerIdentity)
66    */
67   struct GNUNET_MessageHeader header;
68
69   /**
70    * For alignment.
71    */
72   uint32_t reserved GNUNET_PACKED;
73
74   /**
75    * ID of the connection
76    */
77   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
78
79   /**
80    * path_length structs defining the *whole* path from the origin [0] to the
81    * final destination [path_length-1].
82    */
83   /* struct GNUNET_PeerIdentity peers[path_length]; */
84 };
85
86
87 /**
88  * Message for ack'ing a connection
89  */
90 struct GNUNET_CADET_ConnectionCreateAckMessage
91 {
92   /**
93    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
94    */
95   struct GNUNET_MessageHeader header;
96
97   /**
98    * For alignment.
99    */
100   uint32_t reserved GNUNET_PACKED;
101
102   /**
103    * ID of the connection.
104    */
105   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
106
107 };
108
109
110 /**
111  * Message for notifying a disconnection in a path
112  */
113 struct GNUNET_CADET_ConnectionBrokenMessage
114 {
115   /**
116    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
117    */
118   struct GNUNET_MessageHeader header;
119
120   /**
121    * For alignment.
122    */
123   uint32_t reserved GNUNET_PACKED;
124
125   /**
126    * ID of the connection.
127    */
128   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
129
130   /**
131    * ID of the endpoint
132    */
133   struct GNUNET_PeerIdentity peer1;
134
135   /**
136    * ID of the endpoint
137    */
138   struct GNUNET_PeerIdentity peer2;
139 };
140
141
142 /**
143  * Message to destroy a connection.
144  */
145 struct GNUNET_CADET_ConnectionDestroyMessage
146 {
147   /**
148    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
149    */
150   struct GNUNET_MessageHeader header;
151
152   /**
153    * For alignment.
154    */
155   uint32_t reserved GNUNET_PACKED;
156
157   /**
158    * ID of the connection.
159    */
160   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
161 };
162
163
164 /******************************************************************************/
165 /*******************************   TUNNEL   ***********************************/
166 /******************************************************************************/
167
168 /**
169  * Unique identifier (counter) for an encrypted message in a channel.
170  * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
171  * and  #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
172  * against the respective  #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
173  * messages.
174  */
175 struct CadetEncryptedMessageIdentifier
176 {
177   /**
178    * This number is incremented by one per message. It may wrap around.
179    * In network byte order.
180    */
181   uint32_t pid GNUNET_PACKED;
182 };
183
184
185 /**
186  * Flags to be used in GNUNET_CADET_KX.
187  */
188 enum GNUNET_CADET_KX_Flags {
189
190   /**
191    * Should the peer reply with its KX details?
192    */
193   GNUNET_CADET_KX_FLAG_NONE = 0,
194
195   /**
196    * The peer should reply with its KX details?
197    */
198   GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
199 };
200
201
202 /**
203  * Message for a Key eXchange for a tunnel.
204  */
205 struct GNUNET_CADET_TunnelKeyExchangeMessage
206 {
207   /**
208    * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX.
209    */
210   struct GNUNET_MessageHeader header;
211
212   /**
213    * Flags for the key exchange in NBO, based on
214    * `enum GNUNET_CADET_KX_Flags`.
215    */
216   uint32_t flags GNUNET_PACKED;
217
218   /**
219    * ID of the connection.
220    */
221   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
222
223   /**
224    * Sender's ephemeral public ECC key encoded in a
225    * format suitable for network transmission, as created
226    * using 'gcry_sexp_sprint'.
227    */
228   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
229
230   /**
231    * Sender's next ephemeral public ECC key encoded in a
232    * format suitable for network transmission, as created
233    * using 'gcry_sexp_sprint'.
234    */
235   struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
236
237 #ifdef NEW_CADET
238   /**
239    * Proof that sender could compute the 3-DH, in lieu of a signature.
240    */
241   struct GNUNET_HashCode triple_dh_proof;
242 #endif
243 };
244
245
246 /**
247  * Axolotl tunnel message.
248  */
249 struct GNUNET_CADET_TunnelEncryptedMessage
250 {
251   /**
252    * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
253    */
254   struct GNUNET_MessageHeader header;
255
256 #if NEW_CADET
257   /**
258    * Reserved, for alignment.
259    */
260   uint32_t reserved GNUNET_PACKED;
261 #else
262   /**
263    * Maximum packet ID authorized.
264    */
265   struct CadetEncryptedMessageIdentifier cemi;
266 #endif
267
268   /**
269    * ID of the connection.
270    */
271   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
272
273   /**
274    * MAC of the encrypted message, used to verify message integrity.
275    * Everything after this value  will be encrypted with the header key
276    * and authenticated.
277    */
278   struct GNUNET_ShortHashCode hmac;
279
280   /**************** AX_HEADER start ****************/
281
282   /**
283    * Number of messages sent with the current ratchet key.
284    */
285   uint32_t Ns GNUNET_PACKED;
286
287   /**
288    * Number of messages sent with the previous ratchet key.
289    */
290   uint32_t PNs GNUNET_PACKED;
291
292   /**
293    * Current ratchet key.
294    */
295   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
296
297   /**************** AX_HEADER  end  ****************/
298
299   /**
300    * Encrypted content follows.
301    */
302 };
303
304
305 #ifndef NEW_CADET
306
307 /**
308  * Message to query a peer about its Flow Control status regarding a tunnel.
309  *
310  * It is NOT yet clear if we need this.
311  */
312 struct GNUNET_CADET_ConnectionHopByHopPollMessage
313 {
314   /**
315    * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL
316    */
317   struct GNUNET_MessageHeader header;
318
319   /**
320    * Last packet sent.
321    */
322   struct CadetEncryptedMessageIdentifier cemi;
323
324   /**
325    * ID of the connection.
326    */
327   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
328
329 };
330
331
332 /**
333  * Message to acknowledge cadet encrypted traffic, used for
334  * flow-control on a hop-by-hop basis on the connection-level. Note
335  * that we do use the @e cemi from the tunnel layer as the connection
336  * layer's header is included/shared with the tunnel layer messages,
337  * and we only do flow control for the payload.
338  */
339 struct GNUNET_CADET_ConnectionEncryptedAckMessage
340 {
341   /**
342    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
343    */
344   struct GNUNET_MessageHeader header;
345
346   /**
347    * Maximum packet ID authorized.
348    */
349   struct CadetEncryptedMessageIdentifier cemi_max;
350
351   /**
352    * ID of the connection.
353    */
354   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
355 };
356
357 #endif
358
359
360 /******************************************************************************/
361 /*******************************   CHANNEL  ***********************************/
362 /******************************************************************************/
363
364
365 /**
366  * Message to create a Channel.
367  */
368 struct GNUNET_CADET_ChannelOpenMessage
369 {
370   /**
371    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
372    */
373   struct GNUNET_MessageHeader header;
374
375   /**
376    * Channel options.
377    */
378   uint32_t opt GNUNET_PACKED;
379
380   /**
381    * Destination port.
382    */
383   struct GNUNET_HashCode port;
384
385   /**
386    * ID of the channel within the tunnel.
387    */
388   struct GNUNET_CADET_ChannelTunnelNumber ctn;
389 };
390
391
392 /**
393  * Message to manage a Channel (CHANNEL_CREATE_ACK, CHANNEL_DESTROY).
394  */
395 struct GNUNET_CADET_ChannelManageMessage
396 {
397   /**
398    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE_ACK or
399    * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
400    */
401   struct GNUNET_MessageHeader header;
402
403 #ifdef NEW_CADET
404   /**
405    * For alignment.
406    */
407   uint32_t reserved GNUNET_PACKED;
408 #endif
409
410   /**
411    * ID of the channel
412    */
413   struct GNUNET_CADET_ChannelTunnelNumber ctn;
414 };
415
416
417 #ifndef NEW_CADET
418
419 /**
420  * Message for cadet data traffic.
421  */
422 struct GNUNET_CADET_ChannelAppDataMessage
423 {
424   /**
425    * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
426    *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
427    */
428   struct GNUNET_MessageHeader header;
429
430   /**
431    * Unique ID of the payload message
432    */
433   /* NEW: struct ChannelMessageIdentifier */
434   uint32_t mid GNUNET_PACKED;
435
436   /**
437    * ID of the channel
438    */
439   struct GNUNET_CADET_ChannelTunnelNumber ctn;
440
441   /**
442    * Payload follows
443    */
444 };
445
446
447 /**
448  * Message to acknowledge end-to-end data.
449  */
450 struct GNUNET_CADET_ChannelDataAckMessage
451 {
452   /**
453    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
454    */
455   struct GNUNET_MessageHeader header;
456
457   /**
458    * ID of the channel
459    */
460   struct GNUNET_CADET_ChannelTunnelNumber ctn;
461
462   /**
463    * Bitfield of already-received newer messages
464    * pid +  1 @ LSB
465    * pid + 64 @ MSB
466    */
467   uint64_t futures GNUNET_PACKED;
468
469   /**
470    * Last message ID received.
471    */
472   /* NEW: struct ChannelMessageIdentifier */
473   uint32_t mid GNUNET_PACKED;
474 };
475
476 #else
477
478
479 /**
480  * Number used to uniquely identify messages in a CADET Channel.
481  */
482 struct ChannelMessageIdentifier
483 {
484   /**
485    * Unique ID of the message, cycles around, in NBO.
486    */
487   uint32_t mid GNUNET_PACKED;
488 };
489
490
491 /**
492  * Message for cadet data traffic.
493  */
494 struct GNUNET_CADET_ChannelAppDataMessage
495 {
496   /**
497    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
498    */
499   struct GNUNET_MessageHeader header;
500
501   /**
502    * Unique ID of the payload message.
503    */
504   struct ChannelMessageIdentifier mid;
505
506   /**
507    * ID of the channel
508    */
509   struct GNUNET_CADET_ChannelTunnelNumber ctn;
510
511   /**
512    * Payload follows
513    */
514 };
515
516
517 /**
518  * Message to acknowledge end-to-end data.
519  */
520 struct GNUNET_CADET_ChannelDataAckMessage
521 {
522   /**
523    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
524    */
525   struct GNUNET_MessageHeader header;
526
527   /**
528    * ID of the channel
529    */
530   struct GNUNET_CADET_ChannelTunnelNumber ctn;
531
532   /**
533    * Bitfield of already-received messages past @e mid.
534    * pid +  1 @ LSB
535    * pid + 64 @ MSB
536    */
537   uint64_t futures GNUNET_PACKED;
538
539   /**
540    * Last message ID received.
541    */
542   struct ChannelMessageIdentifier mid;
543 };
544
545
546 #endif
547
548 GNUNET_NETWORK_STRUCT_END
549
550 #if 0                           /* keep Emacsens' auto-indent happy */
551 {
552 #endif
553 #ifdef __cplusplus
554 }
555 #endif
556
557 /* ifndef CADET_PROTOCOL_H */
558 #endif
559 /* end of cadet_protocol.h */