Author: robert
Date: 2008-01-09 16:15:47 +0000 (Wed, 09 Jan 2008)
New Revision: 16981

Modified:
   trunk/freenet/src/freenet/node/NodeStats.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
factor out getProbableSendQueueTime


Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java       2008-01-09 16:08:19 UTC 
(rev 16980)
+++ trunk/freenet/src/freenet/node/NodeStats.java       2008-01-09 16:15:47 UTC 
(rev 16981)
@@ -538,12 +538,11 @@
                }

                if(source != null) {
-                       long queuedBytes = source.getMessageQueueLengthBytes();
-                       if(queuedBytes > MAX_PEER_QUEUE_BYTES) {
+                       if(source.getMessageQueueLengthBytes() > 
MAX_PEER_QUEUE_BYTES) {
                                rejected(">MAX_PEER_QUEUE_BYTES", isLocal);
                                return "Too many message bytes queued for peer";
                        }
-                       if(queuedBytes / 
(source.getThrottle().getBandwidth()+1.0) > MAX_PEER_QUEUE_TIME) {
+                       if(source.getProbableSendQueueTime() > 
MAX_PEER_QUEUE_TIME) {
                                rejected(">MAX_PEER_QUEUE_TIME", isLocal);
                                return "Peer's queue will take too long to 
transfer";
                        }

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2008-01-09 16:08:19 UTC 
(rev 16980)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2008-01-09 16:15:47 UTC 
(rev 16981)
@@ -998,6 +998,13 @@
        }

        /**
+        * Returns the number of milliseconds that it is estimated to take to 
transmit the currently queued packets.
+        */
+       public long getProbableSendQueueTime() {
+               return 
(long)(getMessageQueueLengthBytes()/(getThrottle().getBandwidth()+1.0));
+       }
+       
+       /**
        * @return The last time we received a packet.
        */
        public synchronized long lastReceivedPacketTime() {
@@ -1421,7 +1428,7 @@
        public boolean conditionalSend(Message req, ByteCounter ctr, long 
timeout) throws NotConnectedException {
                if (timeout<=0)
                        return false;
-               if 
(getMessageQueueLengthBytes()/(getThrottle().getBandwidth()+1.0) > timeout) {
+               if (getProbableSendQueueTime() > timeout) {
                        Logger.normal(this, "conditionalSend; pre-emptively not 
sending message ("+timeout+"ms): "+req);
                        return false;
                }


Reply via email to