#include "platform.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
/**
- * 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;
struct GNUNET_MessageHeader header;
/**
- * TID of the tunnel
+ * ID of the channel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t id GNUNET_PACKED;
/**
* Payload follows
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,_PEER]
*/
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 peers in the service.
+ */
+struct GNUNET_MESH_LocalInfoPeer
+{
/**
- * ID of the destination of the tunnel (can be local peer).
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER[S]
*/
- struct GNUNET_PeerIdentity destination;
-};
+ struct GNUNET_MessageHeader header;
+ /**
+ * Number of paths.
+ */
+ uint16_t paths GNUNET_PACKED;
-GNUNET_NETWORK_STRUCT_END
+ /**
+ * Do we have a tunnel toward this peer?
+ */
+ int16_t tunnel GNUNET_PACKED;
-/******************************************************************************/
-/************************ ENUMERATIONS ****************************/
-/******************************************************************************/
+ /**
+ * 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) */
+};
/**
- * All the states a tunnel can be in.
+ * Message to inform the client about one of the tunnels in the service.
*/
-enum MeshTunnelState
+struct GNUNET_MESH_LocalInfoTunnel
{
- /**
- * Uninitialized status, should never appear in operation.
- */
- MESH_TUNNEL_NEW,
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL[S]
+ */
+ struct GNUNET_MessageHeader header;
- /**
- * Path to the peer not known yet
- */
- MESH_TUNNEL_SEARCHING,
+ /**
+ * Number of channels.
+ */
+ uint32_t channels GNUNET_PACKED;
- /**
- * Request sent, not yet answered.
- */
- MESH_TUNNEL_WAITING,
+ /**
+ * ID of the destination of the tunnel (can be local peer).
+ */
+ struct GNUNET_PeerIdentity destination;
- /**
- * Peer connected and ready to accept data
- */
- MESH_TUNNEL_READY,
+ /**
+ * Number of connections.
+ */
+ uint32_t connections GNUNET_PACKED;
- /**
- * Peer connected previosly but not responding
- */
- MESH_TUNNEL_RECONNECTING
+ /**
+ * 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] */
};
+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.
*
* @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);
/**
* @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);
/**
* @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);
+
+/**
+ * Get a string from a Mesh Hash (256 bits).
+ * WARNING: Not reentrant (based on GNUNET_h2s).
+ */
+const char *
+GM_h2s (const struct GNUNET_MeshHash *id);
+
/**
* Convert a message type into a string to help debug
* Generated with:
* @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 */
{