aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-09 16:31:09 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-09 16:31:09 +0000
commit3124634919314510e62da112612ad7fe66b2dd83 (patch)
tree18e452a2201d845978422e6c56ddf2c7d3e0dfc5 /src/fragmentation
parent54a83ae9ffdf895596369a78929a8213fb8d900c (diff)
downloadgnunet-3124634919314510e62da112612ad7fe66b2dd83.tar.gz
gnunet-3124634919314510e62da112612ad7fe66b2dd83.zip
frag
Diffstat (limited to 'src/fragmentation')
-rw-r--r--src/fragmentation/fragmentation.h30
-rw-r--r--src/fragmentation/fragmentation_new.c19
2 files changed, 44 insertions, 5 deletions
diff --git a/src/fragmentation/fragmentation.h b/src/fragmentation/fragmentation.h
index 9473fa31a..3469dd27e 100644
--- a/src/fragmentation/fragmentation.h
+++ b/src/fragmentation/fragmentation.h
@@ -28,13 +28,33 @@
28#include "gnunet_fragmentation_lib.h" 28#include "gnunet_fragmentation_lib.h"
29 29
30/** 30/**
31 * Header for a message fragment. 31 * Header for a message fragment. Followed by the
32 * original message.
32 */ 33 */
33struct FragmentHeader 34struct FragmentHeader
34{ 35{
35 36
37 /**
38 * Message header.
39 */
36 struct GNUNET_MessageHeader header; 40 struct GNUNET_MessageHeader header;
37 41
42 /**
43 * Unique fragment ID.
44 */
45 uint32_t fragment_id;
46
47 /**
48 * Total message size of the original message.
49 */
50 uint16_t total_size;
51
52 /**
53 * Absolute offset (in bytes) of this fragment in the original
54 * message. Will be a multiple of the MTU.
55 */
56 uint16_t offset;
57
38}; 58};
39 59
40 60
@@ -44,9 +64,17 @@ struct FragmentHeader
44struct FragmentAcknowledgement 64struct FragmentAcknowledgement
45{ 65{
46 66
67 /**
68 * Message header.
69 */
47 struct GNUNET_MessageHeader header; 70 struct GNUNET_MessageHeader header;
48 71
49 /** 72 /**
73 * Unique fragment ID.
74 */
75 uint32_t fragment_id;
76
77 /**
50 * Bits that are being acknowledged, in big-endian. 78 * Bits that are being acknowledged, in big-endian.
51 * (bits that are set correspond to fragments that 79 * (bits that are set correspond to fragments that
52 * have not yet been received). 80 * have not yet been received).
diff --git a/src/fragmentation/fragmentation_new.c b/src/fragmentation/fragmentation_new.c
index 66633e4c1..6a2747e4d 100644
--- a/src/fragmentation/fragmentation_new.c
+++ b/src/fragmentation/fragmentation_new.c
@@ -22,11 +22,12 @@
22 * @brief library to help fragment messages 22 * @brief library to help fragment messages
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25
26#include "platform.h" 25#include "platform.h"
27#include "gnunet_fragmentation_lib.h" 26#include "gnunet_fragmentation_lib.h"
27#include "gnunet_protocols.h"
28#include "fragmentation.h" 28#include "fragmentation.h"
29 29
30
30/** 31/**
31 * Fragmentation context. 32 * Fragmentation context.
32 */ 33 */
@@ -78,6 +79,11 @@ struct GNUNET_FRAGMENT_Context
78 GNUNET_SCHEDULER_TaskIdentifier task; 79 GNUNET_SCHEDULER_TaskIdentifier task;
79 80
80 /** 81 /**
82 * Our fragmentation ID. (chosen at random)
83 */
84 uint32_t fragment_id;
85
86 /**
81 * Round-robin selector for the next transmission. 87 * Round-robin selector for the next transmission.
82 */ 88 */
83 unsigned int next_transmission; 89 unsigned int next_transmission;
@@ -150,7 +156,9 @@ transmit_next (void *cls,
150 fh = (struct FragmentHeader*) msg; 156 fh = (struct FragmentHeader*) msg;
151 fh->header.size = htons (fsize); 157 fh->header.size = htons (fsize);
152 fh->header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT); 158 fh->header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT);
153 /* FIXME: add specific ID info... */ 159 fh->fragment_id = htonl (fc->fragment_id);
160 fh->total_size = fc->msg->size; /* already in big-endian */
161 fh->offset = htons (fc->mtu * bit);
154 memcpy (&fc[1], 162 memcpy (&fc[1],
155 &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))], 163 &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))],
156 fsize - sizeof (struct FragmentHeader)); 164 fsize - sizeof (struct FragmentHeader));
@@ -236,6 +244,8 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
236 fc->msg = (const struct GNUNET_MessageHeader*)&fc[1]; 244 fc->msg = (const struct GNUNET_MessageHeader*)&fc[1];
237 fc->proc = proc; 245 fc->proc = proc;
238 fc->proc_cls = proc_cls; 246 fc->proc_cls = proc_cls;
247 fc->fragment_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
248 UINT32_MAX);
239 memcpy (&fc[1], msg, size); 249 memcpy (&fc[1], msg, size);
240 bits = (size + mtu - 1) / (mtu - sizeof (struct FragmentHeader)); 250 bits = (size + mtu - 1) / (mtu - sizeof (struct FragmentHeader));
241 GNUNET_assert (bits <= 64); 251 GNUNET_assert (bits <= 64);
@@ -275,9 +285,9 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
275 return GNUNET_SYSERR; 285 return GNUNET_SYSERR;
276 } 286 }
277 fa = (const struct FragmentAcknowledgement *) msg; 287 fa = (const struct FragmentAcknowledgement *) msg;
288 if (ntohl (fa->fragment_id) != fc->fragment_id)
289 return GNUNET_SYSERR; /* not our ACK */
278 abits = GNUNET_ntohll (fa->bits); 290 abits = GNUNET_ntohll (fa->bits);
279 /* FIXME: match FA to us... */
280
281 if (GNUNET_YES == fc->wack) 291 if (GNUNET_YES == fc->wack)
282 { 292 {
283 /* normal ACK, can update running average of delay... */ 293 /* normal ACK, can update running average of delay... */
@@ -326,5 +336,6 @@ GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc)
326 return ret; 336 return ret;
327} 337}
328 338
339
329/* end of fragmentation_new.c */ 340/* end of fragmentation_new.c */
330 341