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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @author Christian Grothoff
24 * Library to help fragment messages
26 * @defgroup fragmentation Fragmentation library
27 * Library to help fragment messages
30 * @todo Consider additional flow-control for sending from
31 * fragmentation based on continuations.
34 #ifndef GNUNET_FRAGMENTATION_LIB_H
35 #define GNUNET_FRAGMENTATION_LIB_H
37 #include "gnunet_util_lib.h"
38 #include "gnunet_bandwidth_lib.h"
39 #include "gnunet_statistics_service.h"
44 #if 0 /* keep Emacsens' auto-indent happy */
51 * Fragmentation context.
53 struct GNUNET_FRAGMENT_Context;
57 * Function that is called with messages created by the fragmentation
58 * module. In the case of the 'proc' callback of the
59 * #GNUNET_FRAGMENT_context_create() function, this function must
60 * eventually call #GNUNET_FRAGMENT_context_transmission_done().
63 * @param msg the message that was created
66 (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
67 const struct GNUNET_MessageHeader *msg);
71 * Create a fragmentation context for the given message.
72 * Fragments the message into fragments of size @a mtu or
73 * less. Calls @a proc on each un-acknowledged fragment,
74 * using both the expected @a msg_delay between messages and
75 * acknowledgements and the given @a tracker to guide the
76 * frequency of calls to @a proc.
78 * @param stats statistics context
79 * @param mtu the maximum message size for each fragment
80 * @param tracker bandwidth tracker to use for flow control (can be NULL)
81 * @param msg_delay initial delay to insert between fragment transmissions
82 * based on previous messages
83 * @param ack_delay expected delay between fragment transmission
84 * and ACK based on previous messages
85 * @param msg the message to fragment
86 * @param proc function to call for each fragment to transmit
87 * @param proc_cls closure for proc
88 * @return the fragmentation context
90 struct GNUNET_FRAGMENT_Context *
91 GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
93 struct GNUNET_BANDWIDTH_Tracker *tracker,
94 struct GNUNET_TIME_Relative msg_delay,
95 struct GNUNET_TIME_Relative ack_delay,
96 const struct GNUNET_MessageHeader *msg,
97 GNUNET_FRAGMENT_MessageProcessor proc,
102 * Continuation to call from the 'proc' function after the fragment
103 * has been transmitted (and hence the next fragment can now be
106 * @param fc fragmentation context
109 GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
113 * Process an acknowledgement message we got from the other
114 * side (to control re-transmits).
116 * @param fc fragmentation context
117 * @param msg acknowledgement message we received
118 * @return #GNUNET_OK if this ack completes the work of the 'fc'
119 * (all fragments have been received);
120 * #GNUNET_NO if more messages are pending
121 * #GNUNET_SYSERR if this ack is not valid for this fc
124 GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
125 const struct GNUNET_MessageHeader *msg);
129 * Destroy the given fragmentation context (stop calling 'proc', free
132 * @param fc fragmentation context
133 * @param msg_delay where to store average delay between individual message transmissions the
134 * last message (OUT only)
135 * @param ack_delay where to store average delay between transmission and ACK for the
136 * last message, set to FOREVER if the message was not fully transmitted (OUT only)
139 GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc,
140 struct GNUNET_TIME_Relative *msg_delay,
141 struct GNUNET_TIME_Relative *ack_delay);
145 * Convert an ACK message to a printable format suitable for logging.
147 * @param ack message to print
148 * @return ack in human-readable format
151 GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack);
155 * Defragmentation context (one per connection).
157 struct GNUNET_DEFRAGMENT_Context;
161 * Function that is called with acknowledgement messages created by
162 * the fragmentation module. Acknowledgements are cummulative,
163 * so it is OK to only transmit the 'latest' ack message for the same
167 * @param id unique message ID (modulo collisions)
168 * @param msg the message that was created
171 (*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
173 const struct GNUNET_MessageHeader *msg);
177 * Create a defragmentation context.
179 * @param stats statistics context
180 * @param mtu the maximum message size for each fragment
181 * @param num_msgs how many fragmented messages
182 * to we defragment at most at the same time?
183 * @param cls closure for @a proc and @a ackp
184 * @param proc function to call with defragmented messages
185 * @param ackp function to call with acknowledgements (to send
186 * back to the other side)
187 * @return the defragmentation context
189 struct GNUNET_DEFRAGMENT_Context *
190 GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
192 unsigned int num_msgs,
194 GNUNET_FRAGMENT_MessageProcessor proc,
195 GNUNET_DEFRAGMENT_AckProcessor ackp);
199 * Destroy the given defragmentation context.
201 * @param dc defragmentation context
204 GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
208 * We have received a fragment. Process it.
210 * @param dc the context
211 * @param msg the message that was received
212 * @return #GNUNET_OK on success,
213 * #GNUNET_NO if this was a duplicate,
214 * #GNUNET_SYSERR on error
217 GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
218 const struct GNUNET_MessageHeader *msg);
222 #if 0 /* keep Emacsens' auto-indent happy */
231 /** @} */ /* end of group */