From 060fab4d8fb050e906b46f8dbc05ef4017e626f0 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Sat, 4 Jan 2025 17:56:13 +0100 Subject: [PATCH] fix busy loop if all darknet peers are connected. --- src/freenet/node/DNSRequester.java | 38 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/freenet/node/DNSRequester.java b/src/freenet/node/DNSRequester.java index e21f07da92..4d2581cb98 100644 --- a/src/freenet/node/DNSRequester.java +++ b/src/freenet/node/DNSRequester.java @@ -81,29 +81,27 @@ private void realRun() { } int unconnectedNodesLength = nodesToCheck.length; - if (unconnectedNodesLength == 0) { - return; // nothing to do - } - // check a randomly chosen node that has not been checked - // recently to avoid sending bursts of DNS requests - PeerNode pn = nodesToCheck[node.getFastWeakRandom().nextInt(unconnectedNodesLength)]; - if (unconnectedNodesLength < 5) { - // no need for optimizations: just clear all state - recentNodeIdentitySet.clear(); - recentNodeIdentityQueue.clear(); - } else { - // do not request this node again, - // until at least 81% of the other unconnected nodes have been checked - recentNodeIdentitySet.add(pn.getLocation()); - recentNodeIdentityQueue.offerFirst(pn.getLocation()); - while (recentNodeIdentityQueue.size() > (0.81 * unconnectedNodesLength)) { - recentNodeIdentitySet.remove(recentNodeIdentityQueue.removeLast()); + if (unconnectedNodesLength > 0) { + // check a randomly chosen node that has not been checked + // recently to avoid sending bursts of DNS requests + PeerNode pn = nodesToCheck[node.getFastWeakRandom().nextInt(unconnectedNodesLength)]; + if (unconnectedNodesLength < 5) { + // no need for optimizations: just clear all state + recentNodeIdentitySet.clear(); + recentNodeIdentityQueue.clear(); + } else { + // do not request this node again, + // until at least 81% of the other unconnected nodes have been checked + recentNodeIdentitySet.add(pn.getLocation()); + recentNodeIdentityQueue.offerFirst(pn.getLocation()); + while (recentNodeIdentityQueue.size() > (0.81 * unconnectedNodesLength)) { + recentNodeIdentitySet.remove(recentNodeIdentityQueue.removeLast()); + } } + // Try new DNS lookup + pn.maybeUpdateHandshakeIPs(false); } - // Try new DNS lookup - pn.maybeUpdateHandshakeIPs(false); - int nextMaxWaitTime = 1000 + node.getFastWeakRandom().nextInt(60000); try { synchronized(this) {