aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-09 16:48:59 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-09 16:48:59 +0000
commit42b758ecd70b4057d2b9a11d16284c9b5fc15d36 (patch)
tree2d15030a129fa7e0d6a42a5237fbfc3cde7ec850 /src/fragmentation
parent3124634919314510e62da112612ad7fe66b2dd83 (diff)
downloadgnunet-42b758ecd70b4057d2b9a11d16284c9b5fc15d36.tar.gz
gnunet-42b758ecd70b4057d2b9a11d16284c9b5fc15d36.zip
data structures
Diffstat (limited to 'src/fragmentation')
-rw-r--r--src/fragmentation/defragmentation_new.c126
1 files changed, 125 insertions, 1 deletions
diff --git a/src/fragmentation/defragmentation_new.c b/src/fragmentation/defragmentation_new.c
index 8fdc334d9..523a2cede 100644
--- a/src/fragmentation/defragmentation_new.c
+++ b/src/fragmentation/defragmentation_new.c
@@ -26,8 +26,97 @@
26#include "gnunet_fragmentation_lib.h" 26#include "gnunet_fragmentation_lib.h"
27#include "fragmentation.h" 27#include "fragmentation.h"
28 28
29
29/** 30/**
30 * Defragmentation context. 31 * Timestamps for fragments.
32 */
33struct FragTimes
34{
35 /**
36 * The time the fragment was received.
37 */
38 GNUNET_TIME_Absolute time;
39
40 /**
41 * Number of the bit for the fragment (in [0,..,63]).
42 */
43 unsigned int bit;
44};
45
46
47/**
48 * Information we keep for one message that is being assembled.
49 */
50struct MessageContext
51{
52 /**
53 * This is a DLL.
54 */
55 struct MessageContext *next;
56
57 /**
58 * This is a DLL.
59 */
60 struct MessageContext *prev;
61
62 /**
63 * Pointer to the assembled message, allocated at the
64 * end of this struct.
65 */
66 const struct GNUNET_MessageHeader *msg;
67
68 /**
69 * Last time we received any update for this message
70 * (least-recently updated message will be discarded
71 * if we hit the queue size).
72 */
73 struct GNUNET_TIME_Absolute last_update;
74
75 /**
76 * Task scheduled for transmitting the next ACK to the
77 * other peer.
78 */
79 struct GNUNET_SCHEDULER_TaskIdentifier ack_task;
80
81 /**
82 * When did we receive which fragment? Used to calculate
83 * the time we should send the ACK.
84 */
85 struct FragTimes frag_times[64];
86
87 /**
88 * Which fragments have we gotten yet? bits that are 1
89 * indicate missing fragments.
90 */
91 uint64_t bits;
92
93 /**
94 * Unique ID for this message.
95 */
96 uint32_t fragment_id;
97
98 /**
99 * For the current ACK round, which is the first relevant
100 * offset in 'frag_times'?
101 */
102 unsigned int frag_times_start_offset;
103
104 /**
105 * Which offset whould we write the next frag value into
106 * in the 'frag_times' array? All smaller entries are valid.
107 */
108 unsigned int frag_times_write_offset;
109
110 /**
111 * Total size of the message that we are assembling.
112 */
113 uint16_t total_size;
114
115};
116
117
118/**
119 * Defragmentation context (one per connection).
31 */ 120 */
32struct GNUNET_DEFRAGMENT_Context 121struct GNUNET_DEFRAGMENT_Context
33{ 122{
@@ -43,6 +132,16 @@ struct GNUNET_DEFRAGMENT_Context
43 void *cls; 132 void *cls;
44 133
45 /** 134 /**
135 * Head of list of messages we're defragmenting.
136 */
137 struct MessageContext *head;
138
139 /**
140 * Tail of list of messages we're defragmenting.
141 */
142 struct MessageContext *tail;
143
144 /**
46 * Function to call with defragmented messages. 145 * Function to call with defragmented messages.
47 */ 146 */
48 GNUNET_FRAGMENT_MessageProcessor proc; 147 GNUNET_FRAGMENT_MessageProcessor proc;
@@ -51,6 +150,26 @@ struct GNUNET_DEFRAGMENT_Context
51 * Function to call with acknowledgements. 150 * Function to call with acknowledgements.
52 */ 151 */
53 GNUNET_FRAGMENT_MessageProcessor ackp; 152 GNUNET_FRAGMENT_MessageProcessor ackp;
153
154 /**
155 * Running average of the latency (delay between messages) for this
156 * connection.
157 */
158 struct GNUNET_TIME_Relative latency;
159
160 /**
161 * num_msgs how many fragmented messages
162 * to we defragment at most at the same time?
163 */
164 unsigned int num_msgs;
165
166 /**
167 * Current number of messages in the 'struct MessageContext'
168 * DLL (smaller or equal to 'num_msgs').
169 */
170 unsigned int list_size;
171
172
54}; 173};
55 174
56 175
@@ -58,6 +177,8 @@ struct GNUNET_DEFRAGMENT_Context
58 * Create a defragmentation context. 177 * Create a defragmentation context.
59 * 178 *
60 * @param stats statistics context 179 * @param stats statistics context
180 * @param num_msgs how many fragmented messages
181 * to we defragment at most at the same time?
61 * @param cls closure for proc and ackp 182 * @param cls closure for proc and ackp
62 * @param proc function to call with defragmented messages 183 * @param proc function to call with defragmented messages
63 * @param ackp function to call with acknowledgements (to send 184 * @param ackp function to call with acknowledgements (to send
@@ -66,6 +187,7 @@ struct GNUNET_DEFRAGMENT_Context
66 */ 187 */
67struct GNUNET_DEFRAGMENT_Context * 188struct GNUNET_DEFRAGMENT_Context *
68GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, 189GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
190 unsigned int num_msgs,
69 void *cls, 191 void *cls,
70 GNUNET_FRAGMENT_MessageProcessor proc, 192 GNUNET_FRAGMENT_MessageProcessor proc,
71 GNUNET_FRAGMENT_MessageProcessor ackp) 193 GNUNET_FRAGMENT_MessageProcessor ackp)
@@ -77,6 +199,8 @@ GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
77 dc->cls = cls; 199 dc->cls = cls;
78 dc->proc = proc; 200 dc->proc = proc;
79 dc->ackp = ackp; 201 dc->ackp = ackp;
202 dc->num_msgs = num_msgs;
203 dc->latency = GNUNET_TIME_UNIT_SECONDS; /* start with likely overestimate */
80 return dc; 204 return dc;
81} 205}
82 206