Author: nextgens
Date: 2008-07-17 17:04:05 +0000 (Thu, 17 Jul 2008)
New Revision: 21173

Modified:
   trunk/freenet/src/freenet/node/PeerManager.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
more on FOAF routing changes: exclude peers from the list we send if 
        - they have been backed off for more than 5mins
OR      - they have a 90+% backoff percentage

shall we consider using the uptime too?

Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java     2008-07-17 15:50:11 UTC 
(rev 21172)
+++ trunk/freenet/src/freenet/node/PeerManager.java     2008-07-17 17:04:05 UTC 
(rev 21173)
@@ -558,7 +558,7 @@
         * @return An array of the current locations (as doubles) of all
         * our connected peers.
         */
-       public double[] getPeerLocationDoubles() {
+       public double[] getPeerLocationDoubles(boolean pruneBackedOffedPeers) {
                double[] locs;
                PeerNode[] conns;
                synchronized(this) {
@@ -567,8 +567,11 @@
                locs = new double[conns.length];
                int x = 0;
                for(int i = 0; i < conns.length; i++) {
-                       if(conns[i].isRoutable())
-                               locs[x++] = conns[i].getLocation();
+                       if(conns[i].isRoutable()) {
+                               if(!conns[i].shouldBeExcludedFromPeerList()) {
+                                       locs[x++] = conns[i].getLocation();
+                               }
+                       }
                }
                // Wipe out any information contained in the order
                java.util.Arrays.sort(locs, 0, x);

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2008-07-17 15:50:11 UTC 
(rev 21172)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2008-07-17 17:04:05 UTC 
(rev 21173)
@@ -74,9 +74,7 @@
 import freenet.support.math.TimeDecayingRunningAverage;
 import freenet.support.transport.ip.HostnameSyntaxException;
 import freenet.support.transport.ip.IPUtil;
-import java.util.ArrayList;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.Collection;

 /**
  * @author amphibian
@@ -328,6 +326,12 @@
        protected NodeCrypto crypto;

        /**
+        * Some alchemy we use in PeerNode.shouldBeExcludedFromPeerList()
+        */
+       public static final int BLACK_MAGIC_BACKOFF_PRUNING_TIME = 5 * 60 * 
1000;
+       public static final double BLACK_MAGIC_BACKOFF_PRUNING_PERCENTAGE = 0.9;
+       
+       /**
         * For FNP link setup:
         *  The initiator has to ensure that nonces send back by the
         *  responder in message2 match what was chosen in message 1
@@ -914,6 +918,18 @@
                return currentLocation;
        }

+       public boolean shouldBeExcludedFromPeerList() {
+               long now = System.currentTimeMillis();
+               synchronized(this) {
+                       if(BLACK_MAGIC_BACKOFF_PRUNING_PERCENTAGE < 
backedOffPercent.currentValue())
+                               return false;
+                       else if(BLACK_MAGIC_BACKOFF_PRUNING_TIME + now < 
getRoutingBackedOffUntil())
+                               return false;
+                       else
+                               return true;
+               }
+       }
+       
        public synchronized  double[] getPeersLocation() {
                return currentPeersLocation;
        }
@@ -2082,7 +2098,7 @@
        */
        protected void sendInitialMessages() {
                Message locMsg = ((getVersionNumber() > 1153) ?
-                       
DMT.createFNPLocChangeNotificationNew(node.lm.getLocation(), 
node.peers.getPeerLocationDoubles()) :
+                       
DMT.createFNPLocChangeNotificationNew(node.lm.getLocation(), 
node.peers.getPeerLocationDoubles(true)) :
                        
DMT.createFNPLocChangeNotification(node.lm.getLocation()));
                Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer);
                Message timeMsg = DMT.createFNPTime(System.currentTimeMillis());


Reply via email to