mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +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();
|
private final ReentrantLock lastPingTimesLock = new ReentrantLock();
|
||||||
@GuardedBy("lastPingTimesLock") private long[] lastPingTimes = null;
|
@GuardedBy("lastPingTimesLock") private long[] lastPingTimes = null;
|
||||||
private final CopyOnWriteArrayList<PendingPing> pendingPings;
|
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 static final int PING_MOVING_AVERAGE_WINDOW = 20;
|
||||||
|
|
||||||
private volatile VersionMessage vPeerVersionMessage;
|
private volatile VersionMessage vPeerVersionMessage;
|
||||||
|
@ -1552,6 +1554,10 @@ public class Peer extends PeerSocketHandler {
|
||||||
final VersionMessage ver = vPeerVersionMessage;
|
final VersionMessage ver = vPeerVersionMessage;
|
||||||
if (!ver.isPingPongSupported())
|
if (!ver.isPingPongSupported())
|
||||||
throw new ProtocolException("Peer version is too low for measurable pings: " + ver);
|
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);
|
PendingPing pendingPing = new PendingPing(nonce);
|
||||||
pendingPings.add(pendingPing);
|
pendingPings.add(pendingPing);
|
||||||
sendMessage(new Ping(pendingPing.nonce));
|
sendMessage(new Ping(pendingPing.nonce));
|
||||||
|
|
Loading…
Add table
Reference in a new issue