commit a0fd1312543aea6391b5a391153ce3672f1bbd6a
parent 4642b0748c466736c5fddb72133ab698b5f4fbd0
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Thu, 6 Aug 2026 18:16:25 +0200
dht: never route with a zero network size estimate
Diffstat:
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/service/dht/gnunet-service-dht.c b/src/service/dht/gnunet-service-dht.c
@@ -176,7 +176,7 @@ static struct MyAddress *a_tail;
* log of the current network size estimate, used as the point where
* we switch between random and deterministic routing.
*/
-static double log_of_network_size_estimate;
+static double log_of_network_size_estimate = MINIMUM_LOG_NSE;
/**
* Are we already serving clients? We suspend the service until PILS
@@ -207,14 +207,14 @@ update_network_size_estimate (void *cls,
"# Network size estimates received",
1,
GNUNET_NO);
- /* do not allow estimates < 0.5 */
+ /* do not allow estimates < #MINIMUM_LOG_NSE */
u->network_size_estimate = pow (2.0,
- GNUNET_MAX (0.5,
+ GNUNET_MAX (MINIMUM_LOG_NSE,
logestimate));
for (struct GDS_Underlay *p = u_head; NULL != p; p = p->next)
sum += p->network_size_estimate;
if (sum <= 2.0)
- log_of_network_size_estimate = 0.5;
+ log_of_network_size_estimate = MINIMUM_LOG_NSE;
else
log_of_network_size_estimate = log2 (sum);
}
diff --git a/src/service/dht/gnunet-service-dht.h b/src/service/dht/gnunet-service-dht.h
@@ -193,6 +193,15 @@ GDS_CLIENTS_process_put (const struct GNUNET_DATACACHE_Block *bd,
uint32_t desired_replication_level);
/**
+ * Floor for the log of the network size estimate, and the value we use
+ * before the NSE service has told us anything. Routing divides by the
+ * estimate and drops requests whose hop count exceeds a multiple of it,
+ * so zero is not a usable "unknown".
+ */
+#define MINIMUM_LOG_NSE 0.5
+
+
+/**
* Our routing table gained a peer. Reset the retry back-off of all
* pending client GET requests and re-transmit them now: a request that
* found no route earlier has been backing off for up to 15 minutes
diff --git a/src/service/dht/gnunet-service-dht_neighbours.c b/src/service/dht/gnunet-service-dht_neighbours.c
@@ -824,8 +824,13 @@ get_forward_count (uint16_t hop_count,
uint32_t forward_count;
float target_value;
double rm1;
+ double nse = GDS_NSE_get ();
- if (hop_count > GDS_NSE_get () * 4.0)
+ /* Guard the divisor below: an NSE of zero would make target_value
+ infinite (or NaN), and the conversion to uint32_t undefined. */
+ if (! (nse >= MINIMUM_LOG_NSE))
+ nse = MINIMUM_LOG_NSE;
+ if (hop_count > nse * 4.0)
{
/* forcefully terminate */
GNUNET_STATISTICS_update (GDS_stats,
@@ -834,7 +839,7 @@ get_forward_count (uint16_t hop_count,
GNUNET_NO);
return 0;
}
- if (hop_count > GDS_NSE_get () * 2.0)
+ if (hop_count > nse * 2.0)
{
/* Once we have reached our ideal number of hops, only forward to 1 peer */
return 1;
@@ -847,7 +852,7 @@ get_forward_count (uint16_t hop_count,
target_replication);
rm1 = target_replication - 1.0;
target_value =
- 1 + (rm1) / (GDS_NSE_get () + (rm1 * hop_count));
+ 1 + (rm1) / (nse + (rm1 * hop_count));
/* Set forward count to floor of target_value */
forward_count = (uint32_t) target_value;