Author: zothar
Date: 2006-07-10 00:57:45 +0000 (Mon, 10 Jul 2006)
New Revision: 9537

Modified:
   trunk/freenet/src/freenet/node/ARKFetcher.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/NodeDispatcher.java
Log:
Locking consistency changes and a not-while-locked native method call change.  
toad_, please check the FIXME comment I added to shouldRejectRequest()

Modified: trunk/freenet/src/freenet/node/ARKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/node/ARKFetcher.java      2006-07-10 00:10:10 UTC 
(rev 9536)
+++ trunk/freenet/src/freenet/node/ARKFetcher.java      2006-07-10 00:57:45 UTC 
(rev 9537)
@@ -161,10 +161,10 @@
                try {
                        fs = new SimpleFieldSet(ref, true);
                        Logger.minor(this, "Got ARK for "+peer.getPeer());
-                       peer.gotARK(fs, startedEdition);
+                       peer.gotARK(fs, getStartedEdition());
                } catch (IOException e) {
                        // Corrupt ref.
-                       Logger.error(this, "Corrupt ARK reference? Fetched 
"+fetchingURI+" got while parsing: "+e+" from:\n"+ref, e);
+                       Logger.error(this, "Corrupt ARK reference? Fetched 
"+getFetchingURI()+" got while parsing: "+e+" from:\n"+ref, e);
                }
        }

@@ -191,12 +191,12 @@
                        }
                }
                if(e.newURI != null) {
-                       Logger.minor(this, "Failed to fetch ARK for 
"+peer.getPeer()+", "+fetchingURI+" gave redirect to "+e.newURI);
+                       Logger.minor(this, "Failed to fetch ARK for 
"+peer.getPeer()+", "+getFetchingURI()+" gave redirect to "+e.newURI);
                        peer.updateARK(e.newURI);
                        queueWithBackoff();
                        return;
                }
-               Logger.minor(this, "Failed to fetch ARK for "+peer.getPeer()+", 
now backing off ARK fetches for "+(backoff / 1000)+" seconds");
+               Logger.minor(this, "Failed to fetch ARK for "+peer.getPeer()+", 
now backing off ARK fetches for "+(getBackoff() / 1000)+" seconds");
                // We may be on the PacketSender thread.
                // FIXME should this be exponential backoff?
                queueWithBackoff();
@@ -217,7 +217,7 @@
                Logger.error(this, "Impossible reached in 
ARKFetcher.onGeneratredURI(FreenetURI,BaseClientPutter) for peer 
"+peer.getPeer(), new Exception("error"));
        }

-       public boolean isFetching() {
+       public synchronized boolean isFetching() {
                return isFetching;
        }

@@ -233,6 +233,18 @@
         * Queue a call to our queue method on the PacketSender timed job queue 
to be run after our ARK fetch backoff expires
         */
        private void queueWithBackoff() {
-               node.ps.queueTimedJob(new Runnable() { public void run() { 
queue(); }}, backoff);  // Runnable rather than FastRunnable so we don't put it 
on the PacketSender thread
+               node.ps.queueTimedJob(new Runnable() { public void run() { 
queue(); }}, getBackoff());  // Runnable rather than FastRunnable so we don't 
put it on the PacketSender thread
        }
+
+       private synchronized int getBackoff() {
+               return backoff;
+       }
+
+       private synchronized FreenetURI getFetchingURI() {
+               return fetchingURI;
+       }
+
+       private synchronized long getStartedEdition() {
+               return startedEdition;
+       }
 }

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-07-10 00:10:10 UTC (rev 
9536)
+++ trunk/freenet/src/freenet/node/Node.java    2006-07-10 00:57:45 UTC (rev 
9537)
@@ -278,7 +278,9 @@

                public void onFailure(InserterException e, BaseClientPutter 
state) {
                        Logger.minor(this, "ARK insert failed: "+e);
-                       lastInsertedPeers = null;
+                       synchronized(this) {
+                               lastInsertedPeers = null;
+                       }
                        // :(
                        // Better try again
                        try {
@@ -2254,9 +2256,7 @@
                + FNPPacketMangler.HEADERS_LENGTH_ONE_MESSAGE;

     /* return reject reason as string if should reject, otherwise return null 
*/
-       public synchronized String shouldRejectRequest(boolean canAcceptAnyway, 
boolean isInsert, boolean isSSK) {
-               long now = System.currentTimeMillis();
-
+       public synchronized String shouldRejectRequest(boolean canAcceptAnyway, 
boolean isInsert, boolean isSSK, long now) {
                dumpByteCostAverages();

                double bwlimitDelayTime = 
throttledPacketSendAverage.currentValue();
@@ -2277,11 +2277,11 @@

                // If no recent reports, no packets have been sent; correct the 
average downwards.

-               if(throttledPacketSendAverage.lastReportTime() < 
System.currentTimeMillis() - 5000) {
+               if(throttledPacketSendAverage.lastReportTime() < 
System.currentTimeMillis() - 5000) {  // if last report more than 5 seconds ago
                        
outputThrottle.blockingGrab(ESTIMATED_SIZE_OF_ONE_THROTTLED_PACKET);
                        
outputThrottle.recycle(ESTIMATED_SIZE_OF_ONE_THROTTLED_PACKET);
                        long after = System.currentTimeMillis();
-                       throttledPacketSendAverage.report(after - now);
+                       throttledPacketSendAverage.report(after - now);  // 
**FIXME** shouldn't this be (after - lastReportTime())?  Otherwise, we measure 
how long it's been since we started executing this shouldRejectRequest method
                        now = after;
                        bwlimitDelayTime = 
throttledPacketSendAverage.currentValue();
                }

Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2006-07-10 00:10:10 UTC 
(rev 9536)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2006-07-10 00:57:45 UTC 
(rev 9537)
@@ -119,7 +119,8 @@
             }
             return true;
         }
-        String rejectReason = node.shouldRejectRequest(!isSSK, false, isSSK);
+               long now = System.currentTimeMillis();
+        String rejectReason = node.shouldRejectRequest(!isSSK, false, isSSK, 
now);
         if(rejectReason != null) {
                // can accept 1 CHK request every so often, but not with SSKs 
because they aren't throttled so won't sort out bwlimitDelayTime, which was the 
whole reason for accepting them when overloaded...
                Logger.normal(this, "Rejecting request from 
"+m.getSource().getPeer()+" preemptively because "+rejectReason);
@@ -153,7 +154,6 @@
     }

     private boolean handleInsertRequest(Message m, boolean isSSK) {
-        long now = System.currentTimeMillis();
         long id = m.getLong(DMT.UID);
         if(node.recentlyCompleted(id)) {
             Message rejected = DMT.createFNPRejectedLoop(id);
@@ -164,8 +164,9 @@
             }
             return true;
         }
+        long now = System.currentTimeMillis();
         // SSKs don't fix bwlimitDelayTime so shouldn't be accepted when 
overloaded.
-        String rejectReason = node.shouldRejectRequest(!isSSK, true, isSSK);
+        String rejectReason = node.shouldRejectRequest(!isSSK, true, isSSK, 
now);
         if(rejectReason != null) {
                Logger.normal(this, "Rejecting insert from 
"+m.getSource().getPeer()+" preemptively because "+rejectReason);
                Message rejected = DMT.createFNPRejectedOverload(id, true);


Reply via email to