allow bucket size, kademlia replication to be set by configuration, increase base...
authorNathan S. Evans <evans@in.tum.de>
Wed, 24 Nov 2010 13:42:41 +0000 (13:42 +0000)
committerNathan S. Evans <evans@in.tum.de>
Wed, 24 Nov 2010 13:42:41 +0000 (13:42 +0000)
src/dht/gnunet-service-dht.c

index 823ad0f55f82eb676bd23ae0e53b80a12d746118..224ac6c460294f00c064695d17e19be65cc1bdba 100644 (file)
 /**
  * How many initial requests to send out (in true Kademlia fashion)
  */
-#define DHT_KADEMLIA_REPLICATION 3
+#define DEFAULT_KADEMLIA_REPLICATION 3
 
 /*
  * Default frequency for sending malicious get messages
@@ -309,7 +309,7 @@ struct PeerInfo
    * be considered a really bad idea.
    * FIXME: remove this value (create struct which holds
    *        a single peerinfo and the matching bits, use
-   *        that to pass to comparitor)
+   *        that to pass to comparator)
    */
   unsigned int matching_bits;
 
@@ -881,6 +881,11 @@ static unsigned long long malicious_get_frequency;
  */
 static unsigned long long malicious_put_frequency;
 
+/**
+ * Kademlia replication
+ */
+static unsigned long long kademlia_replication;
+
 /**
  * Reply times for requests, if we are busy, don't send any
  * more requests!
@@ -2730,6 +2735,11 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
   float target_value;
   unsigned int diameter;
 
+  diameter = estimate_diameter ();
+
+  if (GNUNET_NO == use_max_hops)
+    max_hops = (diameter + 1) * 2;
+
   /**
    * If we are behaving in strict kademlia mode, send multiple initial requests,
    * but then only send to 1 or 0 peers based strictly on the number of hops.
@@ -2737,7 +2747,7 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
   if (strict_kademlia == GNUNET_YES)
     {
       if (hop_count == 0)
-        return DHT_KADEMLIA_REPLICATION;
+        return kademlia_replication;
       else if (hop_count < max_hops)
         return 1;
       else
@@ -2748,28 +2758,19 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
    * routing right?  The estimation below only works if we think we have reasonably
    * full routing tables, which for our RR topologies may not be the case!
    */
-  diameter = estimate_diameter ();
-  if ((hop_count > (diameter + 1) * 2) && (MINIMUM_PEER_THRESHOLD < estimate_diameter() * bucket_size) && (use_max_hops == GNUNET_NO))
+  if (hop_count > max_hops)
     {
 #if DEBUG_DHT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "`%s:%s': Hop count too high (est %d, lowest %d), NOT Forwarding request\n", my_short_id,
                   "DHT", estimate_diameter(), lowest_bucket);
-#endif
-      return 0;
-    }
-  else if (hop_count > max_hops)
-    {
-#if DEBUG_DHT
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "`%s:%s': Hop count too high (greater than max)\n", my_short_id,
-                  "DHT");
 #endif
       return 0;
     }
 
   random_value = 0;
-  target_value = target_replication / ((2.0 * (diameter)) + ((float)target_replication * hop_count));
+  /* FIXME: we use diameter as the expected number of hops, but with randomized routing we will likely route to more! */
+  target_value = target_replication / (diameter + ((float)target_replication * hop_count));
   if (target_value > 1)
     return (unsigned int)target_value;
   else
@@ -4665,6 +4666,16 @@ run (void *cls,
       dht_republish_frequency = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, temp_config_num);
     }
 
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "DHT", "bucket_size", &temp_config_num))
+    {
+      bucket_size = (unsigned int)temp_config_num;
+    }
+
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, "DHT", "kad_alpha", &kademlia_replication))
+    {
+      kademlia_replication = DEFAULT_KADEMLIA_REPLICATION;
+    }
+
   if (GNUNET_YES ==
           GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht",
                                                "malicious_dropper"))