- use variables to cound ch, conns
[oweals/gnunet.git] / src / mesh / mesh.h
index 38b5e966c0262cb08fdebd441178455fe99656c8..7011bd51ac6ebf495b58ef6603c064d527e22c64 100644 (file)
@@ -39,51 +39,18 @@ extern "C"
 #define MESH_DEBUG              GNUNET_YES
 
 #include "platform.h"
-#include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_peer_lib.h"
 #include "gnunet_core_service.h"
 #include "gnunet_protocols.h"
 #include <gnunet_mesh_service.h>
 
-/******************************************************************************/
-/********************        MESH LOCAL MESSAGES      *************************/
-/******************************************************************************/
-/*  Any API call should be documented in the folowing table under API CALL.
- *  Also, any message type should be documented in the following table, with the
- * associated event.
- *
- * API CALL (GNUNET_MESH_*)             MESSAGE USED
- * ------------------------             ------------
- * connect                              GNUNET_MESH_ClientConnect
- * disconnect                           None (network level disconnect)
- *
- * tunnel_create                        GNUNET_MESH_TunnelMessage
- * tunnel_destroy                       GNUNET_MESH_TunnelMessage
- * tunnel_buffer                        GNUNET_MESH_TunnelMessage
- *
- * notify_transmit_ready                None (queue / GNUNET_CLIENT_ntf_tmt_rdy)
- * notify_transmit_ready_cancel         None (clear of internal data structures)
- *
- * 
- * EVENT                                MESSAGE USED
- * -----                                ------------
- * data                                 GNUNET_MESH_Unicast OR
- *                                      GNUNET_MESH_Multicast OR
- *                                      GNUNET_MESH_ToOrigin
- * data ack                             GNUNET_MESH_LocalAck
- * 
- * new incoming tunnel                  GNUNET_MESH_PeerControl
- * peer connects to a tunnel            FIXME
- * peer disconnects from a tunnel       FIXME
- */
-
 /******************************************************************************/
 /**************************       CONSTANTS      ******************************/
 /******************************************************************************/
 
-#define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI         0x80000000
-#define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV        0xB0000000
+#define GNUNET_MESH_LOCAL_CHANNEL_ID_CLI        0x80000000
+#define GNUNET_MESH_LOCAL_CHANNEL_ID_SERV       0xB0000000
 
 #define HIGH_PID                                0xFFFF0000
 #define LOW_PID                                 0x0000FFFF
@@ -114,38 +81,38 @@ struct GNUNET_MESH_ClientConnect
 
 
 /**
- * Type for tunnel numbering.
- * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
- * - Local tunnel numbers given by the client (created) are >= 0x80000000
- * - Global tunnel numbers are < 0x80000000
+ * Type for channel numbering.
+ * - Local channel numbers given by the service (incoming) are >= 0xB0000000
+ * - Local channel numbers given by the client (created) are >= 0x80000000
+ * - Global channel numbers are < 0x80000000
  */
-typedef uint32_t MESH_TunnelNumber;
+typedef uint32_t MESH_ChannelNumber;
 
 
 /**
- * Message for a client to create and destroy tunnels.
+ * Message for a client to create and destroy channels.
  */
-struct GNUNET_MESH_TunnelMessage
+struct GNUNET_MESH_ChannelMessage
 {
     /**
      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
      *
-     * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
+     * Size: sizeof(struct GNUNET_MESH_ChannelMessage)
      */
   struct GNUNET_MessageHeader header;
 
     /**
-     * ID of a tunnel controlled by this client.
+     * ID of a channel controlled by this client.
      */
-  MESH_TunnelNumber tunnel_id GNUNET_PACKED;
+  MESH_ChannelNumber channel_id GNUNET_PACKED;
 
     /**
-     * Tunnel's peer
+     * Channel's peer
      */
   struct GNUNET_PeerIdentity peer;
 
     /**
-     * Port of the tunnel.
+     * Port of the channel.
      */
   uint32_t port GNUNET_PACKED;
 
@@ -167,9 +134,9 @@ struct GNUNET_MESH_LocalData
   struct GNUNET_MessageHeader header;
 
     /**
-     * TID of the tunnel
+     * ID of the channel
      */
-  uint32_t tid GNUNET_PACKED;
+  uint32_t id GNUNET_PACKED;
 
     /**
      * Payload follows
@@ -189,81 +156,92 @@ struct GNUNET_MESH_LocalAck
   struct GNUNET_MessageHeader header;
 
     /**
-     * ID of the tunnel allowed to send more data.
+     * ID of the channel allowed to send more data.
      */
-  MESH_TunnelNumber tunnel_id GNUNET_PACKED;
+  MESH_ChannelNumber channel_id GNUNET_PACKED;
 
 };
 
 
 /**
- * Message to inform the client about tunnels in the service.
+ * Message to inform the client about channels in the service.
  */
