- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_channel.h
index 3b6769132e97efb5706e3c8fc003c2e5f48d0ca1..504754148c849fa0c4f1a61a7a65d21d9cc79a65 100644 (file)
@@ -40,8 +40,8 @@ extern "C"
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
-#include "mesh_protocol_enc.h"
-#include "mesh_enc.h"
+#include "mesh_protocol.h"
+#include "mesh.h"
 
 /**
  * Struct containing all information regarding a channel to a remote client.
@@ -53,6 +53,14 @@ struct MeshChannel;
 #include "gnunet-service-mesh_local.h"
 
 
+/**
+ * Destroy a channel and free all resources.
+ *
+ * @param ch Channel to destroy.
+ */
+void
+GMCH_destroy (struct MeshChannel *ch);
+
 /**
  * Get channel ID.
  *
@@ -84,13 +92,26 @@ GMCH_get_tunnel (const struct MeshChannel *ch);
 unsigned int
 GMCH_get_buffer (struct MeshChannel *ch, int fwd);
 
+
+/**
+ * Get flow control status of end point: is client allow to send?
+ *
+ * @param ch Channel.
+ * @param fwd Is query about FWD traffic? (Request root status).
+ *
+ * @return #GNUNET_YES if client is allowed to send us data.
+ */
+int
+GMCH_get_allowed (struct MeshChannel *ch, int fwd);
+
+
 /**
  * Is the root client for this channel on this peer?
  *
  * @param ch Channel.
  * @param fwd Is this for fwd traffic?
  *
- * @return GNUNET_YES in case it is.
+ * @return #GNUNET_YES in case it is.
  */
 int
 GMCH_is_origin (struct MeshChannel *ch, int fwd);
@@ -101,7 +122,7 @@ GMCH_is_origin (struct MeshChannel *ch, int fwd);
  * @param ch Channel.
  * @param fwd Is this for fwd traffic?
  *
- * @return GNUNET_YES in case it is.
+ * @return #GNUNET_YES in case it is.
  */
 int
 GMCH_is_terminal (struct MeshChannel *ch, int fwd);
@@ -115,22 +136,7 @@ GMCH_is_terminal (struct MeshChannel *ch, int fwd);
  * @param fwd Is for FWD traffic? (ACK dest->owner)
  */
 void
-GMCH_send_ack (struct MeshChannel *ch, int fwd);
-
-/**
- * Send data on a channel.
- *
- * If the destination is local, send it to client, otherwise encrypt and
- * send to next hop.
- *
- * @param ch Channel
- * @param msg Message.
- * @param fwd Is this a fwd (root->dest) message?
- */
-void
-GMCH_send_data (struct MeshChannel *ch,
-                const struct GNUNET_MESH_Data *msg,
-                int fwd);
+GMCH_send_data_ack (struct MeshChannel *ch, int fwd);
 
 /**
  * Notify the destination client that a new incoming channel was created.
@@ -141,12 +147,13 @@ void
 GMCH_send_create (struct MeshChannel *ch);
 
 /**
- * Notify a client that the channel is no longer valid.
+ * Allow a client to send us more data, in case it was choked.
  *
- * @param ch Channel that is destroyed.
+ * @param ch Channel.
+ * @param fwd Is this about FWD traffic? (Root client).
  */
 void
