From 2f98d05e7c7266d6116682567e8648b1ac1781e9 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sun, 9 Sep 2012 15:45:29 +0000
Subject: [PATCH]   * Clock: Synchronization, log large shifts to event log

---
 core/java/src/net/i2p/util/Clock.java           | 4 ++--
 router/java/src/net/i2p/router/Router.java      | 1 +
 router/java/src/net/i2p/router/RouterClock.java | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/core/java/src/net/i2p/util/Clock.java b/core/java/src/net/i2p/util/Clock.java
index afcf3afaa7..c8587f48eb 100644
--- a/core/java/src/net/i2p/util/Clock.java
+++ b/core/java/src/net/i2p/util/Clock.java
@@ -43,7 +43,7 @@ public class Clock implements Timestamper.UpdateListener {
     /** we fetch it on demand to avoid circular dependencies (logging uses the clock) */
     protected Log getLog() { return _context.logManager().getLog(Clock.class); }
 
-    /** if the clock is skewed by 3+ days, fuck 'em */
+    /** if the clock is skewed by 3+ days, forget it */
     public final static long MAX_OFFSET = 3 * 24 * 60 * 60 * 1000;
     /** after we've started up and shifted the clock, don't allow shifts of more than 10 minutes */
     public final static long MAX_LIVE_OFFSET = 10 * 60 * 1000;
@@ -67,7 +67,7 @@ public class Clock implements Timestamper.UpdateListener {
      *
      * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now())
      */
-    public void setOffset(long offsetMs, boolean force) {
+    public synchronized void setOffset(long offsetMs, boolean force) {
         if (false) return;
         long delta = offsetMs - _offset;
         if (!force) {
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 9e5e3380c6..11b0274c6e 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -1056,6 +1056,7 @@ public class Router implements RouterClock.ClockShiftListener {
             return;
         if (delta > -60*1000 && delta < 60*1000)
             return;
+        _eventLog.addEvent(EventLog.CLOCK_SHIFT, Long.toString(delta));
         // update the routing key modifier
         _context.routingKeyGenerator().generateDateBasedModData();
         if (_context.commSystem().countActivePeers() <= 0)
diff --git a/router/java/src/net/i2p/router/RouterClock.java b/router/java/src/net/i2p/router/RouterClock.java
index 0cb6961e49..12efbce48a 100644
--- a/router/java/src/net/i2p/router/RouterClock.java
+++ b/router/java/src/net/i2p/router/RouterClock.java
@@ -91,7 +91,7 @@ public class RouterClock extends Clock {
      * @since 0.7.12
      * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now())
      */
-    private void setOffset(long offsetMs, boolean force, int stratum) {
+    private synchronized void setOffset(long offsetMs, boolean force, int stratum) {
         long delta = offsetMs - _offset;
         if (!force) {
             if ((offsetMs > MAX_OFFSET) || (offsetMs < 0 - MAX_OFFSET)) {
@@ -236,7 +236,7 @@ public class RouterClock extends Clock {
      *
      *  @since 0.8.8
      */
-    private void notifyMassive(long shift) {
+    private synchronized void notifyMassive(long shift) {
         long nowNanos = System.nanoTime();
         // try to prevent dups, not guaranteed
         // nanoTime() isn't guaranteed to be monotonic either :(
-- 
GitLab