Author: toad
Date: 2008-08-20 21:08:56 +0000 (Wed, 20 Aug 2008)
New Revision: 22067
Modified:
branches/db4o/freenet/src/freenet/client/FetchException.java
branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
branches/db4o/freenet/src/freenet/client/async/ClientGetter.java
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
branches/db4o/freenet/src/freenet/client/async/SingleFileFetcher.java
branches/db4o/freenet/src/freenet/client/async/SplitFileFetcher.java
branches/db4o/freenet/src/freenet/keys/ClientSSK.java
Log:
Transient requests seem to be working. Persistent requests are at least
*partly* working.
Modified: branches/db4o/freenet/src/freenet/client/FetchException.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/FetchException.java
2008-08-20 20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/client/FetchException.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -50,7 +50,9 @@
errorCodes = null;
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
@@ -63,7 +65,9 @@
newURI = null;
this.expectedSize = expectedSize;
this.expectedMimeType = expectedMimeType;
- if(Logger.shouldLog(Logger.MINOR, this))
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
@@ -76,7 +80,9 @@
newURI = uri;
this.expectedSize = expectedSize;
this.expectedMimeType = expectedMimeType;
- if(Logger.shouldLog(Logger.MINOR, this))
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
@@ -88,8 +94,10 @@
initCause(e);
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+e,e);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(ArchiveFailureException e) {
@@ -100,8 +108,10 @@
newURI = null;
initCause(e);
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+e,e);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(ArchiveRestartException e) {
@@ -112,8 +122,11 @@
initCause(e);
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+e,e); }
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
+ }
public FetchException(int mode, Throwable t) {
super(getMessage(mode)+": "+t.getMessage());
@@ -123,8 +136,10 @@
initCause(t);
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+t.getMessage(),t);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(int mode, String reason, Throwable t) {
@@ -135,8 +150,10 @@
initCause(t);
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+t.getMessage(),t);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(int mode, FailureCodeTracker errorCodes) {
@@ -146,8 +163,10 @@
this.errorCodes = errorCodes;
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this, "FetchException("+getMessage(mode)+
')');
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(int mode, String msg) {
@@ -157,8 +176,10 @@
this.mode = mode;
newURI = null;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+msg,this);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(int mode, FreenetURI newURI) {
@@ -168,8 +189,10 @@
errorCodes = null;
this.newURI = newURI;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+") -> "+newURI, this);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(int mode, String msg, FreenetURI uri) {
@@ -179,8 +202,10 @@
this.mode = mode;
newURI = uri;
expectedSize = -1;
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this,
"FetchException("+getMessage(mode)+"): "+msg,this);
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(FetchException e, int newMode) {
@@ -192,6 +217,10 @@
this.expectedSize = e.expectedSize;
this.extraMessage = e.extraMessage;
this.finalizedSizeAndMimeType = e.finalizedSizeAndMimeType;
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public FetchException(FetchException e, FreenetURI uri) {
@@ -204,6 +233,10 @@
this.expectedSize = e.expectedSize;
this.extraMessage = e.extraMessage;
this.finalizedSizeAndMimeType = e.finalizedSizeAndMimeType;
+ if(mode == INTERNAL_ERROR)
+ Logger.error(this, "Internal error: "+this);
+ else if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "FetchException("+getMessage(mode)+
')', this);
}
public static String getShortMessage(int mode) {
Modified:
branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
2008-08-20 20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -36,6 +36,8 @@
protected BaseSingleFileFetcher(ClientKey key, int maxRetries,
FetchContext ctx, ClientRequester parent) {
super(parent);
+ if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "Creating BaseSingleFileFetcher for
"+key);
retryCount = 0;
this.maxRetries = maxRetries;
this.key = key;
@@ -188,10 +190,19 @@
}
synchronized(this) {
chosen = true;
+ if(finished) {
+ if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "onGotKey() called
twice on "+this, new Exception("debug"));
+ return;
+ }
finished = true;
if(persistent)
container.set(this);
if(isCancelled(container)) return;
+ if(key == null)
+ throw new NullPointerException();
+ if(this.key == null)
+ throw new NullPointerException("Key is null on
"+this);
if(!key.equals(this.key.getNodeKey())) {
Logger.normal(this, "Got sent key "+key+" but
want "+this.key+" for "+this);
return;
@@ -244,6 +255,11 @@
}
public void schedule(ObjectContainer container, ClientContext context) {
+ if(persistent) {
+ container.activate(ctx, 1);
+ if(ctx.blocks != null)
+ container.activate(ctx.blocks, 5);
+ }
try {
getScheduler(context).register(this, new SendableGet[]
{ this }, persistent, true, ctx.blocks, false);
} catch (KeyListenerConstructionException e) {
@@ -252,6 +268,11 @@
}
public void reschedule(ObjectContainer container, ClientContext
context) {
+ if(persistent) {
+ container.activate(ctx, 1);
+ if(ctx.blocks != null)
+ container.activate(ctx.blocks, 5);
+ }
try {
getScheduler(context).register(null, new SendableGet[]
{ this }, persistent, true, ctx.blocks, true);
} catch (KeyListenerConstructionException e) {
Modified: branches/db4o/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientGetter.java
2008-08-20 20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/client/async/ClientGetter.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -102,6 +102,9 @@
returnBucket, true, container,
context);
}
if(cancelled) cancel();
+ // schedule() may deactivate stuff, so store it now.
+ if(persistent())
+ container.set(currentState);
if(currentState != null && !finished) {
if(binaryBlobBucket != null) {
try {
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-08-20 20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -294,19 +294,27 @@
} else
listener = null;
+ // Avoid NPEs due to deactivation.
+ if(getters != null) {
+ for(SendableGet getter : getters) {
+ selectorContainer.activate(getter, 1);
+ selectorContainer.set(getter);
+ }
+ }
+
if(isInsertScheduler) {
IllegalStateException e = new
IllegalStateException("finishRegister on an insert scheduler");
throw e;
}
if(!noCheckStore) {
// Check the datastore before proceding.
- for(SendableGet getter : getters)
+ for(SendableGet getter : getters) {
+ selectorContainer.activate(getter, 1);
datastoreChecker.queuePersistentRequest(getter,
blocks, selectorContainer);
+ selectorContainer.deactivate(getter, 1);
+ }
selectorContainer.deactivate(listener, 1);
- if(getters != null) {
- for(int i=0;i<getters.length;i++)
-
selectorContainer.deactivate(getters[i], 1);
- }
+
} else {
// We have already checked the datastore, this is a
retry, the listener hasn't been unregistered.
short prio = RequestStarter.MINIMUM_PRIORITY_CLASS;
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
2008-08-20 20:14:10 UTC (rev 22066)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -300,8 +300,9 @@
}
}
if(matches != null) {
- for(KeyListener listener : matches)
+ for(KeyListener listener : matches) {
listener.handleBlock(key, saltedKey, block,
container, context);
+ }
}
}
Modified: branches/db4o/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/SingleFileFetcher.java
2008-08-20 20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/client/async/SingleFileFetcher.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -522,7 +522,8 @@
parent.onTransition(this, f, container);
if(persistent) {
container.set(metaStrings);
- container.set(this); // Store *before*
scheduling to avoid activation problems.
+ container.set(f); // Store *before*
scheduling to avoid activation problems.
+ container.set(this);
}
f.schedule(container, context);
// All done! No longer our problem!
@@ -604,6 +605,8 @@
SplitFileFetcher sf = new
SplitFileFetcher(metadata, rcb, parent, ctx,
decompressors, clientMetadata,
actx, recursionLevel, returnBucket, token, container, context);
+ if(persistent)
+ container.set(sf); // Avoid problems
caused by storing a deactivated sf
parent.onTransition(this, sf, container);
try {
sf.schedule(container, context);
Modified: branches/db4o/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/SplitFileFetcher.java
2008-08-20 20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/client/async/SplitFileFetcher.java
2008-08-20 21:08:56 UTC (rev 22067)
@@ -205,8 +205,6 @@
this, archiveContext, fetchContext,
maxTempLength, recursionLevel, parent, 0);
if(persistent) {
container.set(segments[0]);
- segments[0].deactivateKeys(container);
- container.deactivate(segments[0], 1);
}
} else {
int dataBlocksPtr = 0;
@@ -227,8 +225,6 @@
fetchContext, maxTempLength,
recursionLevel+1, parent, i);
if(persistent) {
container.set(segments[i]);
- segments[i].deactivateKeys(container);
- container.deactivate(segments[i], 1);
}
}
if(dataBlocksPtr != splitfileDataBlocks.length)
@@ -305,6 +301,9 @@
} catch (IOException e) {
throw new FetchException(FetchException.BUCKET_ERROR,
"Unable to write Bloom filters for splitfile");
}
+ for(int i=0;i<segments.length;i++) {
+ segments[i].deactivateKeys(container);
+ }
}
/** Return the final status of the fetch. Throws an exception, or
returns a
Modified: branches/db4o/freenet/src/freenet/keys/ClientSSK.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/ClientSSK.java 2008-08-20
20:14:10 UTC (rev 22066)
+++ branches/db4o/freenet/src/freenet/keys/ClientSSK.java 2008-08-20
21:08:56 UTC (rev 22067)
@@ -92,6 +92,8 @@
} finally {
SHA256.returnMessageDigest(md);
}
+ if(ehDocname == null)
+ throw new NullPointerException();
}
public ClientSSK(FreenetURI origURI) throws MalformedURLException {
@@ -131,6 +133,10 @@
public Key getNodeKey() {
try {
+ if(ehDocname == null)
+ throw new NullPointerException();
+ if(pubKeyHash == null)
+ throw new NullPointerException();
return new NodeSSK(pubKeyHash, ehDocname, pubKey,
cryptoAlgorithm);
} catch (SSKVerifyException e) {
IllegalStateException x = new
IllegalStateException("Have already verified and yet it fails!: "+e);