mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 06:47:54 +01:00
PeerGroup.addAddress(): Don't increase max connections if address already exists.
This commit is contained in:
parent
0ea885fa10
commit
8931c58dca
1 changed files with 9 additions and 5 deletions
|
@ -860,22 +860,26 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||
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 and 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;
|
||||
return false;
|
||||
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
|
||||
inactives.offer(peerAddress);
|
||||
return true;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue