2 This file is part of GNUnet.
3 Copyright (C) 2007 - 2017 GNUnet e.V.
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.
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.
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.
22 * @file cadet/cadet_protocol.h
23 * @brief P2P messages used by CADET
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
28 #ifndef CADET_PROTOCOL_H_
29 #define CADET_PROTOCOL_H_
32 #include "gnunet_util_lib.h"
37 struct GNUNET_CADET_TunnelMessage;
41 /* keep Emacsens' auto-indent happy */
46 /******************************************************************************/
47 /******************** CADET NETWORK MESSAGES **************************/
48 /******************************************************************************/
50 GNUNET_NETWORK_STRUCT_BEGIN
53 /******************************************************************************/
54 /***************************** CONNECTION **********************************/
55 /******************************************************************************/
59 * Message for cadet connection creation.
61 struct GNUNET_CADET_ConnectionCreateMessage
64 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
66 * Size: sizeof (struct GNUNET_CADET_ConnectionCreateMessage) +
67 * path_length * sizeof (struct GNUNET_PeerIdentity)
69 struct GNUNET_MessageHeader header;
72 * Connection options in network byte order.
73 * #GNUNET_CADET_OPTION_DEFAULT for buffered;
74 * #GNUNET_CADET_OPTION_NOBUFFER for unbuffered.
75 * Other flags are ignored and should not be set at this level.
77 uint32_t options GNUNET_PACKED;
80 * ID of the connection
82 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
85 * path_length structs defining the *whole* path from the origin [0] to the
86 * final destination [path_length-1].
88 /* struct GNUNET_PeerIdentity peers[path_length]; */
93 * Message for ack'ing a connection
95 struct GNUNET_CADET_ConnectionCreateAckMessage
98 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
100 struct GNUNET_MessageHeader header;
105 uint32_t reserved GNUNET_PACKED;
108 * ID of the connection.
110 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
116 * Message for notifying a disconnection in a path
118 struct GNUNET_CADET_ConnectionBrokenMessage
121 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
123 struct GNUNET_MessageHeader header;
128 uint32_t reserved GNUNET_PACKED;
131 * ID of the connection.
133 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
138 struct GNUNET_PeerIdentity peer1;
143 struct GNUNET_PeerIdentity peer2;
148 * Message to destroy a connection.
150 struct GNUNET_CADET_ConnectionDestroyMessage
153 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
155 struct GNUNET_MessageHeader header;
160 uint32_t reserved GNUNET_PACKED;
163 * ID of the connection.
165 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
169 /******************************************************************************/
170 /******************************* TUNNEL ***********************************/
171 /******************************************************************************/
174 * Unique identifier (counter) for an encrypted message in a channel.
175 * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
176 * and #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
177 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
180 struct CadetEncryptedMessageIdentifier
183 * This number is incremented by one per message. It may wrap around.
184 * In network byte order.
186 uint32_t pid GNUNET_PACKED;
191 * Flags to be used in GNUNET_CADET_KX.
193 enum GNUNET_CADET_KX_Flags {
196 * Should the peer reply with its KX details?
198 GNUNET_CADET_KX_FLAG_NONE = 0,
201 * The peer should reply with its KX details?
203 GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
208 * Message for a Key eXchange for a tunnel.
210 struct GNUNET_CADET_TunnelKeyExchangeMessage
213 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
214 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
215 * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
217 struct GNUNET_MessageHeader header;
220 * Flags for the key exchange in NBO, based on
221 * `enum GNUNET_CADET_KX_Flags`.
223 uint32_t flags GNUNET_PACKED;
226 * ID of the connection.
228 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
231 * Sender's ephemeral public ECC key encoded in a
232 * format suitable for network transmission, as created
233 * using 'gcry_sexp_sprint'.
235 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
238 * Sender's next ephemeral public ECC key encoded in a
239 * format suitable for network transmission, as created
240 * using 'gcry_sexp_sprint'.
242 struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
248 * Message for a Key eXchange for a tunnel, with authentication.
249 * Used as a response to the initial KX as well as for rekeying.
251 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
255 * Message header with key material.
257 struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
260 * KDF-proof that sender could compute the 3-DH, used in lieu of a
261 * signature or payload data.
263 struct GNUNET_HashCode auth;
269 * Encrypted axolotl header with numbers that identify which
270 * keys in which ratchet are to be used to decrypt the body.
272 struct GNUNET_CADET_AxHeader
276 * Number of messages sent with the current ratchet key.
278 uint32_t Ns GNUNET_PACKED;
281 * Number of messages sent with the previous ratchet key.
283 uint32_t PNs GNUNET_PACKED;
286 * Current ratchet key.
288 struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
294 * Axolotl-encrypted tunnel message with application payload.
296 struct GNUNET_CADET_TunnelEncryptedMessage
299 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
301 struct GNUNET_MessageHeader header;
304 * Reserved, for alignment.
306 uint32_t reserved GNUNET_PACKED;
309 * ID of the connection.
311 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
314 * MAC of the encrypted message, used to verify message integrity.
315 * Everything after this value will be encrypted with the header key
318 struct GNUNET_ShortHashCode hmac;
321 * Axolotl-header that specifies which keys to use in which ratchet
322 * to decrypt the body that follows.
324 struct GNUNET_CADET_AxHeader ax_header;
327 * Encrypted content follows.
332 /******************************************************************************/
333 /******************************* CHANNEL ***********************************/
334 /******************************************************************************/
338 * Message to create a Channel.
340 struct GNUNET_CADET_ChannelOpenMessage
343 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
345 struct GNUNET_MessageHeader header;
350 uint32_t opt GNUNET_PACKED;
353 * Hash of destination port and listener.
355 struct GNUNET_HashCode h_port;
358 * ID of the channel within the tunnel.
360 struct GNUNET_CADET_ChannelTunnelNumber ctn;
365 * Message to acknowledge opening a channel of type
366 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
368 struct GNUNET_CADET_ChannelOpenAckMessage
371 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
373 struct GNUNET_MessageHeader header;
378 uint32_t reserved GNUNET_PACKED;
383 struct GNUNET_CADET_ChannelTunnelNumber ctn;
386 * Port number of the channel, used to prove to the
387 * initiator that the receiver knows the port.
389 struct GNUNET_HashCode port;
394 * Message to destroy a channel of type
395 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
397 struct GNUNET_CADET_ChannelDestroyMessage
400 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
402 struct GNUNET_MessageHeader header;
407 uint32_t reserved GNUNET_PACKED;
412 struct GNUNET_CADET_ChannelTunnelNumber ctn;
417 * Number used to uniquely identify messages in a CADET Channel.
419 struct ChannelMessageIdentifier
422 * Unique ID of the message, cycles around, in NBO.
424 uint32_t mid GNUNET_PACKED;
429 * Message for cadet data traffic.
431 struct GNUNET_CADET_ChannelAppDataMessage
434 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
436 struct GNUNET_MessageHeader header;
439 * Unique ID of the payload message.
441 struct ChannelMessageIdentifier mid;
446 struct GNUNET_CADET_ChannelTunnelNumber ctn;
455 * Message to acknowledge end-to-end data.
457 struct GNUNET_CADET_ChannelDataAckMessage
460 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
462 struct GNUNET_MessageHeader header;
467 struct GNUNET_CADET_ChannelTunnelNumber ctn;
470 * Bitfield of already-received newer messages. Note that bit 0
471 * corresponds to @e mid + 1.
476 uint64_t futures GNUNET_PACKED;
479 * Next message ID expected.
481 struct ChannelMessageIdentifier mid;
485 GNUNET_NETWORK_STRUCT_END
487 #if 0 /* keep Emacsens' auto-indent happy */
494 /* ifndef CADET_PROTOCOL_H */
496 /* end of cadet_protocol.h */