aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index ca255310c..6465d8d57 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -844,6 +844,10 @@ get_forward_count (uint32_t hop_count,
844 uint32_t forward_count; 844 uint32_t forward_count;
845 float target_value; 845 float target_value;
846 846
847 if (0 == target_replication)
848 target_replication = 1; /* 0 is verboten */
849 if (target_replication > MAXIMUM_REPLICATION_LEVEL)
850 target_replication = MAXIMUM_REPLICATION_LEVEL;
847 if (hop_count > GDS_NSE_get () * 4.0) 851 if (hop_count > GDS_NSE_get () * 4.0)
848 { 852 {
849 /* forcefully terminate */ 853 /* forcefully terminate */
@@ -864,6 +868,8 @@ get_forward_count (uint32_t hop_count,
864 1 + (target_replication - 1.0) / (GDS_NSE_get () 868 1 + (target_replication - 1.0) / (GDS_NSE_get ()
865 + ((float) (target_replication - 1.0) 869 + ((float) (target_replication - 1.0)
866 * hop_count)); 870 * hop_count));
871
872
867 /* Set forward count to floor of target_value */ 873 /* Set forward count to floor of target_value */
868 forward_count = (uint32_t) target_value; 874 forward_count = (uint32_t) target_value;
869 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 875 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
@@ -872,7 +878,8 @@ get_forward_count (uint32_t hop_count,
872 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 878 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
873 if (random_value < (target_value * UINT32_MAX)) 879 if (random_value < (target_value * UINT32_MAX))
874 forward_count++; 880 forward_count++;
875 return forward_count; 881 return GNUNET_MIN (forward_count,
882 MAXIMUM_REPLICATION_LEVEL);
876} 883}
877 884
878 885