#include "gnunet-service-mesh_connection.h"
+/**
+ * Callback called when a queued message is sent.
+ *
+ * @param cls Closure.
+ * @param c Connection this message was on.
+ * @param type Type of message sent.
+ * @param fwd Was this a FWD going message?
+ * @param size Size of the message.
+ * @param wait Time spent waiting for core (only the time for THIS message)
+ */
+typedef void (*GMP_sent) (void *cls,
+ struct MeshConnection *c, uint16_t type,
+ int fwd, size_t size,
+ struct GNUNET_TIME_Relative wait);
/******************************************************************************/
/******************************** API ***********************************/
void
GMP_shutdown (void);
+
+/**
+ * Retrieve the MeshPeer stucture associated with the peer, create one
+ * and insert it in the appropriate structures if the peer is not known yet.
+ *
+ * @param peer Full identity of the peer.
+ *
+ * @return Existing or newly created peer structure.
+ */
+struct MeshPeer *
+GMP_get (const struct GNUNET_PeerIdentity *peer_id);
+
+
+/**
+ * Retrieve the MeshPeer stucture associated with the peer, create one
+ * and insert it in the appropriate structures if the peer is not known yet.
+ *
+ * @param peer Short identity of the peer.
+ *
+ * @return Existing or newly created peer structure.
+ */
+struct MeshPeer *
+GMP_get_short (const GNUNET_PEER_Id peer);
+
+/**
+ * Try to establish a new connection to this peer (in its tunnel).
+ * If the peer doesn't have any path to it yet, try to get one.
+ * If the peer already has some path, send a CREATE CONNECTION towards it.
+ *
+ * @param peer Peer to connect to.
+ */
+void
+GMP_connect (struct MeshPeer *peer);
+
/**
* @brief Queue and pass message to core when possible.
*
+ * @param peer Peer towards which to queue the message.
* @param cls Closure (@c type dependant). It will be used by queue_send to
* build the message to be sent if not already prebuilt.
* @param type Type of the message, 0 for a raw message.
* @param c Connection this message belongs to (cannot be NULL).
* @param ch Channel this message belongs to, if applicable (otherwise NULL).
* @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
+ * @param cont Continuation to be called once CORE has taken the message.
+ * @param cont_cls Closure for @c cont.
*/
void
-GMP_queue_add (void *cls, uint16_t type, size_t size,
- struct MeshConnection *c,
- struct MeshChannel *ch,
- int fwd);
+GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
+ struct MeshConnection *c, struct MeshChannel *ch, int fwd,
+ GMP_sent cont, void *cont_cls);
+
+/**
+ * Cancel all queued messages to a peer that belong to a certain connection.
+ *
+ * @param peer Peer towards whom to cancel.
+ * @param c Connection whose queued messages to cancel.
+ */
+void
+GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c);
+
+void
+GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c);
/**
* Set tunnel.
int
GMP_is_neighbor (const struct MeshPeer *peer);
+/**
+ * Create and initialize a new tunnel towards a peer, in case it has none.
+ *
+ * Does not generate any traffic, just creates the local data structures.
+ *
+ * @param peer Peer towards which to create the tunnel.
+ */
+void
+GMP_add_tunnel (struct MeshPeer *peer);
/**
* Add a connection to a neighboring peer.
int
GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
+/**
+ * Add the path to the peer and update the path used to reach it in case this
+ * is the shortest.
+ *
+ * @param peer_info Destination peer to add the path to.
+ * @param path New path to add. Last peer must be the peer in arg 1.
+ * Path will be either used of freed if already known.
+ * @param trusted Do we trust that this path is real?
+ */
+void
+GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
+
+/**
+ * Add the path to the origin peer and update the path used to reach it in case
+ * this is the shortest.
+ * The path is given in peer_info -> destination, therefore we turn the path
+ * upside down first.
+ *
+ * @param peer_info Peer to add the path to, being the origin of the path.
+ * @param path New path to add after being inversed.
+ * Path will be either used or freed.
+ * @param trusted Do we trust that this path is real?
+ */
+void
+GMP_add_path_to_origin (struct MeshPeer *peer_info,
+ struct MeshPeerPath *path,
+ int trusted);
+
+/**
+ * Adds a path to the info of all the peers in the path
+ *
+ * @param p Path to process.
+ * @param confirmed Whether we know if the path works or not.
+ */
+void
+GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed);
+
+/**
+ * Remove a connection from a neighboring peer.
+ *
+ * @param peer Peer to remove connection from.
+ * @param c Connection to remove.
+ *
+ * @return GNUNET_OK on success.
+ */
int
-GMP_remove_connection (struct MeshPeer *peer, struct MeshConnection *c);
+GMP_remove_connection (struct MeshPeer *peer, const struct MeshConnection *c);
+
+/**
+ * Start the DHT search for new paths towards the peer: we don't have
+ * enough good connections.
+ *
+ * @param peer Destination peer.
+ */
+void
+GMP_start_search (struct MeshPeer *peer);
+
+/**
+ * Stop the DHT search for new paths towards the peer: we already have
+ * enough good connections.
+ *
+ * @param peer Destination peer.
+ */
+void
+GMP_stop_search (struct MeshPeer *peer);
/**
* Get the Full ID of a peer.
*
* @return Full ID of peer.
*/
-struct GNUNET_PeerIdentity *
+const struct GNUNET_PeerIdentity *
GMP_get_id (const struct MeshPeer *peer);
/**
GNUNET_PEER_Id
GMP_get_short_id (const struct MeshPeer *peer);
+/**
+ * Get the tunnel towards a peer.
+ *
+ * @param peer Peer to get from.
+ *
+ * @return Tunnel towards peer.
+ */
+struct MeshTunnel3 *
+GMP_get_tunnel (const struct MeshPeer *peer);
+
/**
* Get the static string for a peer ID.
*