-GMCH_send_destroy (struct MeshChannel *ch);
+GMCH_allow_client (struct MeshChannel *ch, int fwd);
 
 /**
  * Log channel info.
@@ -175,6 +182,8 @@ GMCH_handle_local_ack (struct MeshChannel *ch, int fwd);
  * in the tunnel.
  *
  * @param ch Channel.
+ * @param c Client which sent the data.
+ * @param message Message.
  * @param fwd Is this a FWD data?
  *
  * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error.
@@ -192,10 +201,12 @@ GMCH_handle_local_data (struct MeshChannel *ch,
  *
  * @param ch Channel.
  * @param c Client that requested the destruction (to avoid notifying him).
+ * @param is_root Is the request coming from root?
  */
 void
 GMCH_handle_local_destroy (struct MeshChannel *ch,
-                           struct MeshClient *c);
+                           struct MeshClient *c,
+                           int is_root);
 
 /**
  * Handle a channel create requested by a client.
@@ -215,8 +226,11 @@ GMCH_handle_local_create (struct MeshClient *c,
  * Handler for mesh network payload traffic.
  *
  * @param ch Channel for the message.
- * @param message Unencryted data message.
- * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
+ * @param msg Unencryted data message.
+ * @param fwd Is this message fwd? This only is meaningful in loopback channels.
+ *            #GNUNET_YES if message is FWD on the respective channel (loopback)
+ *            #GNUNET_NO if message is BCK on the respective channel (loopback)
+ *            #GNUNET_SYSERR if message on a one-ended channel (remote)
  */
 void
 GMCH_handle_data (struct MeshChannel *ch,
@@ -226,9 +240,12 @@ GMCH_handle_data (struct MeshChannel *ch,
 /**
  * Handler for mesh network traffic end-to-end ACKs.
  *
- * @param t Tunnel on which we got this message.
- * @param message Data message.
- * @param fwd Is this a fwd ACK? (dest->orig)
+ * @param ch Channel on which we got this message.
+ * @param msg Data message.
+ * @param fwd Is this message fwd? This only is meaningful in loopback channels.
+ *            #GNUNET_YES if message is FWD on the respective channel (loopback)
+ *            #GNUNET_NO if message is BCK on the respective channel (loopback)
+ *            #GNUNET_SYSERR if message on a one-ended channel (remote)
  */
 void
 GMCH_handle_data_ack (struct MeshChannel *ch,
@@ -238,20 +255,34 @@ GMCH_handle_data_ack (struct MeshChannel *ch,
 /**
  * Handler for channel create messages.
  *
- * @param t Tunnel this channel is to be created in.
- * @param msg Message.
- * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
+ * Does not have fwd parameter because it's always 'FWD': channel is incoming.
+ *
+ * @param t Tunnel this channel will be in.
+ * @param msg Channel crate message.
  */
 struct MeshChannel *
-GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg,
-                    int fwd);
+GMCH_handle_create (struct MeshTunnel3 *t,
+                    const struct GNUNET_MESH_ChannelCreate *msg);
+
+/**
+ * Handler for channel NACK messages.
+ *
+ * NACK messages always go dest -> root, no need for 'fwd' or 'msg' parameter.
+ *
+ * @param ch Channel.
+ */
+void
+GMCH_handle_nack (struct MeshChannel *ch);
 
 /**
  * Handler for channel ack messages.
  *
- * @param t Tunnel this channel is to be created in.
+ * @param ch Channel this channel is to be created in.
  * @param msg Message.
- * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
+ * @param fwd Is this message fwd? This only is meaningful in loopback channels.
+ *            #GNUNET_YES if message is FWD on the respective channel (loopback)
+ *            #GNUNET_NO if message is BCK on the respective channel (loopback)
+ *            #GNUNET_SYSERR if message on a one-ended channel (remote)
  */
 void
 GMCH_handle_ack (struct MeshChannel *ch,
@@ -261,9 +292,12 @@ GMCH_handle_ack (struct MeshChannel *ch,
 /**
  * Handler for channel destroy messages.
  *
- * @param t Tunnel this channel is to be destroyed of.
+ * @param ch Channel this channel is to be destroyed of.
  * @param msg Message.
- * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
+ * @param fwd Is this message fwd? This only is meaningful in loopback channels.
+ *            #GNUNET_YES if message is FWD on the respective channel (loopback)
+ *            #GNUNET_NO if message is BCK on the respective channel (loopback)
+ *            #GNUNET_SYSERR if message on a one-ended channel (remote)
  */
 void
 GMCH_handle_destroy (struct MeshChannel *ch,
@@ -279,18 +313,22 @@ GMCH_handle_destroy (struct MeshChannel *ch,
  * On a normal channel passes the message to the tunnel for encryption and
  * sending on a connection.
  *
+ * This function DOES NOT save the message for retransmission.
+ *
  * @param message Message to send. Function makes a copy of it.
  * @param ch Channel on which this message is transmitted.
  * @param fwd Is this a fwd message?
+ * @param existing_copy This is a retransmission, don't save a copy.
  */
 void
 GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
-                            struct MeshChannel *ch, int fwd);
+                            struct MeshChannel *ch, int fwd,
+                            void *existing_copy);
 
 /**
  * Get the static string for identification of the channel.
  *
- * @param ch Channel.
+ * @param ch Channel.i
  *
  * @return Static string with the channel IDs.
  */