clean up for configs
[oweals/gnunet.git] / src / mesh / mesh_protocol.h
index 38c57607bb44a125548b6c8a8141ee5be6dba0f9..c36fa9f93e7e0081a8da36afafac84b7d902645b 100644 (file)
 #ifndef MESH_PROTOCOL_H_
 #define MESH_PROTOCOL_H_
 
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "mesh.h"
+
 #ifdef __cplusplus
+
+struct GNUNET_MESH_TunnelMessage;
 extern "C"
 {
 #if 0
@@ -35,10 +41,6 @@ extern "C"
 #endif
 #endif
 
-#define MESH_TUNNEL_OPT_SPEED_MIN       0x1
-#define MESH_TUNNEL_OPT_NOBUFFER        0x2
-
-
 /******************************************************************************/
 /********************      MESH NETWORK MESSAGES     **************************/
 /******************************************************************************/
@@ -46,33 +48,23 @@ extern "C"
 GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
- * Message for mesh path management
+ * Message for mesh connection creation.
+ * TODO onionify path, add random tunnel ID
  */
-struct GNUNET_MESH_ManipulatePath
+struct GNUNET_MESH_ConnectionCreate
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DESTROY]
+     * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE
      *
      * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
-     *       path_length * sizeof (struct GNUNET_PeerIdentity)
+     *              path_length * sizeof (struct GNUNET_PeerIdentity)
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * Global id of the tunnel this path belongs to,
-     * unique in conjunction with the origin.
-     */
-  uint32_t tid GNUNET_PACKED;
-
-    /**
-     * Tunnel options (MESH_TUNNEL_OPT_*).
-     */
-  uint32_t opt GNUNET_PACKED;
-
-    /**
-     * 64 bit alignment padding.
+     * ID of the connection
      */
-  uint32_t reserved GNUNET_PACKED;
+  struct GNUNET_HashCode cid;
 
     /**
      * path_length structs defining the *whole* path from the origin [0] to the
@@ -82,198 +74,349 @@ struct GNUNET_MESH_ManipulatePath
 };
 
 /**
- * Message for mesh data traffic to all tunnel targets.
+ * Message for ack'ing a connection
  */
-struct GNUNET_MESH_Multicast
+struct GNUNET_MESH_ConnectionACK
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_MULTICAST
+     * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * TID of the tunnel
+     * Always 0.
      */
-  uint32_t tid GNUNET_PACKED;
+  uint32_t reserved GNUNET_PACKED;
 
     /**
-     * Number of hops to live
+     * ID of the connection.
      */
-  uint32_t ttl GNUNET_PACKED;
+  struct GNUNET_HashCode cid;
+
+  /* TODO: signature */
+};
+
 
+/**
+ * Message for encapsulation of a Key eXchange message in a connection.
+ */
+struct GNUNET_MESH_KX
+{
     /**
-     * Unique ID of the packet
+     * Type: GNUNET_MESSAGE_TYPE_MESH_KX.
      */
-  uint32_t pid GNUNET_PACKED;
+  struct GNUNET_MessageHeader header;
 
     /**
-     * OID of the tunnel
+     * Always 0.
      */
-  struct GNUNET_PeerIdentity oid;
+  uint32_t reserved GNUNET_PACKED;
 
     /**
-     * Payload follows
+     * ID of the connection.
      */
+  struct GNUNET_HashCode cid;
+
+  /* Specific KX message follows. */
 };
 
 
 /**
- * Message for mesh data traffic to a particular destination from origin.
+ * 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.
  */
-struct GNUNET_MESH_Unicast
+struct GNUNET_MESH_KX_Ephemeral
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST
-     */
+
+  /**
+   * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_EPHEMERAL.
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * TID of the tunnel
-     */
-  uint32_t tid GNUNET_PACKED;
+  /**
+   * Status of the sender (should be in "enum PeerStateMachine"), nbo.
+   */
+  int32_t sender_status GNUNET_PACKED;
 
-    /**
-     * Number of hops to live
-     */
-  uint32_t ttl GNUNET_PACKED;
+  /**
+   * An ECC signature of the 'origin' asserting the validity of
+   * the given ephemeral key.
+   */
+  struct GNUNET_CRYPTO_EddsaSignature signature;
 
