Skip to content

Commit

Permalink
Limit nr. of Bitcoin network peers at re-connect after connection loss
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Jun 16, 2016
1 parent bca80f0 commit e112b13
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,14 @@ protected Peer connectTo(PeerAddress address, boolean incrementMaxConnections, i
ver.time = Utils.currentTimeSeconds();

Peer peer = new Peer(params, ver, address, chain, downloadTxDependencies);

// 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.
// TODO: Review if the return of the peer cause any issues.
if(pendingPeers.size() + peers.size() >= maxConnections)
return peer;

peer.addEventListener(startupListener, Threading.SAME_THREAD);
peer.setMinProtocolVersion(vMinRequiredProtocolVersion);
pendingPeers.add(peer);
Expand Down

0 comments on commit e112b13

Please sign in to comment.