-only notify AFTER sending is really close to finished, not before
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_tunnel.h
index 6f6151ddc289cf18ebb6b9d0f9b03d2090694f24..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    ***********************************/
@@ -336,6 +351,18 @@ GMT_unchoke_channels (struct MeshTunnel3 *t);
 void
 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
  * choosing the best connection.
@@ -344,12 +371,16 @@ GMT_send_connection_acks (struct MeshTunnel3 *t);
  * @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 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?