mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 23:03:04 +00:00
Fix a bug that could cause pinging a remote node as fast as it will respond.
This commit is contained in:
parent
9a0950e578
commit
0608b3a383
@ -101,7 +101,7 @@ public class PeerGroup extends AbstractIdleService {
|
|||||||
// and network latency. We ping peers every pingIntervalMsec milliseconds.
|
// and network latency. We ping peers every pingIntervalMsec milliseconds.
|
||||||
private Timer pingTimer;
|
private Timer pingTimer;
|
||||||
/** How many milliseconds to wait after receiving a pong before sending another ping. */
|
/** How many milliseconds to wait after receiving a pong before sending another ping. */
|
||||||
public static final long DEFAULT_PING_INTERVAL_MSEC = 5000;
|
public static final long DEFAULT_PING_INTERVAL_MSEC = 1000;
|
||||||
private long pingIntervalMsec = DEFAULT_PING_INTERVAL_MSEC;
|
private long pingIntervalMsec = DEFAULT_PING_INTERVAL_MSEC;
|
||||||
|
|
||||||
private final NetworkParameters params;
|
private final NetworkParameters params;
|
||||||
@ -793,7 +793,8 @@ public class PeerGroup extends AbstractIdleService {
|
|||||||
return; // Disabled.
|
return; // Disabled.
|
||||||
// Start the process of pinging the peer. Do a ping right now and then ensure there's a fixed delay between
|
// Start the process of pinging the peer. Do a ping right now and then ensure there's a fixed delay between
|
||||||
// each ping. If the peer is taken out of the peers list then the cycle will stop.
|
// each ping. If the peer is taken out of the peers list then the cycle will stop.
|
||||||
new Runnable() {
|
final Runnable[] pingRunnable = new Runnable[1];
|
||||||
|
pingRunnable[0] = new Runnable() {
|
||||||
private boolean firstRun = true;
|
private boolean firstRun = true;
|
||||||
public void run() {
|
public void run() {
|
||||||
// Ensure that the first ping happens immediately and later pings after the requested delay.
|
// Ensure that the first ping happens immediately and later pings after the requested delay.
|
||||||
@ -817,14 +818,15 @@ public class PeerGroup extends AbstractIdleService {
|
|||||||
try {
|
try {
|
||||||
if (!peers.contains(peer) || !PeerGroup.this.isRunning())
|
if (!peers.contains(peer) || !PeerGroup.this.isRunning())
|
||||||
return; // Peer was removed/shut down.
|
return; // Peer was removed/shut down.
|
||||||
peer.ping().addListener(this, MoreExecutors.sameThreadExecutor());
|
peer.ping().addListener(pingRunnable[0], MoreExecutors.sameThreadExecutor());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("{}: Exception whilst trying to ping peer: {}", peer, e.toString());
|
log.warn("{}: Exception whilst trying to ping peer: {}", peer, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, interval);
|
}, interval);
|
||||||
}
|
}
|
||||||
}.run();
|
};
|
||||||
|
pingRunnable[0].run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if at least one peer received an inv. */
|
/** Returns true if at least one peer received an inv. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user