Author: toad
Date: 2006-09-28 17:44:00 +0000 (Thu, 28 Sep 2006)
New Revision: 10550

Modified:
   trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
Log:
More minor fixes to TDRA.

Modified: trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
===================================================================
--- trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java      
2006-09-28 17:34:18 UTC (rev 10549)
+++ trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java      
2006-09-28 17:44:00 UTC (rev 10550)
@@ -158,13 +158,20 @@
                        } else if(lastReportTime != -1) { // might be just 
serialized in
                                long thisInterval =
                                         now - lastReportTime;
+                               long uptime = now - createdTime;
                                if(thisInterval < 0) {
-                                       Logger.error(this, "Clock went back in 
time, ignoring report: "+now+" was "+lastReportTime+" (back 
"+(-thisInterval)+"ms");
+                                       Logger.error(this, "Clock (reporting) 
went back in time, ignoring report: "+now+" was "+lastReportTime+" (back 
"+(-thisInterval)+"ms");
+                                       lastReportTime = now;
                                        return;
                                }
                                double thisHalfLife = halfLife;
-                               long uptime = now - createdTime;
-                               if((uptime / 4) < thisHalfLife) thisHalfLife = 
(uptime / 4);
+                               if(uptime < 0) {
+                                       Logger.error(this, "Clock (uptime) went 
back in time, ignoring report: "+now+" was "+createdTime+" (back 
"+(-uptime)+"ms");
+                                       return;
+                               } else {
+                                       if((uptime / 4) < thisHalfLife) 
thisHalfLife = (uptime / 4);
+                               }
+                               
                                if(thisHalfLife == 0) thisHalfLife = 1;
                                double changeFactor =
                                        Math.pow(0.5, (thisInterval) / 
thisHalfLife);


Reply via email to