frag
authorChristian Grothoff <christian@grothoff.org>
Sat, 9 Jul 2011 16:31:09 +0000 (16:31 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 9 Jul 2011 16:31:09 +0000 (16:31 +0000)
src/fragmentation/fragmentation.h
src/fragmentation/fragmentation_new.c

index 9473fa31a7c5bdee21d863914fd8fd5fa5de2829..3469dd27ed2fc99aa1b13ca51cd0d35e0b897ed2 100644 (file)
 #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
index 66633e4c1cc4012811e698cba7fe1238183de0fb..6a2747e4d1bc8e3cf05cb7f0ef420cc4d1f35e6d 100644 (file)
  * @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 */