From 3124634919314510e62da112612ad7fe66b2dd83 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 9 Jul 2011 16:31:09 +0000 Subject: [PATCH] frag --- src/fragmentation/fragmentation.h | 30 ++++++++++++++++++++++++++- src/fragmentation/fragmentation_new.c | 19 +++++++++++++---- 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 @@ #include "gnunet_fragmentation_lib.h" /** - * Header for a message fragment. + * Header for a message fragment. Followed by the + * original message. */ struct FragmentHeader { + /** + * Message header. + */ struct GNUNET_MessageHeader header; + /** + * Unique fragment ID. + */ + uint32_t fragment_id; + + /** + * Total message size of the original message. + */ + uint16_t total_size; + + /** + * Absolute offset (in bytes) of this fragment in the original + * message. Will be a multiple of the MTU. + */ + uint16_t offset; + }; @@ -44,8 +64,16 @@ struct FragmentHeader struct FragmentAcknowledgement { + /** + * Message header. + */ struct GNUNET_MessageHeader header; + /** + * Unique fragment ID. + */ + uint32_t fragment_id; + /** * Bits that are being acknowledged, in big-endian. * (bits that are set correspond to fragments that 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 @@ * @brief library to help fragment messages * @author Christian Grothoff */ - #include "platform.h" #include "gnunet_fragmentation_lib.h" +#include "gnunet_protocols.h" #include "fragmentation.h" + /** * Fragmentation context. */ @@ -77,6 +78,11 @@ struct GNUNET_FRAGMENT_Context */ GNUNET_SCHEDULER_TaskIdentifier task; + /** + * Our fragmentation ID. (chosen at random) + */ + uint32_t fragment_id; + /** * Round-robin selector for the next transmission. */ @@ -150,7 +156,9 @@ transmit_next (void *cls, fh = (struct FragmentHeader*) msg; fh->header.size = htons (fsize); fh->header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT); - /* FIXME: add specific ID info... */ + fh->fragment_id = htonl (fc->fragment_id); + fh->total_size = fc->msg->size; /* already in big-endian */ + fh->offset = htons (fc->mtu * bit); memcpy (&fc[1], &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))], fsize - sizeof (struct FragmentHeader)); @@ -236,6 +244,8 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, fc->msg = (const struct GNUNET_MessageHeader*)&fc[1]; fc->proc = proc; fc->proc_cls = proc_cls; + fc->fragment_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX); memcpy (&fc[1], msg, size); bits = (size + mtu - 1) / (mtu - sizeof (struct FragmentHeader)); GNUNET_assert (bits <= 64); @@ -275,9 +285,9 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, return GNUNET_SYSERR; } fa = (const struct FragmentAcknowledgement *) msg; + if (ntohl (fa->fragment_id) != fc->fragment_id) + return GNUNET_SYSERR; /* not our ACK */ abits = GNUNET_ntohll (fa->bits); - /* FIXME: match FA to us... */ - if (GNUNET_YES == fc->wack) { /* normal ACK, can update running average of delay... */ @@ -326,5 +336,6 @@ GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc) return ret; } + /* end of fragmentation_new.c */ -- 2.25.1