gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r15912 - gnunet/src/fragmentation


From: gnunet
Subject: [GNUnet-SVN] r15912 - gnunet/src/fragmentation
Date: Sat, 9 Jul 2011 18:31:09 +0200

Author: grothoff
Date: 2011-07-09 18:31:09 +0200 (Sat, 09 Jul 2011)
New Revision: 15912

Modified:
   gnunet/src/fragmentation/fragmentation.h
   gnunet/src/fragmentation/fragmentation_new.c
Log:
frag

Modified: gnunet/src/fragmentation/fragmentation.h
===================================================================
--- gnunet/src/fragmentation/fragmentation.h    2011-07-09 16:21:14 UTC (rev 
15911)
+++ gnunet/src/fragmentation/fragmentation.h    2011-07-09 16:31:09 UTC (rev 
15912)
@@ -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,9 +64,17 @@
 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
    * have not yet been received).

Modified: gnunet/src/fragmentation/fragmentation_new.c
===================================================================
--- gnunet/src/fragmentation/fragmentation_new.c        2011-07-09 16:21:14 UTC 
(rev 15911)
+++ gnunet/src/fragmentation/fragmentation_new.c        2011-07-09 16:31:09 UTC 
(rev 15912)
@@ -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.
  */
@@ -78,6 +79,11 @@
   GNUNET_SCHEDULER_TaskIdentifier task;
 
   /**
+   * Our fragmentation ID. (chosen at random)
+   */
+  uint32_t fragment_id;
+
+  /**
    * Round-robin selector for the next transmission.
    */
   unsigned int next_transmission;
@@ -150,7 +156,9 @@
   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 @@
   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 @@
       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 @@
   return ret;
 }
 
+
 /* end of fragmentation_new.c */
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]