Author: toad
Date: 2008-09-19 17:53:44 +0000 (Fri, 19 Sep 2008)
New Revision: 22709

Modified:
   trunk/freenet/src/freenet/node/PacketSender.java
   trunk/freenet/src/freenet/support/TokenBucket.java
Log:
Add tokens before returning count. Otherwise we may go round and round forever.


Modified: trunk/freenet/src/freenet/node/PacketSender.java
===================================================================
--- trunk/freenet/src/freenet/node/PacketSender.java    2008-09-19 17:39:53 UTC 
(rev 22708)
+++ trunk/freenet/src/freenet/node/PacketSender.java    2008-09-19 17:53:44 UTC 
(rev 22709)
@@ -213,7 +213,7 @@
                boolean canSendThrottled = false;

                int MAX_PACKET_SIZE = 
node.darknetCrypto.socket.getMaxPacketSize();
-               long count = node.outputThrottle.count();
+               long count = node.outputThrottle.getCount();
                if(count > MAX_PACKET_SIZE)
                        canSendThrottled = true;
                else {
@@ -258,7 +258,7 @@

                                if(pn.maybeSendPacket(now, rpiTemp, rpiIntTemp) 
&& canSendThrottled) {
                                        canSendThrottled = false;
-                                       count = node.outputThrottle.count();
+                                       count = node.outputThrottle.getCount();
                                        if(count > MAX_PACKET_SIZE)
                                                canSendThrottled = true;
                                        else {

Modified: trunk/freenet/src/freenet/support/TokenBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/TokenBucket.java  2008-09-19 17:39:53 UTC 
(rev 22708)
+++ trunk/freenet/src/freenet/support/TokenBucket.java  2008-09-19 17:53:44 UTC 
(rev 22709)
@@ -89,10 +89,15 @@
                if(logMINOR) Logger.minor(this, "Removed tokens, balance now 
"+current);
        }

+       public synchronized long count() {
+               return current;
+       }
+       
        /**
         * Get the current number of available tokens.
         */
-       public synchronized long count() {
+       public synchronized long getCount() {
+               addTokens();
                return current;
        }



Reply via email to