Skip to content

Commit

Permalink
PeerGroup: Add check to not duplicate peers
Browse files Browse the repository at this point in the history
The inactives collection contained duplicated peerAddresses after
connection loss and reconnect.
We add a check to see if the to-get-added peerAddress is not already
in the collection and only add it if it is absent.
This problem was not discovered when using the public network as the
chance that same peerAddress get reported is pretty low. But with our
provided nodes we got frequently duplicates.

Fixes bisq-network/bisq#1703

Cherry-pick 34461fe

PeerGroup.triggerConnectionsJob: Remove isAlreadyAdded() check because it is not necessary.

Cherry pick 3185434

PeerGroup.addInactive(): Remove isAlreadyAdded() check because it is not necessary.

Cherry pick 7dfab73

PeerGroup.handlePeerDeath(): check isAlreadyAdded() before calling inactives.offer(address).

Cherry pick de6ca8b

PeerGroup.isAlreadyAdded(): refactor to ignore metadata and inline method because it is only used once.

Cherry pick f790821
  • Loading branch information
ManfredKarrer authored and oscarguindzberg committed May 16, 2020
1 parent 321aa8a commit 76f589d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ private boolean addInactive(PeerAddress peerAddress, int priority) {
if (priority != 0)
priorityMap.put(peerAddress, priority);
inactives.offer(peerAddress);

return true;
} finally {
lock.unlock();
Expand Down Expand Up @@ -1706,7 +1707,16 @@ protected void handlePeerDeath(final Peer peer, @Nullable Throwable exception) {
} else {
backoffMap.get(address).trackFailure();
// Put back on inactive list
inactives.offer(address);
boolean inactiveContainsAddress = false;
for (PeerAddress a : inactives) {
if (a.equalsIgnoringMetadata(address)) {
inactiveContainsAddress = true;
break;
}
}
if (!inactiveContainsAddress) {
inactives.offer(address);
}
}

if (numPeers < getMaxConnections()) {
Expand Down

0 comments on commit 76f589d

Please sign in to comment.