f85ef17ae70f7a1d60290c5469894cb06a1092ca
[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_ConnectionCreateMessageAckMessage
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   /**
257    * ID of the packet (hop by hop).
258    */
259   struct CadetEncryptedMessageIdentifier cemi;
260
261   /**
262    * ID of the connection.
263    */
264   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
265
266   /**
267    * MAC of the encrypted message, used to verify message integrity.
268    * Everything after this value  will be encrypted with the header key
269    * and authenticated.
270    */
271   struct GNUNET_ShortHashCode hmac;
272
273   /**************** AX_HEADER start ****************/
274
275   /**
276    * Number of messages sent with the current ratchet key.
277    */
278   uint32_t Ns GNUNET_PACKED;
279
280   /**
281    * Number of messages sent with the previous ratchet key.
282    */
283   uint32_t PNs GNUNET_PACKED;
284
285   /**
286    * Current ratchet key.
287    */
288   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
289
290   /**************** AX_HEADER  end  ****************/
291
292   /**
293    * Encrypted content follows.
294    */
295 };
296
297
298 /**
299  * Message to query a peer about its Flow Control status regarding a tunnel.
300  *
301  * It is NOT yet clear if we need this.
302  */
303 struct GNUNET_CADET_ConnectionHopByHopPollMessage
304 {
305   /**
306    * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL
307    */
308   struct GNUNET_MessageHeader header;
309
310   /**
311    * Last packet sent.
312    */
313   struct CadetEncryptedMessageIdentifier cemi;
314
315   /**
316    * ID of the connection.
317    */
318   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
319
320 };
321
322
323 /**
324  * Message to acknowledge cadet encrypted traffic, used for
325  * flow-control on a hop-by-hop basis on the connection-level. Note
326  * that we do use the @e cemi from the tunnel layer as the connection
327  * layer's header is included/shared with the tunnel layer messages,
328  * and we only do flow control for the payload.
329  */
330 struct GNUNET_CADET_ConnectionEncryptedAckMessage
331 {
332   /**
333    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
334    */
335   struct GNUNET_MessageHeader header;
336
337   /**
338    * Maximum packet ID authorized.
339    */
340   struct CadetEncryptedMessageIdentifier cemi_max;
341
342   /**
343    * ID of the connection.
344    */
345   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
346 };
347
348
349 /******************************************************************************/
350 /*******************************   CHANNEL  ***********************************/
351 /******************************************************************************/
352
353
354 /**
355  * Message to create a Channel.
356  */
357 struct GNUNET_CADET_ChannelOpenMessage
358 {
359   /**
360    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
361    */
362   struct GNUNET_MessageHeader header;
363
364   /**
365    * Channel options.
366    */
367   uint32_t opt GNUNET_PACKED;
368
369   /**
370    * Destination port.
371    */
372   struct GNUNET_HashCode port;
373
374   /**
375    * ID of the channel within the tunnel.
376    */
377   struct GNUNET_CADET_ChannelTunnelNumber chid;
378 };
379
380
381 /**
382  * Message to manage a Channel (CHANNEL_CREATE_ACK, CHANNEL_DESTROY).
383  */
384 struct GNUNET_CADET_ChannelManageMessage
385 {
386   /**
387    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE_ACK or
388    * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
389    */
390   struct GNUNET_MessageHeader header;
391
392 #ifdef NEW_CADET
393   /**
394    * For alignment.
395    */
396   uint32_t reserved GNUNET_PACKED;
397 #endif
398
399   /**
400    * ID of the channel
401    */
402   struct GNUNET_CADET_ChannelTunnelNumber chid;
403 };
404
405
406 #ifndef NEW_CADET
407
408 /**
409  * Message for cadet data traffic.
410  */
411 struct GNUNET_CADET_ChannelAppDataMessage
412 {
413   /**
414    * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
415    *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
416    */
417   struct GNUNET_MessageHeader header;
418
419   /**
420    * Unique ID of the payload message
421    */
422   /* NEW: struct ChannelMessageIdentifier */
423   uint32_t mid GNUNET_PACKED;
424
425   /**
426    * ID of the channel
427    */
428   struct GNUNET_CADET_ChannelTunnelNumber chid;
429
430   /**
431    * Payload follows
432    */
433 };
434
435
436 /**
437  * Message to acknowledge end-to-end data.
438  */
439 struct GNUNET_CADET_ChannelDataAckMessage
440 {
441   /**
442    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
443    */
444   struct GNUNET_MessageHeader header;
445
446   /**
447    * ID of the channel
448    */
449   struct GNUNET_CADET_ChannelTunnelNumber chid;
450
451   /**
452    * Bitfield of already-received newer messages
453    * pid +  1 @ LSB
454    * pid + 64 @ MSB
455    */
456   uint64_t futures GNUNET_PACKED;
457
458   /**
459    * Last message ID received.
460    */
461   /* NEW: struct ChannelMessageIdentifier */
462   uint32_t mid GNUNET_PACKED;
463 };
464
465 #else
466
467
468 /**
469  * Number used to uniquely identify messages in a CADET Channel.
470  */
471 struct ChannelMessageIdentifier
472 {
473   /**
474    * Unique ID of the message, cycles around, in NBO.
475    */
476   uint32_t mid GNUNET_PACKED;
477 };
478
479
480 /**
481  * Message for cadet data traffic.
482  */
483 struct GNUNET_CADET_ChannelAppDataMessage
484 {
485   /**
486    * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
487    *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
488    */
489   struct GNUNET_MessageHeader header;
490
491   /**
492    * Unique ID of the payload message.
493    */
494   struct ChannelMessageIdentifier mid;
495
496   /**
497    * ID of the channel
498    */
499   struct GNUNET_CADET_ChannelTunnelNumber gid;
500
501   /**
502    * Payload follows
503    */
504 };
505
506
507 /**
508  * Message to acknowledge end-to-end data.
509  */
510 struct GNUNET_CADET_ChannelDataAckMessage
511 {
512   /**
513    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
514    */
515   struct GNUNET_MessageHeader header;
516
517   /**
518    * ID of the channel
519    */
520   struct GNUNET_CADET_ChannelTunnelNumber gid;
521
522   /**
523    * Bitfield of already-received messages past @e mid.
524    * pid +  1 @ LSB
525    * pid + 64 @ MSB
526    */
527   uint64_t futures GNUNET_PACKED;
528
529   /**
530    * Last message ID received.
531    */
532   struct ChannelMessageIdentifier mid;
533 };
534
535
536 #endif
537
538 GNUNET_NETWORK_STRUCT_END
539
540 #if 0                           /* keep Emacsens' auto-indent happy */
541 {
542 #endif
543 #ifdef __cplusplus
544 }
545 #endif
546
547 /* ifndef CADET_PROTOCOL_H */
548 #endif
549 /* end of cadet_protocol.h */