Don't pass NULL to destroy_route
[oweals/gnunet.git] / src / cadet / cadet_protocol.h
index 070be3e28d57990a58f9097c55502d52160e33d3..d2426addbd67cad26531acdea192034093c3f244 100644 (file)
@@ -67,9 +67,12 @@ struct GNUNET_CADET_ConnectionCreateMessage
   struct GNUNET_MessageHeader header;
 
   /**
-   * For alignment.
+   * Connection options in network byte order.
+   * #GNUNET_CADET_OPTION_DEFAULT for buffered;
+   * #GNUNET_CADET_OPTION_NOBUFFER for unbuffered.
+   * Other flags are ignored and should not be set at this level.
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t options GNUNET_PACKED;
 
   /**
    * ID of the connection
@@ -87,7 +90,7 @@ struct GNUNET_CADET_ConnectionCreateMessage
 /**
  * Message for ack'ing a connection
  */
-struct GNUNET_CADET_ConnectionCreateMessageAckMessage
+struct GNUNET_CADET_ConnectionCreateAckMessage
 {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
@@ -205,7 +208,9 @@ enum GNUNET_CADET_KX_Flags {
 struct GNUNET_CADET_TunnelKeyExchangeMessage
 {
   /**
-   * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX.
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
+   * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
+   * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
    */
   struct GNUNET_MessageHeader header;
 
@@ -234,17 +239,57 @@ struct GNUNET_CADET_TunnelKeyExchangeMessage
    */
   struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
 
-#ifdef NEW_CADET
+};
+
+
+/**
+ * Message for a Key eXchange for a tunnel, with authentication.
+ * Used as a response to the initial KX as well as for rekeying.
+ */
+struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
+{
+
   /**
-   * Proof that sender could compute the 3-DH, in lieu of a signature.
+   * Message header with key material.
    */
-  struct GNUNET_HashCode triple_dh_proof;
-#endif
+  struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
+
+  /**
+   * KDF-proof that sender could compute the 3-DH, used in lieu of a
+   * signature or payload data.
+   */
+  struct GNUNET_HashCode auth;
+
+};
+
+
+/**
+ * Encrypted axolotl header with numbers that identify which
+ * keys in which ratchet are to be used to decrypt the body.
+ */
+struct GNUNET_CADET_AxHeader
+{
+
+  /**
+   * Number of messages sent with the current ratchet key.
+   */
+  uint32_t Ns GNUNET_PACKED;
+
+  /**
+   * Number of messages sent with the previous ratchet key.
+   */
+  uint32_t PNs GNUNET_PACKED;
+
+  /**
+   * Current ratchet key.
+   */
+  struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
+
 };
 
 
 /**
- * Axolotl tunnel message.
+ * Axolotl-encrypted tunnel message with application payload.
  */
 struct GNUNET_CADET_TunnelEncryptedMessage
 {
@@ -253,10 +298,17 @@ struct GNUNET_CADET_TunnelEncryptedMessage
    */
   struct GNUNET_MessageHeader header;
 
+#if NEW_CADET
+  /**
+   * Reserved, for alignment.
+   */
+  uint32_t reserved GNUNET_PACKED;
+#else
   /**
-   * ID of the packet (hop by hop).
+   * Maximum packet ID authorized.
    */
   struct CadetEncryptedMessageIdentifier cemi;
+#endif
 
   /**
    * ID of the connection.
@@ -270,8 +322,13 @@ struct GNUNET_CADET_TunnelEncryptedMessage
    */
   struct GNUNET_ShortHashCode hmac;
 
-  /**************** AX_HEADER start ****************/
-
+  #if NEW_CADET
+  /**
+   * Axolotl-header that specifies which keys to use in which ratchet
+   * to decrypt the body that follows.
+   */
+  struct GNUNET_CADET_AxHeader ax_header;
+#else
   /**
    * Number of messages sent with the current ratchet key.
    */
@@ -286,15 +343,15 @@ struct GNUNET_CADET_TunnelEncryptedMessage
    * Current ratchet key.
    */
   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
-
-  /**************** AX_HEADER  end  ****************/
-
+#endif
   /**
    * Encrypted content follows.
    */
 };
 
 
+#ifndef NEW_CADET
+
 /**
  * Message to query a peer about its Flow Control status regarding a tunnel.
  *
@@ -345,6 +402,8 @@ struct GNUNET_CADET_ConnectionEncryptedAckMessage
   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
 };
 
+#endif
+
 
 /******************************************************************************/
 /*******************************   CHANNEL  ***********************************/
@@ -374,17 +433,19 @@ struct GNUNET_CADET_ChannelOpenMessage
   /**
    * ID of the channel within the tunnel.
    */
-  struct GNUNET_CADET_ChannelTunnelNumber chid;
+  struct GNUNET_CADET_ChannelTunnelNumber ctn;
 };
 
 
 /**
- * Message to manage a Channel (CHANNEL_CREATE_ACK, CHANNEL_DESTROY).
+ * Message to manage a Channel
+ * (#GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK,
+ * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY).
  */
 struct GNUNET_CADET_ChannelManageMessage
 {
   /**
-   * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE_ACK or
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK or
    * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
    */
   struct GNUNET_MessageHeader header;
@@ -399,7 +460,7 @@ struct GNUNET_CADET_ChannelManageMessage
   /**
    * ID of the channel
    */
-  struct GNUNET_CADET_ChannelTunnelNumber chid;
+  struct GNUNET_CADET_ChannelTunnelNumber ctn;
 };
 
 
@@ -425,7 +486,7 @@ struct GNUNET_CADET_ChannelAppDataMessage
   /**
    * ID of the channel
    */
-  struct GNUNET_CADET_ChannelTunnelNumber chid;
+  struct GNUNET_CADET_ChannelTunnelNumber ctn;
 
   /**
    * Payload follows
@@ -446,10 +507,10 @@ struct GNUNET_CADET_ChannelDataAckMessage
   /**
    * ID of the channel
    */
-  struct GNUNET_CADET_ChannelTunnelNumber chid;
+  struct GNUNET_CADET_ChannelTunnelNumber ctn;
 
   /**
-   * Bitfield of already-received newer messages
+   * Bitfield of already-received messages past @e mid.
    * pid +  1 @ LSB
    * pid + 64 @ MSB
    */
@@ -483,8 +544,7 @@ struct ChannelMessageIdentifier
 struct GNUNET_CADET_ChannelAppDataMessage
 {
   /**
-   * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
-   *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
+   * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
    */
   struct GNUNET_MessageHeader header;
 
@@ -496,7 +556,7 @@ struct GNUNET_CADET_ChannelAppDataMessage
   /**
    * ID of the channel
    */
-  struct GNUNET_CADET_ChannelTunnelNumber chid;
+  struct GNUNET_CADET_ChannelTunnelNumber ctn;
 
   /**
    * Payload follows
@@ -517,17 +577,19 @@ struct GNUNET_CADET_ChannelDataAckMessage
   /**
    * ID of the channel
    */
-  struct GNUNET_CADET_ChannelTunnelNumber chid;
+  struct GNUNET_CADET_ChannelTunnelNumber ctn;
 
   /**
-   * Bitfield of already-received messages past @e mid.
-   * pid +  1 @ LSB
-   * pid + 64 @ MSB
+   * Bitfield of already-received newer messages.  Note that bit 0
+   * corresponds to @e mid + 1.
+   *
+   * pid +  0 @ LSB
+   * pid + 63 @ MSB
    */
   uint64_t futures GNUNET_PACKED;
 
   /**
-   * Last message ID received.
+   * Next message ID expected.
    */
   struct ChannelMessageIdentifier mid;
 };