Author: robert
Date: 2008-01-08 00:46:35 +0000 (Tue, 08 Jan 2008)
New Revision: 16962

Modified:
   trunk/freenet/src/freenet/io/xfer/BlockReceiver.java
   trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
Log:
trivial: comments, logging, readability


Modified: trunk/freenet/src/freenet/io/xfer/BlockReceiver.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BlockReceiver.java        2008-01-07 
20:56:43 UTC (rev 16961)
+++ trunk/freenet/src/freenet/io/xfer/BlockReceiver.java        2008-01-08 
00:46:35 UTC (rev 16962)
@@ -66,6 +66,7 @@

        public byte[] receive() throws RetrievalException {
                int consecutiveMissingPacketReports = 0;
+               boolean logMINOR=Logger.shouldLog(Logger.MINOR, this);
                try {
                while (!_prb.allReceived()) {
                        Message m1;
@@ -80,7 +81,7 @@
                 _prb.abort(RetrievalException.SENDER_DIED, "Disconnected 
during receive");
                 throw new 
RetrievalException(RetrievalException.SENDER_DISCONNECTED);
             }
-            if(Logger.shouldLog(Logger.MINOR, this))
+            if(logMINOR)
                Logger.minor(this, "Received "+m1);
             if ((m1 != null) && m1.getSpec().equals(DMT.sendAborted)) {
                                _prb.abort(m1.getInt(DMT.REASON), 
m1.getString(DMT.DESCRIPTION));
@@ -112,7 +113,7 @@
                                                }
                                        }
                                }
-                               if(Logger.shouldLog(Logger.MINOR, this))
+                               if(logMINOR)
                                        Logger.minor(this, "Missing: 
"+missing.size());
                                if (missing.size() > 0) {
                                        Message mn = 
DMT.createMissingPacketNotification(_uid, missing);

Modified: trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java     2008-01-07 
20:56:43 UTC (rev 16961)
+++ trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java     2008-01-08 
00:46:35 UTC (rev 16962)
@@ -84,9 +84,13 @@
                                        try {
                                                while (true) {
                                                        
synchronized(_senderThread) {
-                                                               
if(_unsent.size() != 0) break;
+                                                               
if(_unsent.size() != 0) {
+                                                                       
timeAllSent = -1;
+                                                                       break;
+                                                               }
                                                                // No unsent 
packets
                                                                if(getNumSent() 
== _prb.getNumPackets()) {
+                                                                       //No 
unreceived packets
                                                                        
if(Logger.shouldLog(Logger.MINOR, this))
                                                                                
Logger.minor(this, "Sent all blocks, none unsent");
                                                                        
if(timeAllSent <= 0)
@@ -96,7 +100,6 @@
                                                                
_senderThread.wait(10*1000);
                                                        }
                                                }
-                                               timeAllSent = -1;
                                        } catch (InterruptedException e) {
                                        } catch (AbortedException e) {
                                                synchronized(_senderThread) {
@@ -136,9 +139,8 @@
                                }
                        }

-                       /** @return True if _sendComplete */
                        private void delay(long startCycleTime) {
-                               
+                               //FIXME: startCycleTime is not used in this 
function, why is it passed in?
                                long startThrottle = System.currentTimeMillis();

                                // Get the current inter-packet delay
@@ -164,6 +166,7 @@
                                        int x = (int) (Math.min(l, 120*1000));
                                        if(x > 0) {
                                                try {
+                                                       //FIXME: if the 
senderThread sleeps here for two minutes, that will timeout the receiver, no? 
Should this be a wait()?
                                                        Thread.sleep(x);
                                                } catch (InterruptedException 
e) {
                                                        // Ignore
@@ -239,6 +242,7 @@
                                        return false;
                                if (msg == null) {
                                        long now = System.currentTimeMillis();
+                                       //SEND_TIMEOUT (one minute) after all 
packets have been transmitted, terminate the send.
                                        if((timeAllSent > 0) && ((now - 
timeAllSent) > SEND_TIMEOUT) &&
                                                        (getNumSent() == 
_prb.getNumPackets())) {
                                                synchronized(_senderThread) {
@@ -280,9 +284,8 @@
                                                _senderThread.notifyAll();
                                        }
                                        return false;
-                               } else if(_sendComplete) {
-                                       // Terminated abnormally
-                                       return false;
+                               } else {
+                                       Logger.error(this, "Transmitter 
received unknown message type: "+msg.getSpec().getName());
                                }
                        }
                } catch (AbortedException e) {


Reply via email to