- fix peer to notify
[oweals/gnunet.git] / src / mesh / mesh.h
index f3abef8ca37b5cc9511067f2f1914f49109ae16d..42d3e6462d4a5c0fab04491d38656344123fd8e7 100644 (file)
@@ -39,7 +39,6 @@ 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"
@@ -90,6 +89,17 @@ struct GNUNET_MESH_ClientConnect
 typedef uint32_t MESH_ChannelNumber;
 
 
+/**
+ * Hash to be used in Mesh communication. Only 256 bits needed,
+ * instead of the 512 from @c GNUNET_HashCode.
+ *
+ */
+struct GNUNET_MeshHash
+{
+  unsigned char bits[256 / 8];
+};
+
+
 /**
  * Message for a client to create and destroy channels.
  */
@@ -167,10 +177,10 @@ struct GNUNET_MESH_LocalAck
 /**
  * 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,_PEER]
    */
   struct GNUNET_MessageHeader header;
 
@@ -180,19 +190,83 @@ struct GNUNET_MESH_LocalMonitor
   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 channel (can be local peer).
+   * ID of the destination of the channel (can be local peer).
+   */
+  struct GNUNET_PeerIdentity peer;
+};
+
+
+/**
+ * Message to inform the client about one of the peers in the service.
+ */
+struct GNUNET_MESH_LocalInfoPeer
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER[S]
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Number of paths.
    */
-  struct GNUNET_PeerIdentity owner;
+  uint16_t paths GNUNET_PACKED;
 
   /**
-   * ID of the destination of the channel (can be local peer).
+   * Do we have a tunnel toward this peer?
+   */
+  int16_t tunnel GNUNET_PACKED;
+
+  /**
+   * ID of the destination of the tunnel (can be local peer).
+   */
+  struct GNUNET_PeerIdentity destination;
+
+  /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
+   * (each path ends in destination) */
+};
+
+/**
+ * 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;
+
+  /**
+   * Encryption state.
+   */
+  uint16_t estate GNUNET_PACKED;
+
+  /**
+   * Connection state.
+   */
+  uint16_t cstate GNUNET_PACKED;
+
+  /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */
+  /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
 };
 
 
@@ -200,6 +274,17 @@ GNUNET_NETWORK_STRUCT_END
 
 
 
+/**
+ * @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);
+
+
 /**
  * Check if one pid is bigger than other, accounting for overflow.
  *
@@ -209,7 +294,7 @@ GNUNET_NETWORK_STRUCT_END
  * @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);
 
 
 /**
@@ -221,7 +306,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);
 
 
 /**
@@ -233,8 +318,19 @@ 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);
+
 
+/**
+ * Convert a 256 bit MeshHash into a 512 HashCode to use in GNUNET_h2s,
+ * multihashmap, and other HashCode-based functions.
+ *
+ * @param id A 256 bit hash to expand.
+ *
+ * @return A HashCode containing the original 256 bit hash right-padded with 0.
+ */
+const struct GNUNET_HashCode *
+GM_h2hc (const struct GNUNET_MeshHash *id);
 
 /**
  * Convert a message type into a string to help debug
@@ -247,7 +343,7 @@ GMC_min_pid (uint32_t a, uint32_t b);
  * @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 */
 {