-    /**
-     * Unique ID of the packet
-     */
-  uint32_t pid GNUNET_PACKED;
+  /**
+   * Information about what is being signed.
+   */
+  struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
 
-    /**
-     * OID of the tunnel
-     */
-  struct GNUNET_PeerIdentity oid;
+  /**
+   * At what time was this key created (beginning of validity).
+   */
+  struct GNUNET_TIME_AbsoluteNBO creation_time;
 
-    /**
-     * Destination.
-     */
-  struct GNUNET_PeerIdentity destination;
+  /**
+   * When does the given ephemeral key expire (end of validity).
+   */
+  struct GNUNET_TIME_AbsoluteNBO expiration_time;
 
-    /**
-     * Payload follows
-     */
+  /**
+   * 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;
 };
 
 
 /**
- * Message for mesh data traffic from a tunnel participant to origin.
+ * We're sending an (encrypted) PING to the other peer to check if he
+ * can decrypt.  The other peer should respond with a PONG with the
+ * same content, except this time encrypted with the receiver's key.
  */
-struct GNUNET_MESH_ToOrigin
+struct GNUNET_MESH_KX_Ping
 {
-    /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
-     */
+  /**
+   * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PING.
+   */
   struct GNUNET_MessageHeader header;
 
-    /**
-     * TID of the tunnel
-     */
-  uint32_t tid GNUNET_PACKED;
+  /**
+   * Seed for the IV
+   */
+  uint32_t iv GNUNET_PACKED;
 
-    /**
-     * Number of hops to live
-     */
-  uint32_t ttl GNUNET_PACKED;
+  /**
+   * Intended target of the PING, used primarily to check
+   * that decryption actually worked.
+   */
+  struct GNUNET_PeerIdentity target;
 
-    /**
-     * Unique ID of the packet
-     */
+  /**
+   * Random number chosen to make reply harder.
+   */
+  uint32_t nonce GNUNET_PACKED;
+};
+
+
+/**
+ * Response to a PING.  Includes data from the original PING.
+ */
+struct GNUNET_MESH_KX_Pong
+{
+  /**
+   * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PONG.
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Seed for the IV
+   */
+  uint32_t iv GNUNET_PACKED;
+
+  /**
+   * Same nonce as in the reve.
+   */
+  uint32_t nonce GNUNET_PACKED;
+};
+
+
+/**
+ * Tunnel(ed) message.
+ */
+struct GNUNET_MESH_Encrypted
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Initialization Vector for payload encryption.
+   */
+  uint32_t iv GNUNET_PACKED;
+
+  /**
+   * ID of the connection.
+   */
+  struct GNUNET_HashCode cid;
+
+  /**
+   * ID of the packet (hop by hop).
+   */
   uint32_t pid GNUNET_PACKED;
 
-    /**
-     * OID of the tunnel
-     */
-  struct GNUNET_PeerIdentity oid;
+  /**
+   * Number of hops to live.
+   */
+  uint32_t ttl GNUNET_PACKED;
 
-    /**
-     * Sender of the message.
-     */
-  struct GNUNET_PeerIdentity sender;
+  /**
+   * Encrypted content follows.
+   */
+};
 
-    /**
-     * Payload follows
-     */
+struct GNUNET_MESH_ChannelCreate
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * ID of the channel
+   */
+  MESH_ChannelNumber chid GNUNET_PACKED;
+
+  /**
+   * Destination port.
+   */
+  uint32_t port GNUNET_PACKED;
+
+  /**
+   * Channel options.
+   */
+  uint32_t opt GNUNET_PACKED;
 };
 
+struct GNUNET_MESH_ChannelManage
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|NACK|DESTROY}
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * ID of the channel
+   */
+  MESH_ChannelNumber chid GNUNET_PACKED;
+};
 
 /**
- * Message to acknowledge mesh data traffic.
+ * Message for mesh data traffic.
  */
-struct GNUNET_MESH_ACK
+struct GNUNET_MESH_Data
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_ACK
+     * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST,
+     *       GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * TID of the tunnel
+     * Unique ID of the payload message
      */
