Author: toad
Date: 2008-03-04 13:53:37 +0000 (Tue, 04 Mar 2008)
New Revision: 18331

Modified:
   trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
   trunk/freenet/src/freenet/node/KeyTracker.java
Log:
Support deprecating one PacketThrottle for another.

Modified: trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PacketThrottle.java       2008-03-04 
13:49:33 UTC (rev 18330)
+++ trunk/freenet/src/freenet/io/xfer/PacketThrottle.java       2008-03-04 
13:53:37 UTC (rev 18331)
@@ -55,6 +55,7 @@
        /** Last time (seqno) we checked whether the window was full, or 
dropped a packet. */
        private long _packetSeqWindowFullChecked;
        private static boolean logMINOR;
+       private PacketThrottle _deprecatedFor;

        /**
         * Create a PacketThrottle for a given peer.
@@ -161,6 +162,7 @@
        public void sendThrottledMessage(Message msg, PeerContext peer, 
DoubleTokenBucket overallThrottle, int packetSize, ByteCounter ctr) throws 
NotConnectedException {
                long start = System.currentTimeMillis();
                long bootID = peer.getBootID();
+               PacketThrottle deprecatedFor = null;
                synchronized(this) {
                        while(true) {
                                int windowSize = (int) getWindowSize();
@@ -182,8 +184,17 @@
                                }
                                if(!peer.isConnected()) throw new 
NotConnectedException();
                                if(bootID != peer.getBootID()) throw new 
NotConnectedException();
+                               if(_deprecatedFor != null) {
+                                       deprecatedFor = _deprecatedFor;
+                                       break;
+                               }
                        }
                }
+               if(deprecatedFor != null) {
+                       // FIXME infinite recursion may be possible here??
+                       deprecatedFor.sendThrottledMessage(msg, peer, 
overallThrottle, packetSize, ctr);
+                       return;
+               }
                long waitTime = System.currentTimeMillis() - start;
                if(waitTime > 60*1000)
                        Logger.error(this, "Congestion control wait time: 
"+waitTime+" for "+this);
@@ -258,4 +269,9 @@
        public synchronized void maybeDisconnected() {
                notifyAll();
        }
+
+       public synchronized void changedAddress(PacketThrottle newThrottle) {
+               _deprecatedFor = newThrottle;
+               notifyAll();
+       }
 }

Modified: trunk/freenet/src/freenet/node/KeyTracker.java
===================================================================
--- trunk/freenet/src/freenet/node/KeyTracker.java      2008-03-04 13:49:33 UTC 
(rev 18330)
+++ trunk/freenet/src/freenet/node/KeyTracker.java      2008-03-04 13:53:37 UTC 
(rev 18331)
@@ -612,7 +612,7 @@
                        _lastThrottle = newThrottle;
                } else return newThrottle;
        }
-       prevThrottle.maybeDisconnected();
+       prevThrottle.changedAddress(newThrottle);
        return newThrottle;
        }



Reply via email to