-only notify AFTER sending is really close to finished, not before
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_tunnel.h
index c31ed8e3bf7a6a3b31f7db6050832b482b488e07..d4be562a2556c99e3990895b248b2595e6d193b9 100644 (file)
@@ -65,11 +65,6 @@ enum MeshTunnel3State
      */
   MESH_TUNNEL3_KEY_SENT,
 
-    /**
-     * Have peer's key, sent ping, waiting for pong.
-     */
-  MESH_TUNNEL3_PING_SENT,
-
     /**
      * Peer connected and ready to accept data.
      */
@@ -82,6 +77,8 @@ enum MeshTunnel3State
 
     /**
      * New ephemeral key and ping sent, waiting for pong.
+     * This means that we DO have the peer's ephemeral key, otherwise the
+     * state would be KEY_SENT.
      */
   MESH_TUNNEL3_REKEY,
 };
@@ -96,6 +93,24 @@ struct MeshTunnel3;
 #include "gnunet-service-mesh_connection.h"
 #include "gnunet-service-mesh_peer.h"
 
+/**
+ * Handle for messages queued but not yet sent.
+ */
+struct MeshTunnel3Queue;
+
+/**
+ * Callback called when a queued message is sent.
+ *
+ * @param cls Closure.
+ * @param t Tunnel this message was on.
+ * @param type Type of message sent.
+ * @param size Size of the message.
+ */
+typedef void (*GMT_sent) (void *cls,
+                          struct MeshTunnel3 *t,
+                          struct MeshTunnel3Queue *q,
+                          uint16_t type, size_t size);
+
 
 /******************************************************************************/
 /********************************    API    ***********************************/
@@ -220,12 +235,10 @@ GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
  *
  * @param t Tunnel this message came on.
  * @param msg Message header.
- * @param fwd Is this message fwd?
  */
 void
 GMT_handle_encrypted (struct MeshTunnel3 *t,
-                      const struct GNUNET_MESH_Encrypted *msg,
-                      int fwd);
+                      const struct GNUNET_MESH_Encrypted *msg);
 
 /**
  * Demultiplex an encapsulated KX message by message type.
@@ -281,17 +294,24 @@ enum MeshTunnel3State
 GMT_get_state (struct MeshTunnel3 *t);
 
 /**
- * Get the total buffer space for a tunnel.
- * 
- * FIXME get a ch parameter in case of loopback tunnels
+ * Get the maximum buffer space for a tunnel towards a local client.
+ *
+ * @param t Tunnel.
+ *
+ * @return Biggest buffer space offered by any channel in the tunnel.
+ */
+unsigned int
+GMT_get_channels_buffer (struct MeshTunnel3 *t);
+
+/**
+ * Get the total buffer space for a tunnel for P2P traffic.
  *
  * @param t Tunnel.
- * @param fwd Is this for FWD traffic?
  *
  * @return Buffer space offered by all connections in the tunnel.
  */
 unsigned int
-GMT_get_buffer (struct MeshTunnel3 *t, int fwd);
+GMT_get_connections_buffer (struct MeshTunnel3 *t);
 
 /**
  * Get the tunnel's destination.
@@ -317,10 +337,9 @@ GMT_get_next_chid (struct MeshTunnel3 *t);
  * Send ACK on one or more channels due to buffer in connections.
  *
  * @param t Channel which has some free buffer space.
- * @param fwd Is this for FWD traffic? (ACK goes to root)
  */
 void
-GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd);
+GMT_unchoke_channels (struct MeshTunnel3 *t);
 
 /**
  * Send ACK on one or more connections due to buffer space to the client.
@@ -328,10 +347,21 @@ GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd);
  * Iterates all connections of the tunnel and sends ACKs appropriately.
  *
  * @param t Tunnel which has some free buffer space.
- * @param fwd Is this in for FWD traffic? (ACK goes dest->root)
  */
 void
-GMT_send_acks (struct MeshTunnel3 *t, int fwd);
+GMT_send_connection_acks (struct MeshTunnel3 *t);
+
+/**
+ * Cancel a previously sent message while it's in the queue.
+ *
+ * ONLY can be called before the continuation given to the send function
+ * is called. Once the continuation is called, the message is no longer in the
+ * queue.
+ *
+ * @param q Handle to the queue.
+ */
+void
+GMT_cancel (struct MeshTunnel3Queue *q);
 
 /**
  * Sends an already built message on a tunnel, encrypting it and
@@ -340,20 +370,24 @@ GMT_send_acks (struct MeshTunnel3 *t, int fwd);
  * @param message Message to send. Function modifies it.
  * @param t Tunnel on which this message is transmitted.
  * @param ch Channel on which this message is transmitted.
- * @param fwd Is this a fwd message?
+ * @param fwd Is this a fwd message on @c ch?
+ * @param cont Continuation to call once message is really sent.
+ * @param cls Closure for @c cont.
+ *
+ * @return Handle to cancel message. NULL if @c cont is NULL.
  */
-void
+struct MeshTunnel3Queue *
 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
                            struct MeshTunnel3 *t,
-                           struct MeshChannel *ch,
-                           int fwd);
+                           struct MeshChannel *ch, int fwd,
+                           GMT_sent cont, void *cls);
 
 /**
  * Is the tunnel directed towards the local peer?
  *
  * @param t Tunnel.
  *
- * @return GNUNET_YES if it is loopback.
+ * @return #GNUNET_YES if it is loopback.
  */
 int
 GMT_is_loopback (const struct MeshTunnel3 *t);
@@ -364,7 +398,7 @@ GMT_is_loopback (const struct MeshTunnel3 *t);
  * @param t Tunnel.
  * @param p Path.
  *
- * @return GNUNET_YES a connection uses this path.
+ * @return #GNUNET_YES a connection uses this path.
  */
 int
 GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);