refactor DHT for new service API
[oweals/gnunet.git] / src / cadet / cadet_protocol.h
index d866e20d32f7fa91fb9a9565b7fe0de6cc4d0f60..2df652e3476ce1de51fa03e85e442c6deec6f136 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001 - 2011 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -52,23 +52,28 @@ GNUNET_NETWORK_STRUCT_BEGIN
  */
 struct GNUNET_CADET_ConnectionCreate
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
-     *
-     * Size: sizeof (struct GNUNET_CADET_ConnectionCreate) +
-     *       path_length * sizeof (struct GNUNET_PeerIdentity)
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
+   *
+   * Size: sizeof (struct GNUNET_CADET_ConnectionCreate) +
+   *       path_length * sizeof (struct GNUNET_PeerIdentity)
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * ID of the connection
-     */
+  /**
+   * For alignment.
+   */
+  uint32_t reserved GNUNET_PACKED;
+  
+  /**
+   * ID of the connection
+   */
   struct GNUNET_CADET_Hash cid;
 
-    /**
-     * path_length structs defining the *whole* path from the origin [0] to the
-     * final destination [path_length-1].
-     */
+  /**
+   * path_length structs defining the *whole* path from the origin [0] to the
+   * final destination [path_length-1].
+   */
   /* struct GNUNET_PeerIdentity peers[path_length]; */
 };
 
@@ -77,191 +82,95 @@ struct GNUNET_CADET_ConnectionCreate
  * Message for ack'ing a connection
  */
 struct GNUNET_CADET_ConnectionACK
-{
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK
-     */
-  struct GNUNET_MessageHeader header;
-
-    /**
-     * ID of the connection.
-     */
-  struct GNUNET_CADET_Hash cid;
-
-};
-
-
-/**
- * Message for encapsulation of a Key eXchange message in a connection.
- */
-struct GNUNET_CADET_KX
-{
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_KX.
-     */
-  struct GNUNET_MessageHeader header;
-
-    /**
-     * ID of the connection.
-     */
-  struct GNUNET_CADET_Hash cid;
-
-  /* Specific KX message follows. */
-};
-
-
-
-/**
- * Message for encapsulation of a Key eXchange message in a connection.
- */
-struct GNUNET_CADET_AX_KX
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_CADET_AX_KX.
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * Sender's ephemeral public ECC key (always for NIST P-521) encoded in a
-   * format suitable for network transmission, as created
-   * using 'gcry_sexp_sprint'.
+   * For alignment.
    */
-  struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
+  uint32_t reserved GNUNET_PACKED;
 
   /**
-   * Sender's next ephemeral public ECC key (always for NIST P-521) encoded in a
-   * format suitable for network transmission, as created
-   * using 'gcry_sexp_sprint'.
+   * ID of the connection.
    */
-  struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
+  struct GNUNET_CADET_Hash cid;
+
 };
 
 
 /**
- * Message transmitted with the signed ephemeral key of a peer.  The
- * session key is then derived from the two ephemeral keys (ECDHE).
- *
- * As far as possible, same as CORE's EphemeralKeyMessage.
+ * Message for encapsulation of a Key eXchange message in a connection.
  */
-struct GNUNET_CADET_KX_Ephemeral
+struct GNUNET_CADET_KX
 {
-
   /**
-   * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL.
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_KX.
    */
   struct GNUNET_MessageHeader header;
-
+  
   /**
-   * Status of the sender (should be in "enum PeerStateMachine"), nbo.
+   * For alignment.
    */
-  int32_t sender_status GNUNET_PACKED;
+  uint32_t reserved GNUNET_PACKED;
 
   /**
-   * An ECC signature of the 'origin' asserting the validity of
-   * the given ephemeral key.
-   */
-  struct GNUNET_CRYPTO_EddsaSignature signature;
-
-  /**
-   * Information about what is being signed.
-   */
-  struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
-
-  /**
-   * At what time was this key created (beginning of validity).
-   */
-  struct GNUNET_TIME_AbsoluteNBO creation_time;
-
-  /**
-   * When does the given ephemeral key expire (end of validity).
-   */
-  struct GNUNET_TIME_AbsoluteNBO expiration_time;
-
-  /**
-   * Ephemeral public ECC key (always for NIST P-521) encoded in a format
-   * suitable for network transmission as created using 'gcry_sexp_sprint'.
-   */
-  struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
-
-  /**
-   * Public key of the signing peer
-   * (persistent version, not the ephemeral public key).
-   */
-  struct GNUNET_PeerIdentity origin_identity;
-
-  /**
-   * Seed for the IV of nonce.
+   * ID of the connection.
    */
-  uint32_t iv GNUNET_PACKED;
+  struct GNUNET_CADET_Hash cid;
 
-  /**
-   * Nonce to check liveness of peer.
-   */
-  uint32_t nonce GNUNET_PACKED;
+  /* Specific KX message follows. */
 };
 
 
 /**
- * Response to a PING.  Includes data from the original PING.
+ * Flags to be used in GNUNET_CADET_AX_KX.
  */
