From 00d6a496534aa78843047973a20d262f9966af7b Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 11 Dec 2015 17:11:16 +0000 Subject: [PATCH] Router: Don't let context clock shifts affect calculated uptime --- router/java/src/net/i2p/router/Router.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 5817446512..e52a079cc6 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -522,13 +522,19 @@ public class Router implements RouterClock.ClockShiftListener { /** * Used only by routerconsole.. to be deprecated? + * @return System time, NOT context time */ 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() { - if ( (_context == null) || (_context.clock() == null) ) return 1; // racing on startup - return Math.max(1, _context.clock().now() - _context.clock().getOffset() - _started); + if (_started <= 0) return 1000; // racing on startup + return Math.max(1000, System.currentTimeMillis() - _started); } /** @@ -566,7 +572,7 @@ public class Router implements RouterClock.ClockShiftListener { _eventLog.addEvent(EventLog.STARTED, RouterVersion.FULL_VERSION); startupStuff(); changeState(State.STARTING_2); - _started = _context.clock().now(); + _started = System.currentTimeMillis(); try { Runtime.getRuntime().addShutdownHook(_shutdownHook); } catch (IllegalStateException ise) {} -- GitLab