Skip to content

Commit

Permalink
Merge branch 'dns-requester-avoid-busy-loop-on-dns-request' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Jan 6, 2025
2 parents c2351e0 + 060fab4 commit a921c7d
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/freenet/node/DNSRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a921c7d

Please sign in to comment.