-only trigger check config if we actually need it
[oweals/gnunet.git] / src / fragmentation / fragmentation.c
index 6dad6d6d7a08c18ce35fbbbbc340b95d7fa4bf27..3a55502e71b03adfcde7e71778b48c1b8a8af73a 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     Copyright (C) 2009-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -167,11 +167,9 @@ GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack)
  * Transmit the next fragment to the other peer.
  *
  * @param cls the `struct GNUNET_FRAGMENT_Context`
- * @param tc scheduler context
  */
 static void
-transmit_next (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_next (void *cls)
 {
   struct GNUNET_FRAGMENT_Context *fc = cls;
   char msg[fc->mtu];
@@ -203,12 +201,19 @@ transmit_next (void *cls,
   else
     fsize = fc->mtu;
   if (NULL != fc->tracker)
-    delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, fsize);
+    delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker,
+                                                fsize);
   else
     delay = GNUNET_TIME_UNIT_ZERO;
   if (delay.rel_value_us > 0)
   {
-    fc->task = GNUNET_SCHEDULER_add_delayed (delay, &transmit_next, fc);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Fragmentation logic delays transmission of next fragment by %s\n",
+                GNUNET_STRINGS_relative_time_to_string (delay,
+                                                        GNUNET_YES));
+    fc->task = GNUNET_SCHEDULER_add_delayed (delay,
+                                             &transmit_next,
+                                             fc);
     return;
   }
   fc->next_transmission = (fc->next_transmission + 1) % 64;
@@ -255,7 +260,7 @@ transmit_next (void *cls,
     delay = GNUNET_TIME_UNIT_ZERO;
   delay = GNUNET_TIME_relative_max (delay,
                                    GNUNET_TIME_relative_multiply (fc->msg_delay,
-                                                                  (1 << fc->num_rounds)));
+                                                                  (1ULL << fc->num_rounds)));
   if (wrap)
   {
     /* full round transmitted wait 2x delay for ACK before going again */
@@ -273,7 +278,8 @@ transmit_next (void *cls,
   fc->proc_busy = GNUNET_YES;
   fc->delay_until = GNUNET_TIME_relative_to_absolute (delay);
   fc->num_transmissions++;
-  fc->proc (fc->proc_cls, &fh->header);
+  fc->proc (fc->proc_cls,
+            &fh->header);
 }
 
 
@@ -331,7 +337,8 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
   fc->proc = proc;
   fc->proc_cls = proc_cls;
   fc->fragment_id =
-      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                UINT32_MAX);
   memcpy (&fc[1], msg, size);
   bits =
       (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu -
@@ -411,10 +418,10 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
     snd_cnt = 0;
     for (i=0;i<64;i++)
     {
-      if (1 == (fc->acks_mask & (1 << i)))
+      if (1 == (fc->acks_mask & (1ULL << i)))
       {
        snd_cnt++;
-       if (0 == (abits & (1 << i)))
+       if (0 == (abits & (1ULL << i)))
          ack_cnt++;
       }
     }