-struct GNUNET_CADET_KX_Pong
-{
-  /**
-   * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_PONG.
-   */
-  struct GNUNET_MessageHeader header;
+enum GNUNET_CADET_AX_KX_Flags {
 
   /**
-   * Seed for the IV
+   * Should the peer reply with its KX details?
    */
-  uint32_t iv GNUNET_PACKED;
+  GNUNET_CADET_AX_KX_FLAG_NONE = 0,
 
   /**
-   * Same nonce as in the reve.
+   * The peer should reply with its KX details?
    */
-  uint32_t nonce GNUNET_PACKED;
+  GNUNET_CADET_AX_KX_FLAG_FORCE_REPLY = 1
 };
 
 
 /**
- * Tunnel(ed) message.
+ * Message for encapsulation of a Key eXchange message in a connection.
  */
-struct GNUNET_CADET_Encrypted
+struct GNUNET_CADET_AX_KX
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_AX_KX.
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * ID of the connection.
+   * Flags for the key exchange in NBO, based on
+   * `enum GNUNET_CADET_AX_KX_Flags`.
    */
-  struct GNUNET_CADET_Hash cid;
+  uint32_t flags GNUNET_PACKED;
 
   /**
-   * ID of the packet (hop by hop).
-   */
-  uint32_t pid GNUNET_PACKED;
-
-  /**
-   * Number of hops to live.
-   */
-  uint32_t ttl GNUNET_PACKED;
-
-  /**
-   * Initialization Vector for payload encryption.
-   */
-  uint32_t iv GNUNET_PACKED;
-
-  /**
-   * MAC of the encrypted message, used to verify message integrity.
-   * Everything after this value  will be encrypted and authenticated.
+   * Sender's ephemeral public ECC key encoded in a
+   * format suitable for network transmission, as created
+   * using 'gcry_sexp_sprint'.
    */
-  struct GNUNET_CADET_Hash hmac;
+  struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
 
   /**
-   * Encrypted content follows.
+   * Sender's next ephemeral public ECC key encoded in a
+   * format suitable for network transmission, as created
+   * using 'gcry_sexp_sprint'.
    */
+  struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
 };
 
 
@@ -271,35 +180,45 @@ struct GNUNET_CADET_Encrypted
 struct GNUNET_CADET_AX
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
    */
   struct GNUNET_MessageHeader header;
 
+  /**
+   * ID of the packet (hop by hop).
+   */
+  uint32_t pid GNUNET_PACKED;
+
   /**
    * ID of the connection.
    */
   struct GNUNET_CADET_Hash cid;
 
   /**
-   * ID of the packet (hop by hop).
+   * MAC of the encrypted message, used to verify message integrity.
+   * Everything after this value  will be encrypted with the header key
+   * and authenticated.
    */
-  uint32_t pid GNUNET_PACKED;
+  struct GNUNET_CADET_Hash hmac;
+
+  /**************** AX_HEADER start ****************/
 
   /**
-   * Number of hops to live.
+   * Number of messages sent with the current ratchet key.
    */
-  uint32_t ttl GNUNET_PACKED;
+  uint32_t Ns GNUNET_PACKED;
 
   /**
-   * Initialization Vector for payload encryption.
+   * Number of messages sent with the previous ratchet key.
    */
