Author: toad
Date: 2008-02-02 23:20:27 +0000 (Sat, 02 Feb 2008)
New Revision: 17486

Modified:
   trunk/freenet/src/freenet/client/async/OfferedKeysList.java
   trunk/freenet/src/freenet/node/NodeClientCore.java
Log:
ClientKey's are optional. Start the request asynchronously without using one.

Modified: trunk/freenet/src/freenet/client/async/OfferedKeysList.java
===================================================================
--- trunk/freenet/src/freenet/client/async/OfferedKeysList.java 2008-02-02 
23:08:40 UTC (rev 17485)
+++ trunk/freenet/src/freenet/client/async/OfferedKeysList.java 2008-02-02 
23:20:27 UTC (rev 17486)
@@ -10,7 +10,6 @@
 import freenet.crypt.RandomSource;
 import freenet.keys.ClientKey;
 import freenet.keys.Key;
-import freenet.node.LowLevelGetException;
 import freenet.node.NodeClientCore;
 import freenet.node.RequestScheduler;
 import freenet.node.SendableRequest;
@@ -65,9 +64,10 @@
        public synchronized void onNoOffers(ClientKey key) {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                if(logMINOR) Logger.minor(this, "No offers for "+key+" , 
removing it");
-               keys.remove(key);
-               keysList.remove(key);
-               clientKeysByKey.remove(key.getNodeKey());
+               Key k = key.getNodeKey();
+               keys.remove(k);
+               keysList.remove(k);
+               clientKeysByKey.remove(k);
        }

        public synchronized boolean isEmpty() {
@@ -82,10 +82,10 @@
        public Object chooseKey() {
                // Pick a random key
                if(keysList.isEmpty()) return null;
-               ClientKey ck = (ClientKey) 
keysList.remove(random.nextInt(keysList.size()));
-               keys.remove(ck);
-               clientKeysByKey.remove(ck.getNodeKey());
-               return ck;
+               Key k = (Key) keysList.remove(random.nextInt(keysList.size()));
+               keys.remove(k);
+               clientKeysByKey.remove(k);
+               return k;
        }

        public Object getClient() {
@@ -110,13 +110,8 @@
        }

        public boolean send(NodeClientCore node, RequestScheduler sched, Object 
keyNum) {
-               ClientKey key = (ClientKey) keyNum;
-               try {
-                       core.realGetKey(key, false, true, // if it's not cached 
it won't propagate FIXME support =false??
-                                       false);
-               } catch (LowLevelGetException e) {
-                       Logger.minor(this, "Caught low level get exception "+e, 
e);
-               }
+               Key key = (Key) keyNum;
+               core.asyncGet(key, true);// Have to cache it in order to 
propagate it; FIXME
                return true;
        }


Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2008-02-02 23:08:40 UTC 
(rev 17485)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2008-02-02 23:20:27 UTC 
(rev 17486)
@@ -436,6 +436,31 @@
                        }
                }, "Startup completion thread");
        }
+
+       /**
+        * 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) {
+               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;
+               }
+               try {
+                       Object o = node.makeRequestSender(key, node.maxHTL(), 
uid, null, node.getLocation(), false, false, cache, false);
+                       if(o instanceof CHKBlock) {
+                               return; // Already have it.
+                       }
+                       // Else it has started a request.
+                       if(logMINOR)
+                               Logger.minor(this, "Started "+o+" for "+uid+" 
for "+key);
+               } finally {
+                       node.unlockUID(uid, false, false, true, false);
+               }
+       }

        public ClientKeyBlock realGetKey(ClientKey key, boolean localOnly, 
boolean cache, boolean ignoreStore) throws LowLevelGetException {
                if(key instanceof ClientCHK)


Reply via email to