forked from I2P_Developers/i2p.i2p
Router: Don't let context clock shifts affect calculated uptime
This commit is contained in:
@@ -522,13 +522,19 @@ public class Router implements RouterClock.ClockShiftListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used only by routerconsole.. to be deprecated?
|
* Used only by routerconsole.. to be deprecated?
|
||||||
|
* @return System time, NOT context time
|
||||||
*/
|
*/
|
||||||
public long getWhenStarted() { return _started; }
|
public long getWhenStarted() { return _started; }
|
||||||
|
|
||||||
/** wall clock uptime */
|
/**
|
||||||
|
* Wall clock uptime.
|
||||||
|
* This uses System time, NOT context time, so context clock shifts will
|
||||||
|
* not affect it. This is important if NTP fails and the
|
||||||
|
* clock then shifts from a SSU peer source just after startup.
|
||||||
|
*/
|
||||||
public long getUptime() {
|
public long getUptime() {
|
||||||
if ( (_context == null) || (_context.clock() == null) ) return 1; // racing on startup
|
if (_started <= 0) return 1000; // racing on startup
|
||||||
return Math.max(1, _context.clock().now() - _context.clock().getOffset() - _started);
|
return Math.max(1000, System.currentTimeMillis() - _started);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -566,7 +572,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
|||||||
_eventLog.addEvent(EventLog.STARTED, RouterVersion.FULL_VERSION);
|
_eventLog.addEvent(EventLog.STARTED, RouterVersion.FULL_VERSION);
|
||||||
startupStuff();
|
startupStuff();
|
||||||
changeState(State.STARTING_2);
|
changeState(State.STARTING_2);
|
||||||
_started = _context.clock().now();
|
_started = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().addShutdownHook(_shutdownHook);
|
Runtime.getRuntime().addShutdownHook(_shutdownHook);
|
||||||
} catch (IllegalStateException ise) {}
|
} catch (IllegalStateException ise) {}
|
||||||
|
Reference in New Issue
Block a user