Skip to content

Commit

Permalink
PeerGroup: Limit number of Bitcoin network peers at re-connect after …
Browse files Browse the repository at this point in the history
…connection loss

Cherry pick e112b13
Cherry pick 093d5e4
Cherry pick cbac863
  • Loading branch information
oscarguindzberg committed Feb 12, 2019
1 parent 34461fe commit 3f1382d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,12 @@ public void go() {
executor.schedule(this, delay, TimeUnit.MILLISECONDS);
return;
}
connectTo(addrToTry, false, vConnectTimeoutMillis);

// BitcoinJ gets too many connections after a connection loss and reconnect as it adds up a lot of
// potential candidates and then try to connect to all of those when getting connection again.
// A check for maxConnections is required to not exceed connections.
if(pendingPeers.size() + peers.size() < maxConnections)
connectTo(addrToTry, false, vConnectTimeoutMillis);
} finally {
lock.unlock();
}
Expand Down

0 comments on commit 3f1382d

Please sign in to comment.