Author: toad
Date: 2006-08-09 16:48:19 +0000 (Wed, 09 Aug 2006)
New Revision: 10002

Modified:
   trunk/freenet/src/freenet/node/Node.java
Log:
check bandwidth usage after checking bwlimitDelayTime/pingtime

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-08-09 16:46:42 UTC (rev 
10001)
+++ trunk/freenet/src/freenet/node/Node.java    2006-08-09 16:48:19 UTC (rev 
10002)
@@ -2396,21 +2396,6 @@

                double bwlimitDelayTime = 
throttledPacketSendAverage.currentValue();

-               // Do we have the bandwidth?
-               double expected = 
-                       (isInsert ? (isSSK ? 
this.remoteSskInsertBytesSentAverage : this.remoteChkInsertBytesSentAverage)
-                                       : (isSSK ? 
this.remoteSskFetchBytesSentAverage : 
this.remoteChkFetchBytesSentAverage)).currentValue();
-               int expectedSent = (int)Math.max(expected, 0);
-               if(!requestOutputThrottle.instantGrab(expectedSent)) return 
"Insufficient output bandwidth";
-               expected = 
-                       (isInsert ? (isSSK ? 
this.remoteSskInsertBytesReceivedAverage : 
this.remoteChkInsertBytesReceivedAverage)
-                                       : (isSSK ? 
this.remoteSskFetchBytesReceivedAverage : 
this.remoteChkFetchBytesReceivedAverage)).currentValue();
-               int expectedReceived = (int)Math.max(expected, 0);
-               if(!requestInputThrottle.instantGrab(expectedReceived)) {
-                       requestOutputThrottle.recycle(expectedSent);
-                       return "Insufficient input bandwidth";
-               }
-               
                // If no recent reports, no packets have been sent; correct the 
average downwards.
                long now = System.currentTimeMillis();
                boolean checkUncontended = false;
@@ -2443,29 +2428,28 @@
                                        lastAcceptedRequest = now;
                                        return null;
                                }
-                               return ">MAX_PING_TIME";
+                               return ">MAX_PING_TIME ("+pingTime+")";
                        }
                        if(pingTime > SUB_MAX_PING_TIME) {
                                double x = ((double)(pingTime - 
SUB_MAX_PING_TIME)) / (MAX_PING_TIME - SUB_MAX_PING_TIME);
                                if(random.nextDouble() < x) {
-                                       return ">SUB_MAX_PING_TIME";
+                                       return ">SUB_MAX_PING_TIME 
("+pingTime+")";
                                }
                        }

                        // Bandwidth limited packets
-                       Logger.minor(this, "bwlimitDelayTime = 
"+bwlimitDelayTime);
                        if(bwlimitDelayTime > MAX_THROTTLE_DELAY) {
                                if((now - lastAcceptedRequest > 
MAX_INTERREQUEST_TIME) && canAcceptAnyway) {
                                        Logger.minor(this, "Accepting request 
anyway (take one every 10 secs to keep bwlimitDelayTime updated)");
                                        lastAcceptedRequest = now;
                                        return null;
                                }
-                               return ">MAX_THROTTLE_DELAY";
+                               return ">MAX_THROTTLE_DELAY 
("+bwlimitDelayTime+")";
                        }
                        if(bwlimitDelayTime > SUB_MAX_THROTTLE_DELAY) {
                                double x = ((double)(bwlimitDelayTime - 
SUB_MAX_THROTTLE_DELAY)) / (MAX_THROTTLE_DELAY - SUB_MAX_THROTTLE_DELAY);
                                if(random.nextDouble() < x) {
-                                       return ">SUB_MAX_THROTTLE_DELAY";
+                                       return ">SUB_MAX_THROTTLE_DELAY 
("+bwlimitDelayTime+")";
                                }
                        }

@@ -2473,6 +2457,23 @@

                        lastAcceptedRequest = now;
                }
+               
+               // Do we have the bandwidth?
+               double expected = 
+                       (isInsert ? (isSSK ? 
this.remoteSskInsertBytesSentAverage : this.remoteChkInsertBytesSentAverage)
+                                       : (isSSK ? 
this.remoteSskFetchBytesSentAverage : 
this.remoteChkFetchBytesSentAverage)).currentValue();
+               int expectedSent = (int)Math.max(expected, 0);
+               if(!requestOutputThrottle.instantGrab(expectedSent)) return 
"Insufficient output bandwidth";
+               expected = 
+                       (isInsert ? (isSSK ? 
this.remoteSskInsertBytesReceivedAverage : 
this.remoteChkInsertBytesReceivedAverage)
+                                       : (isSSK ? 
this.remoteSskFetchBytesReceivedAverage : 
this.remoteChkFetchBytesReceivedAverage)).currentValue();
+               int expectedReceived = (int)Math.max(expected, 0);
+               if(!requestInputThrottle.instantGrab(expectedReceived)) {
+                       requestOutputThrottle.recycle(expectedSent);
+                       return "Insufficient input bandwidth";
+               }
+               
+               // Accept
                return null;
        }

@@ -2503,6 +2504,7 @@
        public SimpleFieldSet exportPublicFieldSet() {
                SimpleFieldSet fs = new SimpleFieldSet();
                Peer[] ips = getPrimaryIPAddress();
+               fs.put("base64", "true");
                if(ips != null) {
                        for(int i=0;i<ips.length;i++)
                                fs.put("physical.udp", ips[i].toString());


Reply via email to