Author: toad
Date: 2006-01-25 20:02:28 +0000 (Wed, 25 Jan 2006)
New Revision: 7926
Modified:
branches/async-client/src/freenet/client/async/ClientRequestScheduler.java
branches/async-client/src/freenet/node/Node.java
Log:
complete queued requests immediately on schedule if we have the data
Modified:
branches/async-client/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/async-client/src/freenet/client/async/ClientRequestScheduler.java
2006-01-25 19:34:28 UTC (rev 7925)
+++ branches/async-client/src/freenet/client/async/ClientRequestScheduler.java
2006-01-25 20:02:28 UTC (rev 7926)
@@ -1,6 +1,10 @@
package freenet.client.async;
import freenet.crypt.RandomSource;
+import freenet.keys.ClientKeyBlock;
+import freenet.keys.KeyVerifyException;
+import freenet.node.LowLevelGetException;
+import freenet.node.Node;
import freenet.node.RequestStarter;
import freenet.support.Logger;
import freenet.support.RandomGrabArrayWithInt;
@@ -26,19 +30,37 @@
final boolean isInsertScheduler;
final RandomSource random;
private final RequestStarter starter;
+ private final Node node;
- public ClientRequestScheduler(boolean forInserts, RandomSource random,
RequestStarter starter) {
+ public ClientRequestScheduler(boolean forInserts, RandomSource random,
RequestStarter starter, Node node) {
this.starter = starter;
this.random = random;
+ this.node = node;
this.isInsertScheduler = forInserts;
priorities = new
SortedVectorByNumber[RequestStarter.NUMBER_OF_PRIORITY_CLASSES];
}
public void register(SendableRequest req) {
Logger.minor(this, "Registering "+req, new Exception("debug"));
+ if((!isInsertScheduler) && req instanceof ClientPutter)
+ throw new IllegalArgumentException("Expected a
ClientPut: "+req);
+ if(req instanceof SendableGet) {
+ SendableGet getter = (SendableGet)req;
+ ClientKeyBlock block;
+ try {
+ block = node.fetchKey(getter.getKey());
+ } catch (KeyVerifyException e) {
+ // Verify exception, probably bogus at source;
+ // verifies at low-level, but not at decode.
+ getter.onFailure(new
LowLevelGetException(LowLevelGetException.DECODE_FAILED));
+ return;
+ }
+ if(block != null) {
+ getter.onSuccess(block);
+ return;
+ }
+ }
synchronized(this) {
- if((!isInsertScheduler) && req instanceof ClientPutter)
- throw new IllegalArgumentException("Expected a
ClientPut: "+req);
RandomGrabArrayWithInt grabber =
makeGrabArray(req.getPriorityClass(),
req.getRetryCount());
grabber.add(req);
Modified: branches/async-client/src/freenet/node/Node.java
===================================================================
--- branches/async-client/src/freenet/node/Node.java 2006-01-25 19:34:28 UTC
(rev 7925)
+++ branches/async-client/src/freenet/node/Node.java 2006-01-25 20:02:28 UTC
(rev 7926)
@@ -54,6 +54,7 @@
import freenet.keys.ClientSSKBlock;
import freenet.keys.Key;
import freenet.keys.KeyBlock;
+import freenet.keys.KeyVerifyException;
import freenet.keys.NodeCHK;
import freenet.keys.NodeSSK;
import freenet.keys.SSKBlock;
@@ -454,14 +455,14 @@
archiveManager = new ArchiveManager(MAX_ARCHIVE_HANDLERS,
MAX_CACHED_ARCHIVE_DATA, MAX_ARCHIVE_SIZE, MAX_ARCHIVED_FILE_SIZE,
MAX_CACHED_ELEMENTS, random, tempFilenameGenerator);
requestThrottle = new RequestThrottle(5000, 2.0F);
requestStarter = new RequestStarter(this, requestThrottle,
"Request starter ("+portNumber+")");
- fetchScheduler = new ClientRequestScheduler(false, random,
requestStarter);
+ fetchScheduler = new ClientRequestScheduler(false, random,
requestStarter, this);
requestStarter.setScheduler(fetchScheduler);
requestStarter.start();
//insertThrottle = new ChainedRequestThrottle(10000, 2.0F,
requestThrottle);
// FIXME reenable the above
insertThrottle = new RequestThrottle(10000, 2.0F);
insertStarter = new RequestStarter(this, insertThrottle,
"Insert starter ("+portNumber+")");
- putScheduler = new ClientRequestScheduler(true, random,
insertStarter);
+ putScheduler = new ClientRequestScheduler(true, random,
insertStarter, this);
insertStarter.setScheduler(putScheduler);
insertStarter.start();
if(testnetHandler != null)
@@ -1463,4 +1464,28 @@
public boolean isTestnetEnabled() {
return testnetEnabled;
}
+
+ public ClientKeyBlock fetchKey(ClientKey key) throws KeyVerifyException
{
+ if(key instanceof ClientCHK)
+ return fetch((ClientCHK)key);
+ else if(key instanceof ClientSSK)
+ return fetch((ClientSSK)key);
+ else
+ throw new IllegalStateException("Don't know what to do
with "+key);
+ }
+
+ private ClientKeyBlock fetch(ClientSSK clientSSK) throws
SSKVerifyException {
+ DSAPublicKey key = getKey(clientSSK.pubKeyHash);
+ if(key == null) return null;
+ clientSSK.setPublicKey(key);
+ SSKBlock block = fetch((NodeSSK)clientSSK.getNodeKey());
+ if(block == null) return null;
+ return new ClientSSKBlock(block, clientSSK);
+ }
+
+ private ClientKeyBlock fetch(ClientCHK clientCHK) throws
CHKVerifyException {
+ CHKBlock block = fetch(clientCHK.getNodeCHK());
+ if(block == null) return null;
+ return new ClientCHKBlock(block, clientCHK);
+ }
}