Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix busy loop if all darknet peers are connected. #1031

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading