mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 06:47:54 +01:00
Peer: Disconnect remote peers which repeatedly don't respond to pings.
This commit is contained in:
parent
ce9801f7e3
commit
29f450b860
1 changed files with 6 additions and 0 deletions
|
@ -149,6 +149,8 @@ public class Peer extends PeerSocketHandler {
|
|||
private final ReentrantLock lastPingTimesLock = new ReentrantLock();
|
||||
@GuardedBy("lastPingTimesLock") private long[] lastPingTimes = null;
|
||||
private final CopyOnWriteArrayList<PendingPing> pendingPings;
|
||||
// Disconnect from a peer that is not responding to Pings
|
||||
private static final int PENDING_PINGS_LIMIT = 50;
|
||||
private static final int PING_MOVING_AVERAGE_WINDOW = 20;
|
||||
|
||||
private volatile VersionMessage vPeerVersionMessage;
|
||||
|
@ -1552,6 +1554,10 @@ public class Peer extends PeerSocketHandler {
|
|||
final VersionMessage ver = vPeerVersionMessage;
|
||||
if (!ver.isPingPongSupported())
|
||||
throw new ProtocolException("Peer version is too low for measurable pings: " + ver);
|
||||
if (pendingPings.size() > PENDING_PINGS_LIMIT) {
|
||||
log.info("{}: Too many pending pings, disconnecting", this);
|
||||
close();
|
||||
}
|
||||
PendingPing pendingPing = new PendingPing(nonce);
|
||||
pendingPings.add(pendingPing);
|
||||
sendMessage(new Ping(pendingPing.nonce));
|
||||
|
|
Loading…
Add table
Reference in a new issue