- add underlay api implementation
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.h
index 1918a78421fb1ebbb51ddfa2ee6a47ca4ff25650..58386c0aa0f71502a6aecab286883dde60f9be13 100644 (file)
@@ -45,20 +45,28 @@ extern "C"
  */
 struct MeshPeer;
 
+/**
+ * Struct containing info about a queued transmission to this peer
+ */
+struct MeshPeerQueue;
+
+#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,
+                          struct MeshConnection *c, uint16_t type,
+                          int fwd, size_t size,
                           struct GNUNET_TIME_Relative wait);
 
-#include "gnunet-service-mesh_connection.h"
-
-
 /******************************************************************************/
 /********************************    API    ***********************************/
 /******************************************************************************/
@@ -77,31 +85,77 @@ GMP_init (const struct GNUNET_CONFIGURATION_Handle *c);
 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_id 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);
+
+/**
+ * Free a transmission that was already queued with all resources
+ * associated to the request.
+ *
+ * @param queue Queue handler to cancel.
+ * @param clear_cls Is it necessary to free associated cls?
+ */
+void
+GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls);
+
 /**
  * @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 size Size of the 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 callback Function to be called once CORE has taken the message.
- * @param callback_cls Closure for @c callback.
+ * @param cont Continuation to be called once CORE has taken the message.
+ * @param cont_cls Closure for @c cont.
+ *
+ * @return Handle to cancel the message before it is sent. Once cont is called
+ *         message has been sent and therefore the handle is no longer valid.
  */
-void
-GMP_queue_add (void *cls, uint16_t type, size_t size,
-               struct MeshConnection *c,
-               struct MeshChannel *ch,
-               int fwd,
-               GMP_sent callback, void *callback_cls);
+struct MeshPeerQueue *
+GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
+               struct MeshConnection *c, 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.
+ * @param c Connection whose queued messages to cancel. Might be destroyed by
+ *          the sent continuation call.
  */
 void
 GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c);
@@ -123,11 +177,20 @@ GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t);
  *
  * @param peer Peer to check.
  *
- * @return GNUNET_YES if there is a direct connection.
+ * @return #GNUNET_YES if there is a direct connection.
  */
 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.
@@ -148,12 +211,15 @@ 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 peer 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?
+ *
+ * @return path if path was taken, pointer to existing duplicate if exists
+ *         NULL on error.
  */
-void
+struct MeshPeerPath *
 GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
 
 /**
@@ -162,13 +228,16 @@ GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
  * 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 peer 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?
+ *
+ * @return path if path was taken, pointer to existing duplicate if exists
+ *         NULL on error.
  */
-void
-GMP_add_path_to_origin (struct MeshPeer *peer_info,
+struct MeshPeerPath *
+GMP_add_path_to_origin (struct MeshPeer *peer,
                         struct MeshPeerPath *path,
                         int trusted);
 
@@ -179,7 +248,7 @@ GMP_add_path_to_origin (struct MeshPeer *peer_info,
  * @param confirmed Whether we know if the path works or not.
  */
 void
-GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed);
+GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed);
 
 /**
  * Remove a connection from a neighboring peer.
@@ -190,11 +259,23 @@ GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed);
  * @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);
 
@@ -205,7 +286,7 @@ GMP_stop_search (struct MeshPeer *peer);
  *
  * @return Full ID of peer.
  */
-struct GNUNET_PeerIdentity *
+const struct GNUNET_PeerIdentity *
 GMP_get_id (const struct MeshPeer *peer);
 
 /**
@@ -218,6 +299,16 @@ 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.
  *