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
  • Loading branch information
ManfredKarrer authored and oscarguindzberg committed Apr 10, 2019
1 parent 3fe0e8c commit 66ddb8f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ public void go() {
}
};

private boolean isAlreadyAdded(PeerAddress peerAddress) {
boolean isAlreadyAdded = false;
for (PeerAddress a : inactives) {
if (a.getHostname() != null && a.getHostname().equals(peerAddress.getHostname())) {
isAlreadyAdded = true;
break;
}
}
return isAlreadyAdded;
}

private void triggerConnections() {
// Run on a background thread due to the need to potentially retry and back off in the background.
if (!executor.isShutdown())
Expand Down Expand Up @@ -879,6 +890,7 @@ private boolean addInactive(PeerAddress peerAddress) {
}
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
inactives.offer(peerAddress);

return true;
} finally {
lock.unlock();
Expand Down

0 comments on commit 66ddb8f

Please sign in to comment.