From 6ef071b8ccea72da6a9e1eee6483c326b6ebc082 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Oct 2021 18:53:37 +0200 Subject: fix #7029 --- src/dht/gnunet-service-dht_neighbours.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') 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, uint32_t forward_count; float target_value; + if (0 == target_replication) + target_replication = 1; /* 0 is verboten */ + if (target_replication > MAXIMUM_REPLICATION_LEVEL) + target_replication = MAXIMUM_REPLICATION_LEVEL; if (hop_count > GDS_NSE_get () * 4.0) { /* forcefully terminate */ @@ -864,6 +868,8 @@ get_forward_count (uint32_t hop_count, 1 + (target_replication - 1.0) / (GDS_NSE_get () + ((float) (target_replication - 1.0) * hop_count)); + + /* Set forward count to floor of target_value */ forward_count = (uint32_t) target_value; /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ @@ -872,7 +878,8 @@ get_forward_count (uint32_t hop_count, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); if (random_value < (target_value * UINT32_MAX)) forward_count++; - return forward_count; + return GNUNET_MIN (forward_count, + MAXIMUM_REPLICATION_LEVEL); } -- cgit v1.2.3