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

PeerGroup.addAddress(): don't increase max connections if address alr… #1741

Closed
Closed
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
17 changes: 11 additions & 6 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,22 +860,27 @@ public void addAddress(PeerAddress peerAddress) {
int newMax;
lock.lock();
try {
addInactive(peerAddress);
newMax = getMaxConnections() + 1;
if(addInactive(peerAddress)) {
newMax = getMaxConnections() + 1;
setMaxConnections(newMax);
}
} finally {
lock.unlock();
}
setMaxConnections(newMax);
}

private void addInactive(PeerAddress peerAddress) {
// Adds peerAddress to backoffMap map nd inactives queue.
// Returns true if it was added, false if it was already there.
private boolean addInactive(PeerAddress peerAddress) {
lock.lock();
try {
// Deduplicate
if (backoffMap.containsKey(peerAddress))
return;
if (backoffMap.containsKey(peerAddress)) {
return false;
}
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
inactives.offer(peerAddress);
return true;
} finally {
lock.unlock();
}
Expand Down