-  uint32_t tid GNUNET_PACKED;
+  uint32_t mid GNUNET_PACKED;
 
     /**
-     * OID of the tunnel
+     * ID of the channel
      */
-  struct GNUNET_PeerIdentity oid;
+  MESH_ChannelNumber chid GNUNET_PACKED;
 
     /**
-     * Maximum packet ID authorized.
+     * Payload follows
      */
-  uint32_t pid;
+};
+
+
+/**
+ * Message to acknowledge end-to-end data.
+ */
+struct GNUNET_MESH_DataACK
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * ID of the channel
+   */
+  MESH_ChannelNumber chid GNUNET_PACKED;
 
+  /**
+   * Bitfield of already-received newer messages
+   * pid +  1 @ LSB
+   * pid + 64 @ MSB
+   */
+  uint64_t futures GNUNET_PACKED;
+
+  /**
+   * Last message ID received.
+   */
+  uint32_t mid GNUNET_PACKED;
 };
 
+
 /**
- * Message for ack'ing a path
+ * Message to acknowledge mesh encrypted traffic.
  */
-struct GNUNET_MESH_PathACK
+struct GNUNET_MESH_ACK
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_ACK
+     * Type: GNUNET_MESSAGE_TYPE_MESH_ACK
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * TID of the tunnel
+     * Maximum packet ID authorized.
      */
-  uint32_t tid GNUNET_PACKED;
+  uint32_t ack GNUNET_PACKED;
 
     /**
-     * OID of the tunnel
+     * ID of the connection.
      */
-  struct GNUNET_PeerIdentity oid;
+  struct GNUNET_HashCode cid;
+};
+
+
+/**
+ * Message to query a peer about its Flow Control status regarding a tunnel.
+ */
+struct GNUNET_MESH_Poll
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_POLL
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Last packet sent.
+   */
+  uint32_t pid GNUNET_PACKED;
 
     /**
-     * ID of the endpoint
+     * ID of the connection.
      */
-  struct GNUNET_PeerIdentity peer_id;
+  struct GNUNET_HashCode cid;
 
-  /* TODO: signature */
 };
 
 
 /**
  * Message for notifying a disconnection in a path
  */
-struct GNUNET_MESH_PathBroken
+struct GNUNET_MESH_ConnectionBroken
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN
+     * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * TID of the tunnel
+     * Always 0.
      */
-  uint32_t tid GNUNET_PACKED;
+  uint32_t reserved GNUNET_PACKED;
 
     /**
-     * OID of the tunnel
+     * ID of the connection.
      */
-  struct GNUNET_PeerIdentity oid;
+  struct GNUNET_HashCode cid;
 
     /**
      * ID of the endpoint
@@ -290,48 +433,48 @@ struct GNUNET_MESH_PathBroken
 
 
 /**
- * Message to destroy a tunnel
+ * Message to destroy a connection.
  */
-struct GNUNET_MESH_TunnelDestroy
+struct GNUNET_MESH_ConnectionDestroy
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY
+     * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * TID of the tunnel
+     * Always 0.
      */
-  uint32_t tid GNUNET_PACKED;
+  uint32_t reserved GNUNET_PACKED;
 
     /**
-     * OID of the tunnel
+     * ID of the connection.
      */
-  struct GNUNET_PeerIdentity oid;
+  struct GNUNET_HashCode cid;
 
   /* TODO: signature */
 };
 
 
 /**
- * Message to destroy a tunnel
+ * Message to keep a connection alive.
  */
-struct GNUNET_MESH_TunnelKeepAlive
+struct GNUNET_MESH_ConnectionKeepAlive
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE
+   * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE
    */
   struct GNUNET_MessageHeader header;
-  
+
   /**
-   * TID of the tunnel
+   * Always 0.
    */
-  uint32_t tid GNUNET_PACKED;
-  
+  uint32_t reserved GNUNET_PACKED;
+
   /**
-   * OID of the tunnel
+   * ID of the connection.
    */
-  struct GNUNET_PeerIdentity oid;
+  struct GNUNET_HashCode cid;
 };