ng
[oweals/gnunet.git] / src / include / gnunet_fragmentation_lib.h
1 /*
2      This file is part of GNUnet
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8      option) any later version.
9
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.
14
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.
19 */
20 /**
21  * @file include/gnunet_fragmentation_lib.h
22  * @brief library to help fragment messages
23  * @author Christian Grothoff
24  */
25
26 #ifndef GNUNET_FRAGMENTATION_LIB_H
27 #define GNUNET_FRAGMENTATION_LIB_H
28
29 #include "gnunet_common.h"
30 #include "gnunet_statistics_service.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 /**
41  * Function that is called with messages
42  * created by the fragmentation module.
43  *
44  * @param cls closure
45  * @param msg the message that was created
46  */
47 typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
48                                                   const struct
49                                                   GNUNET_MessageHeader * msg);
50
51
52 /**
53  * Fragment an over-sized message.
54  *
55  * @param msg the message to fragment
56  * @param mtu the maximum message size
57  * @param proc function to call for each fragment
58  * @param proc_cls closure for proc
59  */
60 void GNUNET_FRAGMENT_fragment (const struct GNUNET_MessageHeader *msg,
61                                uint16_t mtu,
62                                GNUNET_FRAGMENT_MessageProcessor proc,
63                                void *proc_cls);
64
65 /**
66  * Defragmentation context.
67  */
68 struct GNUNET_FRAGMENT_Context;
69
70 /**
71  * Create a defragmentation context.
72  *
73  * @param stats statistics context
74  * @param proc function to call with defragmented messages
75  * @param proc_cls closure for proc
76  * @return the defragmentation context
77  */
78 struct GNUNET_FRAGMENT_Context *GNUNET_FRAGMENT_context_create (struct
79                                                                 GNUNET_STATISTICS_Handle
80                                                                 *stats,
81                                                                 GNUNET_FRAGMENT_MessageProcessor
82                                                                 proc,
83                                                                 void
84                                                                 *proc_cls);
85
86
87 /**
88  * Destroy the given defragmentation context.
89  */
90 void GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *ctx);
91
92
93 /**
94  * We have received a fragment.  Process it.
95  *
96  * @param ctx the context
97  * @param sender who transmitted the fragment
98  * @param msg the message that was received
99  */
100 void GNUNET_FRAGMENT_process (struct GNUNET_FRAGMENT_Context *ctx,
101                               const struct GNUNET_PeerIdentity *sender,
102                               const struct GNUNET_MessageHeader *msg);
103
104
105 #if 0                           /* keep Emacsens' auto-indent happy */
106 {
107 #endif
108 #ifdef __cplusplus
109 }
110 #endif
111
112 /* end of gnunet_fragmentation_lib.h */
113 #endif