Skip to content

Commit

Permalink
Fix: at less than 5 unconnected nodes no optimization is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Nov 30, 2024
1 parent 1cf9ed5 commit 8957221
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/freenet/node/DNSRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,18 @@ private void realRun() {
// recently to avoid sending bursts of DNS requests
int unconnectedNodesLength = nodesToCheck.length;
PeerNode pn = nodesToCheck[node.getFastWeakRandom().nextInt(unconnectedNodesLength)];
// do not request this node again,
// until at least 80% of the other unconnected nodes have been checked
recentNodeIdentitySet.add(pn.getLocation());
recentNodeIdentityQueue.offerFirst(pn.getLocation());
while (unconnectedNodesLength > 5 && recentNodeIdentityQueue.size() > (0.81 * unconnectedNodesLength)) {
recentNodeIdentitySet.remove(recentNodeIdentityQueue.removeLast());
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 80% 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());
}
}
//Logger.minor(this, "Node: "+pn);

Expand Down

0 comments on commit 8957221

Please sign in to comment.