2 This file is part of GNUnet
3 Copyright (C) 2009, 2011, 2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Christian Grothoff
22 * Library to help fragment messages
24 * @defgroup fragmentation Fragmentation library
25 * Library to help fragment messages
28 * @todo Consider additional flow-control for sending from
29 * fragmentation based on continuations.
32 #ifndef GNUNET_FRAGMENTATION_LIB_H
33 #define GNUNET_FRAGMENTATION_LIB_H
35 #include "gnunet_util_lib.h"
36 #include "gnunet_bandwidth_lib.h"
37 #include "gnunet_statistics_service.h"
42 #if 0 /* keep Emacsens' auto-indent happy */
49 * Fragmentation context.
51 struct GNUNET_FRAGMENT_Context;
55 * Function that is called with messages created by the fragmentation
56 * module. In the case of the 'proc' callback of the
57 * #GNUNET_FRAGMENT_context_create() function, this function must
58 * eventually call #GNUNET_FRAGMENT_context_transmission_done().
61 * @param msg the message that was created
64 (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
65 const struct GNUNET_MessageHeader *msg);
69 * Create a fragmentation context for the given message.
70 * Fragments the message into fragments of size @a mtu or
71 * less. Calls @a proc on each un-acknowledged fragment,
72 * using both the expected @a msg_delay between messages and
73 * acknowledgements and the given @a tracker to guide the
74 * frequency of calls to @a proc.
76 * @param stats statistics context
77 * @param mtu the maximum message size for each fragment
78 * @param tracker bandwidth tracker to use for flow control (can be NULL)
79 * @param msg_delay initial delay to insert between fragment transmissions
80 * based on previous messages
81 * @param ack_delay expected delay between fragment transmission
82 * and ACK based on previous messages
83 * @param msg the message to fragment
84 * @param proc function to call for each fragment to transmit
85 * @param proc_cls closure for proc
86 * @return the fragmentation context
88 struct GNUNET_FRAGMENT_Context *
89 GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
91 struct GNUNET_BANDWIDTH_Tracker *tracker,
92 struct GNUNET_TIME_Relative msg_delay,
93 struct GNUNET_TIME_Relative ack_delay,
94 const struct GNUNET_MessageHeader *msg,
95 GNUNET_FRAGMENT_MessageProcessor proc,
100 * Continuation to call from the 'proc' function after the fragment
101 * has been transmitted (and hence the next fragment can now be
104 * @param fc fragmentation context
107 GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
111 * Process an acknowledgement message we got from the other
112 * side (to control re-transmits).
114 * @param fc fragmentation context
115 * @param msg acknowledgement message we received
116 * @return #GNUNET_OK if this ack completes the work of the 'fc'
117 * (all fragments have been received);
118 * #GNUNET_NO if more messages are pending
119 * #GNUNET_SYSERR if this ack is not valid for this fc
122 GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
123 const struct GNUNET_MessageHeader *msg);
127 * Destroy the given fragmentation context (stop calling 'proc', free
130 * @param fc fragmentation context
131 * @param msg_delay where to store average delay between individual message transmissions the
132 * last message (OUT only)
133 * @param ack_delay where to store average delay between transmission and ACK for the
134 * last message, set to FOREVER if the message was not fully transmitted (OUT only)
137 GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc,
138 struct GNUNET_TIME_Relative *msg_delay,
139 struct GNUNET_TIME_Relative *ack_delay);
143 * Convert an ACK message to a printable format suitable for logging.
145 * @param ack message to print
146 * @return ack in human-readable format
149 GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack);
153 * Defragmentation context (one per connection).
155 struct GNUNET_DEFRAGMENT_Context;
159 * Function that is called with acknowledgement messages created by
160 * the fragmentation module. Acknowledgements are cummulative,
161 * so it is OK to only transmit the 'latest' ack message for the same
165 * @param id unique message ID (modulo collisions)
166 * @param msg the message that was created
169 (*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
171 const struct GNUNET_MessageHeader *msg);
175 * Create a defragmentation context.
177 * @param stats statistics context
178 * @param mtu the maximum message size for each fragment
179 * @param num_msgs how many fragmented messages
180 * to we defragment at most at the same time?
181 * @param cls closure for @a proc and @a ackp
182 * @param proc function to call with defragmented messages
183 * @param ackp function to call with acknowledgements (to send
184 * back to the other side)
185 * @return the defragmentation context
187 struct GNUNET_DEFRAGMENT_Context *
188 GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
190 unsigned int num_msgs,
192 GNUNET_FRAGMENT_MessageProcessor proc,
193 GNUNET_DEFRAGMENT_AckProcessor ackp);
197 * Destroy the given defragmentation context.
199 * @param dc defragmentation context
202 GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
206 * We have received a fragment. Process it.
208 * @param dc the context
209 * @param msg the message that was received
210 * @return #GNUNET_OK on success,
211 * #GNUNET_NO if this was a duplicate,
212 * #GNUNET_SYSERR on error
215 GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
216 const struct GNUNET_MessageHeader *msg);
220 #if 0 /* keep Emacsens' auto-indent happy */
229 /** @} */ /* end of group */