-  uint32_t iv GNUNET_PACKED;
+  uint32_t PNs GNUNET_PACKED;
 
   /**
-   * MAC of the encrypted message, used to verify message integrity.
-   * Everything after this value  will be encrypted and authenticated.
+   * Current ratchet key.
    */
-  struct GNUNET_CADET_Hash hmac;
+  struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
+
+  /**************** AX_HEADER  end  ****************/
 
   /**
    * Encrypted content follows.
@@ -313,24 +232,24 @@ struct GNUNET_CADET_AX
 struct GNUNET_CADET_ChannelCreate
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * ID of the channel
+   * Channel options.
    */
-  CADET_ChannelNumber chid GNUNET_PACKED;
+  uint32_t opt GNUNET_PACKED;
 
   /**
    * Destination port.
    */
-  uint32_t port GNUNET_PACKED;
+  struct GNUNET_HashCode port;
 
   /**
-   * Channel options.
+   * ID of the channel
    */
-  uint32_t opt GNUNET_PACKED;
+  CADET_ChannelNumber chid GNUNET_PACKED;
 };
 
 
@@ -340,7 +259,7 @@ struct GNUNET_CADET_ChannelCreate
 struct GNUNET_CADET_ChannelManage
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
    */
   struct GNUNET_MessageHeader header;
 
@@ -356,25 +275,25 @@ struct GNUNET_CADET_ChannelManage
  */
 struct GNUNET_CADET_Data
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_UNICAST,
-     *       GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
+   *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * Unique ID of the payload message
-     */
+  /**
+   * Unique ID of the payload message
+   */
   uint32_t mid GNUNET_PACKED;
 
-    /**
-     * ID of the channel
-     */
+  /**
+   * ID of the channel
+   */
   CADET_ChannelNumber chid GNUNET_PACKED;
 
-    /**
-     * Payload follows
-     */
+  /**
+   * Payload follows
+   */
 };
 
 
@@ -412,19 +331,19 @@ struct GNUNET_CADET_DataACK
  */
 struct GNUNET_CADET_ACK
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_ACK
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_ACK
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * Maximum packet ID authorized.
-     */
+  /**
+   * Maximum packet ID authorized.
+   */
   uint32_t ack GNUNET_PACKED;
 
-    /**
-     * ID of the connection.
-     */
+  /**
+   * ID of the connection.
+   */
   struct GNUNET_CADET_Hash cid;
 };
 
@@ -434,19 +353,19 @@ struct GNUNET_CADET_ACK
  */
 struct GNUNET_CADET_Poll
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_POLL
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_POLL
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * Last packet sent.
-     */
+  /**
+   * Last packet sent.
+   */
   uint32_t pid GNUNET_PACKED;
 
-    /**
-     * ID of the connection.
-     */
+  /**
+   * ID of the connection.
+   */
   struct GNUNET_CADET_Hash cid;
 
 };
@@ -457,24 +376,29 @@ struct GNUNET_CADET_Poll
  */
 struct GNUNET_CADET_ConnectionBroken
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * ID of the connection.
-     */
+  /**
+   * For alignment.
+   */
+  uint32_t reserved GNUNET_PACKED;
+
+  /**
+   * ID of the connection.
+   */
   struct GNUNET_CADET_Hash cid;
 
-    /**
-     * ID of the endpoint
-     */
+  /**
+   * ID of the endpoint
+   */
   struct GNUNET_PeerIdentity peer1;
 
-    /**
-     * ID of the endpoint
-     */
+  /**
+   * ID of the endpoint
+   */
   struct GNUNET_PeerIdentity peer2;
 };
 
@@ -484,14 +408,19 @@ struct GNUNET_CADET_ConnectionBroken
  */
 struct GNUNET_CADET_ConnectionDestroy
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
-     */
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * ID of the connection.
-     */
+  /**
+   * For alignment.
+   */
+  uint32_t reserved GNUNET_PACKED;
+
+  /**
+   * ID of the connection.
+   */
   struct GNUNET_CADET_Hash cid;
 };