- add underlay api implementation
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.h
index 3a336fb37ae78261d66bcc33a3b15bcd58f76737..58386c0aa0f71502a6aecab286883dde60f9be13 100644 (file)
@@ -45,6 +45,27 @@ 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, uint16_t type,
+                          int fwd, size_t size,
+                          struct GNUNET_TIME_Relative wait);
 
 /******************************************************************************/
 /********************************    API    ***********************************/
@@ -64,22 +85,83 @@ 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 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.
+ */
+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. Might be destroyed by
+ *          the sent continuation call.
  */
 void
-GMP_queue_add (void *cls, uint16_t type, size_t size, 
-               struct MeshConnection *c,
-               struct MeshChannel *ch,
-               int fwd);
+GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c);
+
+void
+GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c);
 
 /**
  * Set tunnel.
@@ -91,15 +173,25 @@ void
 GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t);
 
 /**
- * Chech whether there is a direct (core level)  connection to peer.
+ * Check whether there is a direct (core level)  connection to peer.
  *
  * @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.
  *
@@ -115,6 +207,108 @@ GMP_is_neighbor (const struct MeshPeer *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 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.
+ */
+struct MeshPeerPath *
+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 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.
+ */
+struct MeshPeerPath *
+GMP_add_path_to_origin (struct MeshPeer *peer,
+                        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, 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.
+ *
+ * @param peer Peer to get from.
+ *
+ * @return Full ID of peer.
+ */
+const struct GNUNET_PeerIdentity *
+GMP_get_id (const struct MeshPeer *peer);
+
+/**
+ * Get the Short ID of a peer.
+ *
+ * @param peer Peer to get from.
+ *
+ * @return Short ID of 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.
  *
@@ -135,4 +329,4 @@ GMP_2s (const struct MeshPeer *peer);
 
 /* ifndef GNUNET_MESH_SERVICE_PEER_H */
 #endif
-/* end of gnunet-mesh-service_peer.h */
\ No newline at end of file
+/* end of gnunet-mesh-service_peer.h */