Skip to content

Commit

Permalink
PeerGroup.addAddress(): don't increase max connections if address alr…
Browse files Browse the repository at this point in the history
…eady exist
  • Loading branch information
oscarguindzberg committed Feb 12, 2019
1 parent b87c8db commit 011fe40
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,22 +979,25 @@ 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) {
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

0 comments on commit 011fe40

Please sign in to comment.