Author: nextgens
Date: 2007-06-05 16:43:30 +0000 (Tue, 05 Jun 2007)
New Revision: 13472

Added:
   trunk/freenet/src/freenet/node/TimeSkewDetectorCallback.java
Modified:
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
Log:
Create a new interface : TimeSkewDetectorCallback and pass that to 
TimeDecayingRunningAverage insteed of a Node object

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2007-06-05 11:43:14 UTC (rev 
13471)
+++ trunk/freenet/src/freenet/node/Node.java    2007-06-05 16:43:30 UTC (rev 
13472)
@@ -117,7 +117,7 @@
 /**
  * @author amphibian
  */
-public class Node {
+public class Node implements TimeSkewDetectorCallback {

        private static boolean logMINOR;


Added: trunk/freenet/src/freenet/node/TimeSkewDetectorCallback.java
===================================================================
--- trunk/freenet/src/freenet/node/TimeSkewDetectorCallback.java                
                (rev 0)
+++ trunk/freenet/src/freenet/node/TimeSkewDetectorCallback.java        
2007-06-05 16:43:30 UTC (rev 13472)
@@ -0,0 +1,14 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.node;
+
+/*
+ * A simple interface used to tell the node that a time skew has been detected
+ * and that it should complain loudly to the user about it.
+ * 
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ */
+public interface TimeSkewDetectorCallback {
+       public void setTimeSkewDetectedUserAlert();
+}

Modified: trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
===================================================================
--- trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java      
2007-06-05 11:43:14 UTC (rev 13471)
+++ trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java      
2007-06-05 16:43:30 UTC (rev 13472)
@@ -7,7 +7,7 @@
 import java.io.DataOutputStream;
 import java.io.IOException;

-import freenet.node.Node;
+import freenet.node.TimeSkewDetectorCallback;
 import freenet.support.Logger;
 import freenet.support.SimpleFieldSet;

@@ -41,7 +41,7 @@
     double minReport;
     double maxReport;
     boolean logDEBUG;
-    private final Node node;
+    private final TimeSkewDetectorCallback timeSkewCallback;

     public String toString() {
                long now = System.currentTimeMillis();
@@ -55,7 +55,7 @@
     }

     public TimeDecayingRunningAverage(double defaultValue, long halfLife,
-            double min, double max, final Node node) {
+            double min, double max, TimeSkewDetectorCallback callback) {
        curValue = defaultValue;
         this.defaultValue = defaultValue;
         started = false;
@@ -68,11 +68,11 @@
         if(logDEBUG)
                Logger.debug(this, "Created "+this,
                                new Exception("debug"));
-        this.node = node;
+        this.timeSkewCallback = callback;
     }

     public TimeDecayingRunningAverage(double defaultValue, long halfLife,
-            double min, double max, SimpleFieldSet fs, final Node node) {
+            double min, double max, SimpleFieldSet fs, 
TimeSkewDetectorCallback callback) {
        curValue = defaultValue;
         this.defaultValue = defaultValue;
         started = false;
@@ -101,10 +101,10 @@
                        }
                }
         }
-        this.node = node;
+        this.timeSkewCallback = callback;
     }

-    public TimeDecayingRunningAverage(double defaultValue, double halfLife, 
double min, double max, DataInputStream dis, final Node node) throws 
IOException {
+    public TimeDecayingRunningAverage(double defaultValue, double halfLife, 
double min, double max, DataInputStream dis, TimeSkewDetectorCallback callback) 
throws IOException {
         int m = dis.readInt();
         if(m != MAGIC) throw new IOException("Invalid magic "+m);
         int v = dis.readInt();
@@ -124,7 +124,7 @@
         lastReportTime = -1;
         createdTime = System.currentTimeMillis() - priorExperienceTime;
         totalReports = dis.readLong();
-        this.node = node;
+        this.timeSkewCallback = callback;
     }

     public TimeDecayingRunningAverage(TimeDecayingRunningAverage a) {
@@ -137,7 +137,7 @@
         this.started = a.started;
         this.totalReports = a.totalReports;
         this.curValue = a.curValue;
-        this.node = a.node;
+        this.timeSkewCallback = a.timeSkewCallback;
     }

     public synchronized double currentValue() {
@@ -173,15 +173,15 @@
                                if(thisInterval < 0) {
                                        Logger.error(this, "Clock (reporting) 
went back in time, ignoring report: "+now+" was "+lastReportTime+" (back 
"+(-thisInterval)+"ms)");
                                        lastReportTime = now;
-                                       if(node != null)
-                                               
node.setTimeSkewDetectedUserAlert();
+                                       if(timeSkewCallback != null)
+                                               
timeSkewCallback.setTimeSkewDetectedUserAlert();
                                        return;
                                }
                                double thisHalfLife = halfLife;
                                if(uptime < 0) {
                                        Logger.error(this, "Clock (uptime) went 
back in time, ignoring report: "+now+" was "+createdTime+" (back 
"+(-uptime)+"ms)");
-                                       if(node != null)
-                                               
node.setTimeSkewDetectedUserAlert();
+                                       if(timeSkewCallback != null)
+                                               
timeSkewCallback.setTimeSkewDetectedUserAlert();
                                        return;
                                } else {
                                        if((uptime / 4) < thisHalfLife) 
thisHalfLife = (uptime / 4);


Reply via email to