mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 12:01:24 +00:00
PeerGroup.addAddress(): Don't increase max connections if address already exists.
This commit is contained in:
committed by
Andreas Schildbach
parent
aba000750c
commit
a9b40c358f
@@ -860,22 +860,26 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
int newMax;
|
int newMax;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
addInactive(peerAddress);
|
if (addInactive(peerAddress)) {
|
||||||
newMax = getMaxConnections() + 1;
|
newMax = getMaxConnections() + 1;
|
||||||
|
setMaxConnections(newMax);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
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();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Deduplicate
|
// Deduplicate
|
||||||
if (backoffMap.containsKey(peerAddress))
|
if (backoffMap.containsKey(peerAddress))
|
||||||
return;
|
return false;
|
||||||
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
|
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
|
||||||
inactives.offer(peerAddress);
|
inactives.offer(peerAddress);
|
||||||
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user