Author: toad
Date: 2008-02-07 16:42:21 +0000 (Thu, 07 Feb 2008)
New Revision: 17665

Modified:
   trunk/freenet/src/freenet/client/async/OfferedKeysList.java
   trunk/freenet/src/freenet/node/NodeClientCore.java
   trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
Log:
Unlock the key from asyncGet(), and implement a callback so OfferedKeysList can 
get notified if necessary.

Modified: trunk/freenet/src/freenet/client/async/OfferedKeysList.java
===================================================================
--- trunk/freenet/src/freenet/client/async/OfferedKeysList.java 2008-02-07 
16:24:47 UTC (rev 17664)
+++ trunk/freenet/src/freenet/client/async/OfferedKeysList.java 2008-02-07 
16:42:21 UTC (rev 17665)
@@ -11,6 +11,7 @@
 import freenet.node.NodeClientCore;
 import freenet.node.RequestScheduler;
 import freenet.node.SendableRequest;
+import freenet.node.NodeClientCore.SimpleRequestSenderCompletionListener;
 import freenet.support.Logger;

 /**
@@ -99,7 +100,13 @@
                // Don't let a node force us to start a real request for a 
specific key.
                // We check the datastore, take up offers if any (on a short 
timeout), and then quit if we still haven't fetched the data.
                // Obviously this may have a marginal impact on load but it 
should only be marginal.
-               core.asyncGet(key, true, true);
+               core.asyncGet(key, true, true, new 
SimpleRequestSenderCompletionListener() {
+
+                       public void completed(boolean success) {
+                               // Ignore
+                       }
+                       
+               });
                return true;
        }


Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2008-02-07 16:24:47 UTC 
(rev 17664)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2008-02-07 16:42:21 UTC 
(rev 17665)
@@ -438,24 +438,54 @@
                }, "Startup completion thread");
        }

+       public interface SimpleRequestSenderCompletionListener {
+
+               public void completed(boolean success);
+               
+       }
+       
+       public void asyncGet(Key key, boolean cache, boolean offersOnly, final 
SimpleRequestSenderCompletionListener listener) {
+               final long uid = random.nextLong();
+               if(!node.lockUID(uid, false, false, false)) {
+                       Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
+                       return;
+               }
+               asyncGet(key, cache, offersOnly, uid, new 
RequestSender.Listener() {
+
+                       public void onCHKTransferBegins() {
+                               // Ignore
+                       }
+
+                       public void onReceivedRejectOverload() {
+                               // Ignore
+                       }
+
+                       public void onRequestSenderFinished(int status) {
+                               node.unlockUID(uid, false, false, false, false);
+                               if(listener != null)
+                                       listener.completed(status == 
RequestSender.SUCCESS);
+                       }
+                       
+               });
+       }
+       
        /**
         * Start an asynchronous fetch of the key in question, which will 
complete to the datastore.
         * It will not decode the data because we don't provide a ClientKey. It 
will not return 
         * anything and will run asynchronously.
         * @param key
         */
-       public void asyncGet(Key key, boolean cache, boolean offersOnly) {
-               long uid = random.nextLong();
-               if(!node.lockUID(uid, false, false, false)) {
-                       Logger.error(this, "Could not lock UID just randomly 
generated: "+uid+" - probably indicates broken PRNG");
-                       return;
-               }
+       void asyncGet(Key key, boolean cache, boolean offersOnly, long uid, 
RequestSender.Listener listener) {
                try {
                        Object o = node.makeRequestSender(key, node.maxHTL(), 
uid, null, node.getLocation(), false, false, cache, false, offersOnly);
                        if(o instanceof CHKBlock) {
                                node.unlockUID(uid, false, false, true, false);
                                return; // Already have it.
                        }
+                       RequestSender rs = (RequestSender) o;
+                       rs.addListener(listener);
+                       if(rs.uid != uid)
+                               node.unlockUID(uid, false, false, false, false);
                        // Else it has started a request.
                        if(logMINOR)
                                Logger.minor(this, "Started "+o+" for "+uid+" 
for "+key);

Modified: trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java   
2008-02-07 16:24:47 UTC (rev 17664)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java   
2008-02-07 16:42:21 UTC (rev 17665)
@@ -35,6 +35,7 @@

     public static void main(String[] args) throws FSParseException, 
PeerParseException, InvalidThresholdException, NodeInitException, 
ReferenceSignatureVerificationException {
         Logger.setupStdoutLogging(Logger.NORMAL, 
"freenet.node.CPUAdjustingSwapRequestInterval:minor" 
/*"freenet.node.LocationManager:debug,freenet.node.FNPPacketManager:normal,freenet.io.comm.MessageCore:debug"*/);
+        Logger.globalSetThreshold(Logger.ERROR);
         System.out.println("Routing test using real nodes:");
         System.out.println();
         String wd = "realNodeRequestInsertTest";


Reply via email to