2 This file is part of GNUnet
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file include/gnunet_fragmentation_lib.h
22 * @brief library to help fragment messages
23 * @author Christian Grothoff
25 * TODO: consider additional flow-control for sending from
26 * fragmentation based on continuations.
29 #ifndef GNUNET_FRAGMENTATION_LIB_H
30 #define GNUNET_FRAGMENTATION_LIB_H
32 #include "gnunet_util_lib.h"
33 #include "gnunet_bandwidth_lib.h"
34 #include "gnunet_statistics_service.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
46 * Fragmentation context.
48 struct GNUNET_FRAGMENT_Context;
52 * Function that is called with messages created by the fragmentation
53 * module. In the case of the 'proc' callback of the
54 * GNUNET_FRAGMENT_context_create function, this function must
55 * eventually call 'GNUNET_FRAGMENT_context_transmission_done'.
58 * @param msg the message that was created
60 typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
61 const struct GNUNET_MessageHeader *msg);
65 * Create a fragmentation context for the given message.
66 * Fragments the message into fragments of size "mtu" or
67 * less. Calls 'proc' on each un-acknowledged fragment,
68 * using both the expected 'delay' between messages and
69 * acknowledgements and the given 'tracker' to guide the
70 * frequency of calls to 'proc'.
72 * @param stats statistics context
73 * @param mtu the maximum message size for each fragment
74 * @param tracker bandwidth tracker to use for flow control (can be NULL)
75 * @param delay expected delay between fragment transmission
76 * and ACK based on previous messages
77 * @param msg the message to fragment
78 * @param proc function to call for each fragment to transmit
79 * @param proc_cls closure for proc
80 * @return the fragmentation context
82 struct GNUNET_FRAGMENT_Context *
83 GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
85 struct GNUNET_BANDWIDTH_Tracker *tracker,
86 struct GNUNET_TIME_Relative delay,
87 const struct GNUNET_MessageHeader *msg,
88 GNUNET_FRAGMENT_MessageProcessor proc,
93 * Continuation to call from the 'proc' function after the fragment
94 * has been transmitted (and hence the next fragment can now be
97 * @param fc fragmentation context
100 GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
104 * Process an acknowledgement message we got from the other
105 * side (to control re-transmits).
107 * @param fc fragmentation context
108 * @param msg acknowledgement message we received
109 * @return GNUNET_OK if this ack completes the work of the 'fc'
110 * (all fragments have been received);
111 * GNUNET_NO if more messages are pending
112 * GNUNET_SYSERR if this ack is not valid for this fc
114 int GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
115 const struct GNUNET_MessageHeader *msg);
119 * Destroy the given fragmentation context (stop calling 'proc', free
122 * @param fc fragmentation context
123 * @return average delay between transmission and ACK for the
124 * last message, FOREVER if the message was not fully transmitted
126 struct GNUNET_TIME_Relative
127 GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc);
131 * Defragmentation context (one per connection).
133 struct GNUNET_DEFRAGMENT_Context;
137 * Function that is called with acknowledgement messages created by
138 * the fragmentation module. Acknowledgements are cummulative,
139 * so it is OK to only transmit the 'latest' ack message for the same
143 * @param id unique message ID (modulo collisions)
144 * @param msg the message that was created
146 typedef void (*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
148 const struct GNUNET_MessageHeader *msg);
152 * Create a defragmentation context.
154 * @param stats statistics context
155 * @param mtu the maximum message size for each fragment
156 * @param num_msgs how many fragmented messages
157 * to we defragment at most at the same time?
158 * @param cls closure for proc and ackp
159 * @param proc function to call with defragmented messages
160 * @param ackp function to call with acknowledgements (to send
161 * back to the other side)
162 * @return the defragmentation context
164 struct GNUNET_DEFRAGMENT_Context *
165 GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
167 unsigned int num_msgs,
169 GNUNET_FRAGMENT_MessageProcessor proc,
170 GNUNET_DEFRAGMENT_AckProcessor ackp);
174 * Destroy the given defragmentation context.
176 * @param dc defragmentation context
179 GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
183 * We have received a fragment. Process it.
185 * @param dc the context
186 * @param msg the message that was received
187 * @return GNUNET_OK on success, GNUNET_NO if this was a duplicate, GNUNET_SYSERR on error
190 GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
191 const struct GNUNET_MessageHeader *msg);
194 #if 0 /* keep Emacsens' auto-indent happy */
201 /* end of gnunet_fragmentation_lib.h */