Author: zothar
Date: 2006-12-10 02:20:01 +0000 (Sun, 10 Dec 2006)
New Revision: 11331

Modified:
   trunk/freenet/src/freenet/node/LocationManager.java
Log:
Should fix bug 956: loc change stats not using circular distance

Modified: trunk/freenet/src/freenet/node/LocationManager.java
===================================================================
--- trunk/freenet/src/freenet/node/LocationManager.java 2006-12-10 00:44:10 UTC 
(rev 11330)
+++ trunk/freenet/src/freenet/node/LocationManager.java 2006-12-10 02:20:01 UTC 
(rev 11331)
@@ -86,10 +86,27 @@

     public void updateLocationChangeSession(double newLoc) {
        double oldLoc = this.loc.getValue();
-               if (newLoc < oldLoc) {
-                       this.locChangeSession -= (oldLoc - newLoc);
+       // Patterned after PeerManager.distance( double, double ), but also 
need to know the direction of the change
+               if (newLoc > oldLoc) {
+                       double directDifference = newLoc - oldLoc;
+                       double oppositeDifference = 1.0 - newLoc + oldLoc;
+                       if (directDifference < oppositeDifference) {
+                               if(logMINOR) Logger.minor(this, 
"updateLocationChangeSession: oldLoc: "+oldLoc+" -> newLoc: "+newLoc+" moved: 
+"+directDifference);
+                               this.locChangeSession += directDifference;
+                       } else {
+                               if(logMINOR) Logger.minor(this, 
"updateLocationChangeSession: oldLoc: "+oldLoc+" -> newLoc: "+newLoc+" moved: 
-"+oppositeDifference);
+                               this.locChangeSession -= oppositeDifference;
+                       }
                } else {
-                       this.locChangeSession += (newLoc - oldLoc);
+                       double directDifference = oldLoc - newLoc;
+                       double oppositeDifference = 1.0 - oldLoc + newLoc;
+                       if (directDifference < oppositeDifference) {
+                               if(logMINOR) Logger.minor(this, 
"updateLocationChangeSession: oldLoc: "+oldLoc+" -> newLoc: "+newLoc+" moved: 
-"+directDifference);
+                               this.locChangeSession -= directDifference;
+                       } else {
+                               if(logMINOR) Logger.minor(this, 
"updateLocationChangeSession: oldLoc: "+oldLoc+" -> newLoc: "+newLoc+" moved: 
+"+oppositeDifference);
+                               this.locChangeSession += oppositeDifference;
+                       }
                }
     }



Reply via email to