-implementing new DNS client API
[oweals/gnunet.git] / src / include / gnunet_fragmentation_lib.h
index b2ba064f8a727c0ebbff0e33e1aa5cbab7fa26f0..a953bd2b131dc67a613f4635432748ba2b8bd343 100644 (file)
@@ -21,6 +21,9 @@
  * @file include/gnunet_fragmentation_lib.h
  * @brief library to help fragment messages
  * @author Christian Grothoff
+ *
+ * TODO: consider additional flow-control for sending from
+ *       fragmentation based on continuations.
  */
 
 #ifndef GNUNET_FRAGMENTATION_LIB_H
@@ -46,14 +49,17 @@ struct GNUNET_FRAGMENT_Context;
 
 
 /**
- * Function that is called with messages
- * created by the fragmentation module.
+ * Function that is called with messages created by the fragmentation
+ * module.  In the case of the 'proc' callback of the
+ * GNUNET_FRAGMENT_context_create function, this function must
+ * eventually call 'GNUNET_FRAGMENT_context_transmission_done'.
  *
  * @param cls closure
  * @param msg the message that was created
  */
 typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
-                                                  const struct GNUNET_MessageHeader *msg);
+                                                  const struct
+                                                  GNUNET_MessageHeader * msg);
 
 
 /**
@@ -76,12 +82,23 @@ typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
  */
 struct GNUNET_FRAGMENT_Context *
 GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
-                               uint16_t mtu,
-                               struct GNUNET_BANDWIDTH_Tracker *tracker,
-                               struct GNUNET_TIME_Relative delay,
-                               const struct GNUNET_MessageHeader *msg,
-                               GNUNET_FRAGMENT_MessageProcessor proc,
-                               void *proc_cls);
+                                uint16_t mtu,
+                                struct GNUNET_BANDWIDTH_Tracker *tracker,
+                                struct GNUNET_TIME_Relative delay,
+                                const struct GNUNET_MessageHeader *msg,
+                                GNUNET_FRAGMENT_MessageProcessor proc,
+                                void *proc_cls);
+
+
+/**
+ * Continuation to call from the 'proc' function after the fragment
+ * has been transmitted (and hence the next fragment can now be
+ * given to proc).
+ *
+ * @param fc fragmentation context
+ */
+void
+GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
 
 
 /**
@@ -95,8 +112,9 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
  *         GNUNET_NO if more messages are pending
  *         GNUNET_SYSERR if this ack is not valid for this fc
  */
-int GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
-                                const struct GNUNET_MessageHeader *msg);
+int
+GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
+                             const struct GNUNET_MessageHeader *msg);
 
 
 /**
@@ -112,15 +130,33 @@ GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc);
 
 
 /**
- * Defragmentation context.
+ * Defragmentation context (one per connection).
  */
 struct GNUNET_DEFRAGMENT_Context;
 
 
+/**
+ * Function that is called with acknowledgement messages created by
+ * the fragmentation module.  Acknowledgements are cummulative,
+ * so it is OK to only transmit the 'latest' ack message for the same
+ * message ID.
+ *
+ * @param cls closure
+ * @param id unique message ID (modulo collisions)
+ * @param msg the message that was created
+ */
+typedef void (*GNUNET_DEFRAGMENT_AckProcessor) (void *cls, uint32_t id,
+                                                const struct
+                                                GNUNET_MessageHeader * msg);
+
+
 /**
  * Create a defragmentation context.
  *
  * @param stats statistics context
+ * @param mtu the maximum message size for each fragment
+ * @param num_msgs how many fragmented messages
+ *                 to we defragment at most at the same time?
  * @param cls closure for proc and ackp
  * @param proc function to call with defragmented messages
  * @param ackp function to call with acknowledgements (to send
@@ -129,9 +165,10 @@ struct GNUNET_DEFRAGMENT_Context;
  */
 struct GNUNET_DEFRAGMENT_Context *
 GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
-                                 void *cls,
-                                 GNUNET_FRAGMENT_MessageProcessor proc,
-                                 GNUNET_FRAGMENT_MessageProcessor ackp);
+                                  uint16_t mtu, unsigned int num_msgs,
+                                  void *cls,
+                                  GNUNET_FRAGMENT_MessageProcessor proc,
+                                  GNUNET_DEFRAGMENT_AckProcessor ackp);
 
 
 /**
@@ -148,10 +185,11 @@ GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
  *
  * @param dc the context
  * @param msg the message that was received
+ * @return GNUNET_OK on success, GNUNET_NO if this was a duplicate, GNUNET_SYSERR on error
  */
-void
+int
 GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
-                                   const struct GNUNET_MessageHeader *msg);
+                                    const struct GNUNET_MessageHeader *msg);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */