Author: toad
Date: 2007-07-13 21:13:44 +0000 (Fri, 13 Jul 2007)
New Revision: 14095

Modified:
   trunk/freenet/src/freenet/io/comm/MessageCore.java
   trunk/freenet/src/freenet/node/OpennetManager.java
   trunk/freenet/src/freenet/node/OpennetPeerNode.java
Log:
More sophisticated isDroppable() - don't drop if less than a certain age, or if 
less than X time since started moving packets, or if less than Y since 
disconnected (but with a cooldown on the last one)

Modified: trunk/freenet/src/freenet/io/comm/MessageCore.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageCore.java  2007-07-13 20:46:44 UTC 
(rev 14094)
+++ trunk/freenet/src/freenet/io/comm/MessageCore.java  2007-07-13 21:13:44 UTC 
(rev 14095)
@@ -41,6 +41,11 @@
        private static final long MAX_UNCLAIMED_FIFO_ITEM_LIFETIME = 
60*60*1000;  // 1 hour
        // Every second, remove all timed out filters
        private static final int FILTER_REMOVE_TIME = 1000;
+       private long startedTime;
+       
+       public synchronized long getStartedTime() {
+               return startedTime;
+       }

        public MessageCore() {
                _timedOutFilters = new Vector(32);
@@ -69,6 +74,9 @@
     private final Vector _timedOutFilters;

     public void start(final Ticker ticker) {
+       synchronized(this) {
+               startedTime = System.currentTimeMillis();
+       }
        ticker.queueTimedJob(new Runnable() {

                        public void run() {

Modified: trunk/freenet/src/freenet/node/OpennetManager.java
===================================================================
--- trunk/freenet/src/freenet/node/OpennetManager.java  2007-07-13 20:46:44 UTC 
(rev 14094)
+++ trunk/freenet/src/freenet/node/OpennetManager.java  2007-07-13 21:13:44 UTC 
(rev 14095)
@@ -47,7 +47,13 @@
        /** Don't re-add a node until it's been up and disconnected for at 
least this long */
        static final int DONT_READD_TIME = 60*1000;
        /** Don't drop a node until it's at least this old */
-       static final int DROP_ELIGIBLE_TIME = 300*1000;
+       static final int DROP_MIN_AGE = 300*1000;
+       /** Don't drop a node until this long after startup */
+       static final int DROP_STARTUP_DELAY = 300*1000;
+       /** Don't drop a node until this long after losing connection to it */
+       static final int DROP_DISCONNECT_DELAY = 300*1000;
+       /** But if it has disconnected more than once in this period, allow it 
to be dropped anyway */
+       static final int DROP_DISCONNECT_DELAY_COOLDOWN = 60*60*1000;
        /** Every DROP_CONNECTED_TIME, we may drop a peer even though it is 
connected */
        static final int DROP_CONNECTED_TIME = 10*60*1000;


Modified: trunk/freenet/src/freenet/node/OpennetPeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/OpennetPeerNode.java 2007-07-13 20:46:44 UTC 
(rev 14094)
+++ trunk/freenet/src/freenet/node/OpennetPeerNode.java 2007-07-13 21:13:44 UTC 
(rev 14095)
@@ -9,6 +9,11 @@
        final OpennetManager opennet;
        private long timeLastSuccess;

+    /** When did we last disconnect? Not Disconnected because a discrete event 
*/
+    private long timeLastDisconnect;
+    /** Previous time of disconnection */
+    private long timePrevDisconnect;
+    
        public OpennetPeerNode(SimpleFieldSet fs, Node node2, NodeCrypto 
crypto, OpennetManager opennet, PeerManager peers, boolean fromLocal, 
OutgoingPacketMangler mangler) throws FSParseException, PeerParseException, 
ReferenceSignatureVerificationException {
                super(fs, node2, crypto, peers, fromLocal, mangler, true);
                this.opennet = opennet;
@@ -28,7 +33,20 @@
        }

        public boolean isDroppable() {
-               return System.currentTimeMillis() - getPeerAddedTime() > 
OpennetManager.DROP_ELIGIBLE_TIME;
+               long now = System.currentTimeMillis();
+               if(now - getPeerAddedTime() < OpennetManager.DROP_MIN_AGE)
+                       return false; // New node
+               if(now - node.usm.getStartedTime() < 
OpennetManager.DROP_STARTUP_DELAY)
+                       return false; // Give them time to connect after we 
startup
+               synchronized(this) {
+                       if((!isConnected()) && (!super.neverConnected()) && 
+                                       now - timeLastDisconnect < 
OpennetManager.DROP_DISCONNECT_DELAY &&
+                                       now - timePrevDisconnect > 
OpennetManager.DROP_DISCONNECT_DELAY_COOLDOWN) {
+                               // Grace period for node restarting
+                               return false;
+                       }
+               }
+               return true;
        }

        public void onSuccess(boolean insert, boolean ssk) {
@@ -50,4 +68,17 @@
     public final long timeLastSuccess() {
        return timeLastSuccess;
     }
+    
+    public void disconnected() {
+       synchronized(this) {
+               timePrevDisconnect = timeLastDisconnect;
+                       timeLastDisconnect = System.currentTimeMillis();
+       }
+       super.disconnected();
+    }
+    
+    public synchronized long timeLastDisconnect() {
+       return timeLastDisconnect;
+    }
+    
 }


Reply via email to