aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-09 11:54:47 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-09 11:54:47 +0000
commit3883c9b973ddcbdc88d9807dbe4252a56ece5f92 (patch)
treeb54d5edf45cbeeb4031aa029210eec6019f7ff73 /src/fragmentation
parent1a39ba90f5af8341431c49f0dc9931d3c86de7a2 (diff)
downloadgnunet-3883c9b973ddcbdc88d9807dbe4252a56ece5f92.tar.gz
gnunet-3883c9b973ddcbdc88d9807dbe4252a56ece5f92.zip
new fragmentation API design - with retransmit
Diffstat (limited to 'src/fragmentation')
-rw-r--r--src/fragmentation/Makefile.am23
-rw-r--r--src/fragmentation/defragmentation_new.c109
-rw-r--r--src/fragmentation/fragmentation.h52
-rw-r--r--src/fragmentation/fragmentation_new.c195
4 files changed, 368 insertions, 11 deletions
diff --git a/src/fragmentation/Makefile.am b/src/fragmentation/Makefile.am
index 5b1367260..15e356fcc 100644
--- a/src/fragmentation/Makefile.am
+++ b/src/fragmentation/Makefile.am
@@ -11,20 +11,21 @@ endif
11lib_LTLIBRARIES = libgnunetfragmentation.la 11lib_LTLIBRARIES = libgnunetfragmentation.la
12 12
13libgnunetfragmentation_la_SOURCES = \ 13libgnunetfragmentation_la_SOURCES = \
14 fragmentation.c 14 fragmentation_new.c \
15 defragmentation_new.c
15libgnunetfragmentation_la_LIBADD = \ 16libgnunetfragmentation_la_LIBADD = \
16 $(top_builddir)/src/util/libgnunetutil.la 17 $(top_builddir)/src/util/libgnunetutil.la
17 18
18check_PROGRAMS = \ 19#check_PROGRAMS = \
19 test_fragmentation 20# test_fragmentation
20 21
21if ENABLE_TEST_RUN 22#if ENABLE_TEST_RUN
22TESTS = $(check_PROGRAMS) 23#TESTS = $(check_PROGRAMS)
23endif 24#endif
24 25
25test_fragmentation_SOURCES = \ 26#test_fragmentation_SOURCES = \
26 test_frag_ji.c 27# test_frag_ji.c
27test_fragmentation_LDADD = \ 28#test_fragmentation_LDADD = \
28 $(top_builddir)/src/fragmentation/libgnunetfragmentation.la \ 29# $(top_builddir)/src/fragmentation/libgnunetfragmentation.la \
29 $(top_builddir)/src/util/libgnunetutil.la 30# $(top_builddir)/src/util/libgnunetutil.la
30 31
diff --git a/src/fragmentation/defragmentation_new.c b/src/fragmentation/defragmentation_new.c
new file mode 100644
index 000000000..8fdc334d9
--- /dev/null
+++ b/src/fragmentation/defragmentation_new.c
@@ -0,0 +1,109 @@
1/*
2 This file is part of GNUnet
3 (C) 2009, 2011 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 3, 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 src/fragmentation/defragmentation_new.c
22 * @brief library to help defragment messages
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_fragmentation_lib.h"
27#include "fragmentation.h"
28
29/**
30 * Defragmentation context.
31 */
32struct GNUNET_DEFRAGMENT_Context
33{
34
35 /**
36 * For statistics.
37 */
38 struct GNUNET_STATISTICS_Handle *stats;
39
40 /**
41 * Closure for 'proc' and 'ackp'.
42 */
43 void *cls;
44
45 /**
46 * Function to call with defragmented messages.
47 */
48 GNUNET_FRAGMENT_MessageProcessor proc;
49
50 /**
51 * Function to call with acknowledgements.
52 */
53 GNUNET_FRAGMENT_MessageProcessor ackp;
54};
55
56
57/**
58 * Create a defragmentation context.
59 *
60 * @param stats statistics context
61 * @param cls closure for proc and ackp
62 * @param proc function to call with defragmented messages
63 * @param ackp function to call with acknowledgements (to send
64 * back to the other side)
65 * @return the defragmentation context
66 */
67struct GNUNET_DEFRAGMENT_Context *
68GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
69 void *cls,
70 GNUNET_FRAGMENT_MessageProcessor proc,
71 GNUNET_FRAGMENT_MessageProcessor ackp)
72{
73 struct GNUNET_DEFRAGMENT_Context *dc;
74
75 dc = GNUNET_malloc (sizeof (struct GNUNET_DEFRAGMENT_Context));
76 dc->stats = stats;
77 dc->cls = cls;
78 dc->proc = proc;
79 dc->ackp = ackp;
80 return dc;
81}
82
83
84/**
85 * Destroy the given defragmentation context.
86 *
87 * @param dc defragmentation context
88 */
89void
90GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc)
91{
92 GNUNET_free (dc);
93}
94
95
96/**
97 * We have received a fragment. Process it.
98 *
99 * @param dc the context
100 * @param msg the message that was received
101 */
102void
103GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
104 const struct GNUNET_MessageHeader *msg)
105{
106}
107
108/* end of defragmentation_new.c */
109
diff --git a/src/fragmentation/fragmentation.h b/src/fragmentation/fragmentation.h
new file mode 100644
index 000000000..e9b3faba5
--- /dev/null
+++ b/src/fragmentation/fragmentation.h
@@ -0,0 +1,52 @@
1/*
2 This file is part of GNUnet
3 (C) 2009, 2011 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 3, 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 src/fragmentation/fragmentation.h
22 * @brief library to help fragment messages
23 * @author Christian Grothoff
24 */
25#ifndef FRAGMENTATION_H
26#define FRAGMENTATION_H
27#include "platform.h"
28#include "gnunet_fragmentation_lib.h"
29
30/**
31 * Header for a message fragment.
32 */
33struct FragmentHeader
34{
35
36 struct GNUNET_MessageHeader header;
37
38};
39
40
41/**
42 * Message fragment acknowledgement.
43 */
44struct FragmentAcknowledgement
45{
46
47 struct GNUNET_MessageHeader header;
48
49};
50
51
52#endif
diff --git a/src/fragmentation/fragmentation_new.c b/src/fragmentation/fragmentation_new.c
new file mode 100644
index 000000000..a95afc4a4
--- /dev/null
+++ b/src/fragmentation/fragmentation_new.c
@@ -0,0 +1,195 @@
1/*
2 This file is part of GNUnet
3 (C) 2009, 2011 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 3, 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 src/fragmentation/fragmentation_new.c
22 * @brief library to help fragment messages
23 * @author Christian Grothoff
24 */
25
26#include "platform.h"
27#include "gnunet_fragmentation_lib.h"
28#include "fragmentation.h"
29
30/**
31 * Fragmentation context.
32 */
33struct GNUNET_FRAGMENT_Context
34{
35 /**
36 * Statistics to use.
37 */
38 struct GNUNET_STATISTICS_Handle *stats;
39
40 /**
41 * Tracker for flow control.
42 */
43 struct GNUNET_BANDWIDTH_Tracker *tracker;
44
45 /**
46 * Current expected delay for ACKs.
47 */
48 struct GNUNET_TIME_Relative delay;
49
50 /**
51 * Message to fragment (allocated at the end of this struct).
52 */
53 const struct GNUNET_MessageHeader *msg;
54
55 /**
56 * Function to call for transmissions.
57 */
58 GNUNET_FRAGMENT_MessageProcessor proc;
59
60 /**
61 * Closure for 'proc'.
62 */
63 void *proc_cls;
64
65 /**
66 * Bitfield, set to 1 for each unacknowledged fragment.
67 */
68 uint64_t acks;
69
70 /**
71 * Task performing work for the fragmenter.
72 */
73 GNUNET_SCHEDULER_TaskIdentifier task;
74
75 /**
76 * Target fragment size.
77 */
78 uint16_t mtu;
79
80};
81
82
83/**
84 * Transmit the next fragment to the other peer.
85 *
86 * @param cls the 'struct GNUNET_FRAGMENT_Context'
87 * @param tc scheduler context
88 */
89static void
90transmit_next (void *cls,
91 const struct GNUNET_SCHEDULER_TaskContext *tc)
92{
93 struct GNUNET_FRAGMENT_Context *fc = cls;
94
95 fc->task = GNUNET_SCHEDULER_NO_TASK;
96}
97
98
99/**
100 * Create a fragmentation context for the given message.
101 * Fragments the message into fragments of size "mtu" or
102 * less. Calls 'proc' on each un-acknowledged fragment,
103 * using both the expected 'delay' between messages and
104 * acknowledgements and the given 'tracker' to guide the
105 * frequency of calls to 'proc'.
106 *
107 * @param stats statistics context
108 * @param mtu the maximum message size for each fragment
109 * @param tracker bandwidth tracker to use for flow control (can be NULL)
110 * @param delay expected delay between fragment transmission
111 * and ACK based on previous messages
112 * @param msg the message to fragment
113 * @param proc function to call for each fragment to transmit
114 * @param proc_cls closure for proc
115 * @return the fragmentation context
116 */
117struct GNUNET_FRAGMENT_Context *
118GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
119 uint16_t mtu,
120 struct GNUNET_BANDWIDTH_Tracker *tracker,
121 struct GNUNET_TIME_Relative delay,
122 const struct GNUNET_MessageHeader *msg,
123 GNUNET_FRAGMENT_MessageProcessor proc,
124 void *proc_cls)
125{
126 struct GNUNET_FRAGMENT_Context *fc;
127 size_t size;
128 uint64_t bits;
129
130 GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader));
131 size = ntohs (msg->size);
132 GNUNET_assert (size > mtu);
133 fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size);
134 fc->stats = stats;
135 fc->mtu = mtu;
136 fc->tracker = tracker;
137 fc->delay = delay;
138 fc->msg = (const struct GNUNET_MessageHeader*)&fc[1];
139 fc->proc = proc;
140 fc->proc_cls = proc_cls;
141 memcpy (&fc[1], msg, size);
142 bits = (size + mtu - 1) / (mtu - sizeof (struct FragmentHeader));
143 GNUNET_assert (bits <= 64);
144 if (bits == 64)
145 fc->acks = UINT64_MAX; /* set all 64 bit */
146 else
147 fc->acks = (1 << bits) - 1; /* set lowest 'bits' bit */
148 fc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_BANDWIDTH_tracker_get_delay (tracker, mtu),
149 &transmit_next,
150 fc);
151 return fc;
152}
153
154
155/**
156 * Process an acknowledgement message we got from the other
157 * side (to control re-transmits).
158 *
159 * @param fc fragmentation context
160 * @param msg acknowledgement message we received
161 * @return GNUNET_OK if this ack completes the work of the 'fc'
162 * (all fragments have been received);
163 * GNUNET_NO if more messages are pending
164 * GNUNET_SYSERR if this ack is not valid for this fc
165 */
166int
167GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
168 const struct GNUNET_MessageHeader *msg)
169{
170 return GNUNET_SYSERR;
171}
172
173
174/**
175 * Destroy the given fragmentation context (stop calling 'proc', free
176 * resources).
177 *
178 * @param fc fragmentation context
179 * @return average delay between transmission and ACK for the
180 * last message, FOREVER if the message was not fully transmitted
181 */
182struct GNUNET_TIME_Relative
183GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc)
184{
185 struct GNUNET_TIME_Relative ret;
186
187 if (fc->task != GNUNET_SCHEDULER_NO_TASK)
188 GNUNET_SCHEDULER_cancel (fc->task);
189 ret = fc->delay;
190 GNUNET_free (fc);
191 return ret;
192}
193
194/* end of fragmentation_new.c */
195