#ifndef MESH_H_
#define MESH_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
#include <stdint.h>
#define MESH_DEBUG GNUNET_YES
+#define INITIAL_WINDOW_SIZE 8
+#define ACK_THRESHOLD INITIAL_WINDOW_SIZE / 2
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_peer_lib.h"
#include "gnunet_core_service.h"
#include "gnunet_protocols.h"
-#include <gnunet_mesh_service_new.h>
+#include <gnunet_mesh_service.h>
/******************************************************************************/
/******************** MESH LOCAL MESSAGES *************************/
*
* tunnel_create GNUNET_MESH_TunnelMessage
* tunnel_destroy GNUNET_MESH_TunnelMessage
+ * tunnel_speed_max GNUNET_MESH_TunnelMessage
+ * tunnel_speed_min GNUNET_MESH_TunnelMessage
+ * tunnel_buffer GNUNET_MESH_TunnelMessage
*
* peer_request_connect_add GNUNET_MESH_PeerControl
* peer_request_connect_del GNUNET_MESH_PeerControl
* peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType
+ * peer_request_connect_by_string GNUNET_MESH_ConnectPeerByString
+ *
+ * peer_blacklist GNUNET_MESH_PeerControl
+ * peer_unblacklist GNUNET_MESH_PeerControl
*
- * notify_transmit_ready *GNUNET_MESH_TransmitReady?*
+ * 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_Data OR
- * GNUNET_MESH_DataBroadcast
+ * 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 GNUNET_MESH_PeerControl
* peer disconnects from a tunnel GNUNET_MESH_PeerControl
/************************** CONSTANTS ******************************/
/******************************************************************************/
-#define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
-#define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
+#define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
+#define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
+
+#define HIGH_PID 0xFFFF0000
+#define LOW_PID 0x0000FFFF
-#define CORE_QUEUE_SIZE 10
-#define LOCAL_QUEUE_SIZE 100
+#define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
/******************************************************************************/
/************************** MESSAGES ******************************/
/******************************************************************************/
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Message for a client to register to the service
*/
struct GNUNET_MessageHeader header;
uint16_t applications GNUNET_PACKED;
uint16_t types GNUNET_PACKED;
- /* uint16_t list_apps[applications] */
+ /* uint32_t list_apps[applications] */
/* uint16_t list_types[types] */
};
/**
* Type for tunnel numbering.
- * - Local tunnel numbers are >= 0x80000000
+ * - 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
*/
typedef uint32_t MESH_TunnelNumber;
{
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
+ * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN]
*
* Size: sizeof(struct GNUNET_MESH_TunnelMessage)
*/
* Peer at the other end, if any
*/
struct GNUNET_PeerIdentity peer;
+
+ /**
+ * Tunnel options (speed, buffering)
+ */
+ uint32_t opt;
};
+/**
+ * Message for announce of regular expressions.
+ */
+struct GNUNET_MESH_RegexAnnounce
+{
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX
+ *
+ * Size: sizeof(struct GNUNET_MESH_RegexAnnounce) + strlen (regex)
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * How many characters do we want to put in an edge label.
+ */
+ uint16_t compression_characters;
+
+ /**
+ * Is this the last message for this regex? (for regex > 65k)
+ */
+ int16_t last;
+
+ /* regex payload */
+};
+
+
/**
* Message for:
* - request adding and deleting peers from a tunnel
struct GNUNET_MESH_PeerControl
{
- /**
- * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL]
- * (client to service, client created tunnel)
- * GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
- * (service to client)
- *
- * Size: sizeof(struct GNUNET_MESH_PeerControl)
- */
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL|[UN]BLACKLIST]
+ * (client to service, client created tunnel)
+ * GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
+ * (service to client)
+ *
+ * Size: sizeof(struct GNUNET_MESH_PeerControl)
+ */
struct GNUNET_MessageHeader header;
- /**
- * ID of a tunnel controlled by this client.
- */
+ /**
+ * ID of a tunnel controlled by this client.
+ */
MESH_TunnelNumber tunnel_id GNUNET_PACKED;
- /**
- * Peer to connect/disconnect.
- */
+ /**
+ * Peer to connect/disconnect.
+ */
struct GNUNET_PeerIdentity peer;
};
/**
- * Message for connecting to peers offering a certain service.
+ * Message for connecting to peers offering a service, by service number.
*/
struct GNUNET_MESH_ConnectPeerByType
{
/**
* Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
* GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
+ *
+ * Size: sizeof(struct GNUNET_MESH_ConnectPeerByType)
*/
struct GNUNET_MessageHeader header;
- /**
- * ID of a tunnel controlled by this client.
- */
+ /**
+ * ID of a tunnel controlled by this client.
+ */
MESH_TunnelNumber tunnel_id GNUNET_PACKED;
- /**
- * Type specification
- */
+ /**
+ * Type specification
+ */
GNUNET_MESH_ApplicationType type GNUNET_PACKED;
};
-/******************************************************************************/
-/************************ ENUMERATIONS ****************************/
-/******************************************************************************/
-
/**
- * All the states a peer participating in a tunnel can be in.
+ * Message for connecting to peers offering a service, by service string.
*/
-enum MeshPeerState
+struct GNUNET_MESH_ConnectPeerByString
{
/**
- * Peer only retransmits traffic, is not a final destination
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING
+ *
+ * Size: sizeof(struct GNUNET_MESH_ConnectPeerByString) + strlen (string)
*/
- MESH_PEER_RELAY,
-
- /**
- * Path to the peer not known yet
- */
- MESH_PEER_SEARCHING,
-
- /**
- * Request sent, not yet answered.
- */
- MESH_PEER_WAITING,
+ struct GNUNET_MessageHeader header;
/**
- * Peer connected and ready to accept data
+ * ID of a tunnel controlled by this client.
*/
- MESH_PEER_READY,
+ MESH_TunnelNumber tunnel_id GNUNET_PACKED;
- /**
- * Peer connected previosly but not responding
- */
- MESH_PEER_RECONNECTING
+ /* String describing the service */
};
-/******************************************************************************/
-/************************ DATA STRUCTURES ****************************/
-/******************************************************************************/
-
/**
- * Information regarding a possible path to reach a single peer
+ * Message to allow the client send more data to the service
+ * (always service -> client).
*/
-struct MeshPeerPath
+struct GNUNET_MESH_LocalAck
{
-
- /**
- * Linked list
- */
- struct MeshPeerPath *next;
- struct MeshPeerPath *prev;
-
/**
- * List of all the peers that form the path from origin to target.
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
*/
- GNUNET_PEER_Id *peers;
+ struct GNUNET_MessageHeader header;
/**
- * Number of peers (hops) in the path
+ * ID of the tunnel allowed to send more data.
*/
- unsigned int length;
-
-};
-
-
-/**
- * Node of path tree for a tunnel
- */
-struct MeshTunnelPathNode
-{
- /**
- * Tunnel this node belongs to (and therefore tree)
- */
- struct MeshTunnel *t;
-
- /**
- * Peer this node describes
- */
- GNUNET_PEER_Id peer;
-
- /**
- * Parent node in the tree
- */
- struct MeshTunnelPathNode *parent;
-
- /**
- * Array of children
- */
- struct MeshTunnelPathNode *children;
-
- /**
- * Number of children
- */
- unsigned int nchildren;
+ MESH_TunnelNumber tunnel_id GNUNET_PACKED;
/**
- * Status of the peer in the tunnel
+ * ID of the last packet allowed.
*/
- enum MeshPeerState status;
+ uint32_t max_pid GNUNET_PACKED;
};
/**
- * Tree to reach all peers in the tunnel
+ * Message to inform the client about tunnels in the service.
*/
-struct MeshTunnelPath
+struct GNUNET_MESH_LocalMonitor
{
/**
- * How often to refresh the path
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
*/
- struct GNUNET_TIME_Relative refresh;
+ struct GNUNET_MessageHeader header;
/**
- * Tunnel this path belongs to
+ * ID of the tunnel allowed to send more data.
*/
- struct MeshTunnel *t;
+ MESH_TunnelNumber tunnel_id GNUNET_PACKED;
/**
- * Root node of peer tree
+ * Number of peers in the tunnel.
*/
- struct MeshTunnelPathNode *root;
+ uint32_t npeers GNUNET_PACKED;
/**
- * Node that represents our position in the tree (for non local tunnels)
+ * Alignment.
*/
- struct MeshTunnelPathNode *me;
+ uint32_t reserved GNUNET_PACKED;
/**
- * Cache of all peers and the first hop to them.
- * Indexed by Peer_Identity, contains a pointer to the PeerIdentity
- * of 1st hop.
+ * ID of the owner of the tunnel (can be local peer).
*/
- struct GNUNET_CONTAINER_MultiHashMap *first_hops;
+ struct GNUNET_PeerIdentity owner;
+ /* struct GNUNET_PeerIdentity peers[npeers] */
};
-/** FWD declaration */
-struct MeshPeerInfo;
-
-/**
- * Struct containing all info possibly needed to build a package when called
- * back by core.
- */
-struct MeshDataDescriptor
-{
- /** ID of the tunnel this packet travels in */
- struct MESH_TunnelID *origin;
-
- /** Ultimate destination of the packet */
- GNUNET_PEER_Id destination;
-
- /** Number of identical messages sent to different hops (multicast) */
- unsigned int copies;
-
- /** Size of the data */
- size_t size;
-
- /** Client that asked for the transmission, if any */
- struct GNUNET_SERVER_Client *client;
-
- /** Who was is message being sent to */
- struct MeshPeerInfo *peer;
-
- /** Which handler was used to request the transmission */
- unsigned int handler_n;
-
- /* Data at the end */
-};
+GNUNET_NETWORK_STRUCT_END
+/******************************************************************************/
+/************************ ENUMERATIONS ****************************/
+/******************************************************************************/
/**
- * Struct containing all information regarding a given peer
+ * All the states a peer participating in a tunnel can be in.
*/
-struct MeshPeerInfo
+enum MeshPeerState
{
/**
- * ID of the peer
- */
- GNUNET_PEER_Id id;
-
- /**
- * Last time we heard from this peer
+ * Uninitialized status, should never appear in operation.
*/
- struct GNUNET_TIME_Absolute last_contact;
+ MESH_PEER_INVALID,
/**
- * Number of attempts to reconnect so far
+ * Peer is the root and owner of the tree
*/
- int n_reconnect_attempts;
+ MESH_PEER_ROOT,
/**
- * Paths to reach the peer, ordered by ascending hop count
- */
- struct MeshPeerPath *path_head;
-
- /**
- * Paths to reach the peer, ordered by ascending hop count
- */
- struct MeshPeerPath *path_tail;
-
- /**
- * Handle to stop the DHT search for a path to this peer
+ * Peer only retransmits traffic, is not a final destination
*/
- struct GNUNET_DHT_GetHandle *dhtget;
+ MESH_PEER_RELAY,
/**
- * Handles to stop queued transmissions for this peer
+ * Path to the peer not known yet
*/
- struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE];
+ MESH_PEER_SEARCHING,
/**
- * Pointer to info stuctures used as cls for queued transmissions
+ * Request sent, not yet answered.
*/
- struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE];
+ MESH_PEER_WAITING,
/**
- * Array of tunnels this peer participates in
- * (most probably a small amount, therefore not a hashmap)
- * When the path to the peer changes, notify these tunnels to let them
- * re-adjust their path trees.
+ * Peer connected and ready to accept data
*/
- struct MeshTunnel **tunnels;
+ MESH_PEER_READY,
/**
- * Number of tunnels above
+ * Peer connected previosly but not responding
*/
- unsigned int ntunnels;
+ MESH_PEER_RECONNECTING
};
/**
- * Data scheduled to transmit (to local client or remote peer)
+ * Check if one pid is bigger than other, accounting for overflow.
+ *
+ * @param bigger Argument that should be bigger.
+ * @param smaller Argument that should be smaller.
+ *
+ * @return True if bigger (arg1) has a higher value than smaller (arg 2).
*/
-struct MeshQueue
-{
- /**
- * Double linked list
- */
- struct MeshQueue *next;
- struct MeshQueue *prev;
-
- /**
- * Target of the data (NULL if target is client)
- */
- struct MeshPeerInfo *peer;
-
- /**
- * Client to send the data to (NULL if target is peer)
- */
- struct MeshClient *client;
-
- /**
- * Size of the message to transmit
- */
- unsigned int size;
-
- /**
- * How old is the data?
- */
- struct GNUNET_TIME_Absolute timestamp;
+int
+GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
- /**
- * Data itself
- */
- struct GNUNET_MessageHeader *data;
-};
/**
- * Globally unique tunnel identification (owner + number)
- * DO NOT USE OVER THE NETWORK
+ * Get the higher ACK value out of two values, taking in account overflow.
+ *
+ * @param a First ACK value.
+ * @param b Second ACK value.
+ *
+ * @return Highest ACK value from the two.
*/
-struct MESH_TunnelID
-{
- /**
- * Node that owns the tunnel
- */
- GNUNET_PEER_Id oid;
-
- /**
- * Tunnel number to differentiate all the tunnels owned by the node oid
- * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_CLI )
- */
- MESH_TunnelNumber tid;
-};
+uint32_t
+GMC_max_pid (uint32_t a, uint32_t b);
-struct MeshClient; /* FWD declaration */
-
/**
- * Struct containing all information regarding a tunnel
- * For an intermediate node the improtant info used will be:
- * - id Tunnel unique identification
- * - paths[0] To know where to send it next
- * - metainfo: ready, speeds, accounting
+ * Get the lower ACK value out of two values, taking in account overflow.
+ *
+ * @param a First ACK value.
+ * @param b Second ACK value.
+ *
+ * @return Lowest ACK value from the two.
*/
-struct MeshTunnel
-{
- /**
- * Tunnel ID
- */
- struct MESH_TunnelID id;
-
- /**
- * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI or 0 )
- */
- MESH_TunnelNumber local_tid;
-
- /**
- * Last time the tunnel was used
- */
- struct GNUNET_TIME_Absolute timestamp;
-
- /**
- * Peers in the tunnel, indexed by PeerIdentity -> (MeshPeerInfo)
- */
- struct GNUNET_CONTAINER_MultiHashMap *peers;
-
- /**
- * Number of peers that are connected and potentially ready to receive data
- */
- unsigned int peers_ready;
-
- /**
- * Number of peers that have been added to the tunnel
- */
- unsigned int peers_total;
-
- /**
- * Client owner of the tunnel, if any
- */
- struct MeshClient *client;
-
- /**
- * Messages ready to transmit
- */
- struct MeshQueue *queue_head;
- struct MeshQueue *queue_tail;
-
- /**
- * Tunnel paths
- */
- struct MeshTunnelPath *tree;
-
- /**
- * Task to keep the used paths alive
- */
- GNUNET_SCHEDULER_TaskIdentifier path_refresh_task;
-};
+uint32_t
+GMC_min_pid (uint32_t a, uint32_t b);
/**
- * Info needed to work with tunnel paths and peers
+ * Convert a message type into a string to help debug
+ * Generated with:
+ * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
+ * REPLACE: " case \2: return "\1"; break;"
+ *
+ * @param m Message type.
+ *
+ * @return Human readable string description.
*/
-struct MeshPathInfo
-{
- /**
- * Tunnel
- */
- struct MeshTunnel *t;
-
- /**
- * Destination peer
- */
- struct MeshPeerInfo *peer;
+const char *
+GNUNET_MESH_DEBUG_M2S (uint16_t m);
- /**
- * Path itself
- */
- struct MeshPeerPath *path;
-};
-
-
-/**
- * Struct containing information about a client of the service
- */
-struct MeshClient
+#if 0 /* keep Emacsens' auto-indent happy */
{
- /**
- * Linked list
- */
- struct MeshClient *next;
- struct MeshClient *prev;
-
- /**
- * Tunnels that belong to this client, indexed by local id
- */
- struct GNUNET_CONTAINER_MultiHashMap *tunnels;
-
- /**
- * Handle to communicate with the client
- */
- struct GNUNET_SERVER_Client *handle;
-
- /**
- * Applications that this client has claimed to provide
- */
- struct GNUNET_CONTAINER_MultiHashMap *apps;
-
- /**
- * Messages that this client has declared interest in
- */
- struct GNUNET_CONTAINER_MultiHashMap *types;
-
- /**
- * Used to search peers offering a service
- */
- struct GNUNET_DHT_GetHandle *dht_get_type;
-
-#if MESH_DEBUG
- /**
- * ID of the client, for debug messages
- */
- unsigned int id;
#endif
-
-};
+#ifdef __cplusplus
+}
+#endif
#endif