-struct GNUNET_MESH_LocalMonitor
+struct GNUNET_MESH_LocalInfo
 {
   /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
+     * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL]
    */
   struct GNUNET_MessageHeader header;
 
   /**
-   * ID of the tunnel allowed to send more data.
+   * ID of the channel allowed to send more data.
    */
-  MESH_TunnelNumber tunnel_id GNUNET_PACKED;
+  MESH_ChannelNumber channel_id GNUNET_PACKED;
 
   /**
-   * Alignment.
+   * ID of the owner of the channel (can be local peer).
    */
-  uint32_t reserved GNUNET_PACKED;
+//   struct GNUNET_PeerIdentity owner;
 
   /**
-   * ID of the owner of the tunnel (can be local peer).
+   * ID of the destination of the channel (can be local peer).
    */
-  struct GNUNET_PeerIdentity owner;
+  struct GNUNET_PeerIdentity peer;
+};
+
+/**
+ * Message to inform the client about one of the tunnels in the service.
+ */
+struct GNUNET_MESH_LocalInfoTunnel
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL[S]
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Number of channels.
+   */
+  uint32_t channels GNUNET_PACKED;
 
   /**
    * ID of the destination of the tunnel (can be local peer).
    */
   struct GNUNET_PeerIdentity destination;
-};
 
+  /**
+   * Number of connections.
+   */
+  uint32_t connections GNUNET_PACKED;
 
-GNUNET_NETWORK_STRUCT_END
+  /**
+   * Encryption state.
+   */
+  uint16_t estate GNUNET_PACKED;
 
-/******************************************************************************/
-/************************        ENUMERATIONS      ****************************/
-/******************************************************************************/
+  /**
+   * Connection state.
+   */
+  uint16_t cstate GNUNET_PACKED;
 
-/**
- * All the states a tunnel can be in.
- */
-enum MeshTunnelState
-{
-    /**
-     * Uninitialized status, should never appear in operation.
-     */
-  MESH_TUNNEL_NEW,
+  /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */
+  /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
+};
 
-    /**
-     * Path to the peer not known yet
-     */
-  MESH_TUNNEL_SEARCHING,
 
-    /**
-     * Request sent, not yet answered.
-     */
-  MESH_TUNNEL_WAITING,
+GNUNET_NETWORK_STRUCT_END
 
-    /**
-     * Peer connected and ready to accept data
-     */
-  MESH_TUNNEL_READY,
 
-    /**
-     * Peer connected previosly but not responding
-     */
-  MESH_TUNNEL_RECONNECTING
-};
+
+/**
+ * @brief Translate a fwd variable into a string representation, for logging.
+ *
+ * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
+ *
+ * @return String representing FWD or BCK.
+ */
+char *
+GM_f2s (int fwd);
 
 
 /**
@@ -275,7 +253,7 @@ enum MeshTunnelState
  * @return True if bigger (arg1) has a higher value than smaller (arg 2).
  */
 int
-GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
+GM_is_pid_bigger (uint32_t bigger, uint32_t smaller);
 
 
 /**
@@ -287,7 +265,7 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
  * @return Highest ACK value from the two.
  */
 uint32_t
-GMC_max_pid (uint32_t a, uint32_t b);
+GM_max_pid (uint32_t a, uint32_t b);
 
 
 /**
@@ -299,7 +277,7 @@ GMC_max_pid (uint32_t a, uint32_t b);
  * @return Lowest ACK value from the two.
  */
 uint32_t
-GMC_min_pid (uint32_t a, uint32_t b);
+GM_min_pid (uint32_t a, uint32_t b);
 
 
 /**
@@ -307,13 +285,13 @@ GMC_min_pid (uint32_t a, uint32_t b);
  * Generated with:
  * FIND:        "#define ([^ ]+)[ ]*([0-9]+)"
  * REPLACE:     "    case \2: return "\1"; break;"
- * 
+ *
  * @param m Message type.
- * 
+ *
  * @return Human readable string description.
  */
 const char *
-GNUNET_MESH_DEBUG_M2S (uint16_t m);
+GM_m2s (uint16_t m);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {