aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-01-31 12:32:27 +0000
committerNathan S. Evans <evans@in.tum.de>2011-01-31 12:32:27 +0000
commitc2fab216d2d9f0bd0fea0f392ea1d11147e344fb (patch)
treea5e301649b4d0251f1400722924e27a9225fadc2 /src/dht/gnunet-service-dht.c
parent8dedbcc97bc3b21e698ed6a069e5cefa80cb27f2 (diff)
downloadgnunet-c2fab216d2d9f0bd0fea0f392ea1d11147e344fb.tar.gz
gnunet-c2fab216d2d9f0bd0fea0f392ea1d11147e344fb.zip
option to always forward until a closest peer is found, exact formula as described in paper
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c60
1 files changed, 48 insertions, 12 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index b7778df8b..366453e82 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -733,6 +733,13 @@ static unsigned int do_find_peer;
733static unsigned int do_republish; 733static unsigned int do_republish;
734 734
735/** 735/**
736 * Use exactly the forwarding formula as described in
737 * the paper if set to GNUNET_YES, otherwise use the
738 * slightly modified version.
739 */
740static unsigned int paper_forwarding;
741
742/**
736 * Use the "real" distance metric when selecting the 743 * Use the "real" distance metric when selecting the
737 * next routing hop. Can be less accurate. 744 * next routing hop. Can be less accurate.
738 */ 745 */
@@ -2941,28 +2948,50 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
2941 "`%s:%s': Hop count too high (est %d, lowest %d), NOT Forwarding request\n", 2948 "`%s:%s': Hop count too high (est %d, lowest %d), NOT Forwarding request\n",
2942 my_short_id, "DHT", estimate_diameter (), lowest_bucket); 2949 my_short_id, "DHT", estimate_diameter (), lowest_bucket);
2943#endif 2950#endif
2951 /* FIXME: does this work as intended, isn't the decision to forward or not made based on closeness as well? */
2952 if (GNUNET_YES == paper_forwarding) /* Once we have reached our ideal number of hops, don't stop forwarding! */
2953 {
2954 return 1;
2955 }
2956
2944 return 0; 2957 return 0;
2945 } 2958 }
2946 2959
2947 random_value = 0; 2960 if (GNUNET_YES == paper_forwarding)
2948 forward_count = 1;
2949 target_value =
2950 target_replication / (diameter +
2951 ((float) target_replication * hop_count));
2952 if (target_value > 1)
2953 { 2961 {
2962 /* FIXME: re-run replication trials with this formula */
2963 target_value = 1 + (target_replication - 1.0) / (diameter
2964 + ((float) (target_replication - 1.0) * hop_count));
2954 /* Set forward count to floor of target_value */ 2965 /* Set forward count to floor of target_value */
2955 forward_count = (unsigned int) target_value; 2966 forward_count = (unsigned int) target_value;
2956 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 2967 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
2957 target_value = target_value - forward_count; 2968 target_value = target_value - forward_count;
2969 random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG,
2970 UINT32_MAX);
2971
2972 if (random_value < (target_value * UINT32_MAX))
2973 forward_count += 1;
2958 } 2974 }
2959 else 2975 else
2960 random_value = 2976 {
2961 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 2977 random_value = 0;
2962 UINT32_MAX); 2978 forward_count = 1;
2979 target_value = target_replication / (diameter
2980 + ((float) target_replication * hop_count));
2981 if (target_value > 1)
2982 {
2983 /* Set forward count to floor of target_value */
2984 forward_count = (unsigned int) target_value;
2985 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
2986 target_value = target_value - forward_count;
2987 }
2988 else
2989 random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG,
2990 UINT32_MAX);
2963 2991
2964 if (random_value < (target_value * UINT32_MAX)) 2992 if (random_value < (target_value * UINT32_MAX))
2965 forward_count += 1; 2993 forward_count += 1;
2994 }
2966 2995
2967 return forward_count; 2996 return forward_count;
2968} 2997}
@@ -5246,6 +5275,13 @@ run (void *cls,
5246 GNUNET_free (converge_modifier_buf); 5275 GNUNET_free (converge_modifier_buf);
5247 } 5276 }
5248 5277
5278 if (GNUNET_YES ==
5279 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "paper_forwarding"))
5280 {
5281 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Forwarding strictly according to paper!\n");
5282 paper_forwarding = GNUNET_YES;
5283 }
5284
5249 stats = GNUNET_STATISTICS_create ("dht", cfg); 5285 stats = GNUNET_STATISTICS_create ("dht", cfg);
5250 5286
5251 if (stats != NULL) 5287 if (stats != NULL)