Skip to content

Commit

Permalink
PeerGroup.isAlreadyAdded(): refactor to ignore metadata and inline me…
Browse files Browse the repository at this point in the history
…thod because it is only used once.
  • Loading branch information
oscarguindzberg committed Apr 1, 2019
1 parent 3834e1f commit a1ed4be
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,17 +640,6 @@ 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 @@ -1876,7 +1865,14 @@ protected void handlePeerDeath(final Peer peer, @Nullable Throwable exception) {
} else {
backoffMap.get(address).trackFailure();
// Put back on inactive list
if (!isAlreadyAdded(address)) {
boolean inactiveContainsAddress = false;
for (PeerAddress a : inactives) {
if (a.equalsIgnoringMetadata(address)) {
inactiveContainsAddress = true;
break;
}
}
if (!inactiveContainsAddress) {
inactives.offer(address);
}
}
Expand Down

0 comments on commit a1ed4be

Please sign in to comment.