use remainder from forward_count
authorNathan S. Evans <evans@in.tum.de>
Fri, 26 Nov 2010 15:07:34 +0000 (15:07 +0000)
committerNathan S. Evans <evans@in.tum.de>
Fri, 26 Nov 2010 15:07:34 +0000 (15:07 +0000)
src/dht/gnunet-service-dht.c

index acadd58b545cba6777d3b2f14e0d54eb8a02749b..fff683a7d74ae33a160fc8c75b8395484b687189 100644 (file)
@@ -2845,17 +2845,20 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
     }
 
   random_value = 0;
-  /* FIXME: we use diameter as the expected number of hops, but with randomized routing we will likely route to more! */
+  forward_count = 1;
   target_value = target_replication / (diameter + ((float)target_replication * hop_count));
   if (target_value > 1)
-    return (unsigned int)target_value;
+    {
+      /* Set forward count to floor of target_value */
+      forward_count = (unsigned int)target_value;
+      /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
+      target_value = target_value - forward_count;
+    }
   else
     random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int)-1);
 
   if (random_value < (target_value * (unsigned int)-1))
-    forward_count = 2;
-  else
-    forward_count = 1;
+    forward_count += 1;
 
   return forward_count;
 }