diff --git a/core/src/main/java/org/bitcoinj/core/PeerGroup.java b/core/src/main/java/org/bitcoinj/core/PeerGroup.java index 09bca468723..aea67607227 100644 --- a/core/src/main/java/org/bitcoinj/core/PeerGroup.java +++ b/core/src/main/java/org/bitcoinj/core/PeerGroup.java @@ -619,7 +619,9 @@ public void go() { if (retryTime > now) { long delay = retryTime - now; log.info("Waiting {} msec before next connect attempt {}", delay, addrToTry == null ? "" : "to " + addrToTry); - inactives.add(addrToTry); + + if (!isAlreadyAdded(addrToTry)) + inactives.add(addrToTry); executor.schedule(this, delay, TimeUnit.MILLISECONDS); return; } @@ -633,6 +635,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()) @@ -1033,7 +1046,10 @@ private boolean addInactive(PeerAddress peerAddress) { return false; } backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams)); - inactives.offer(peerAddress); + + if (!isAlreadyAdded(peerAddress)) + inactives.offer(peerAddress); + return true; } finally { lock.unlock();