Author: toad
Date: 2009-03-07 18:23:08 +0000 (Sat, 07 Mar 2009)
New Revision: 25942
Modified:
branches/db4o/freenet/src/freenet/client/async/USKInserter.java
branches/db4o/freenet/src/freenet/client/async/USKManager.java
branches/db4o/freenet/src/freenet/keys/InsertableUSK.java
Log:
USK removal bugfixes
Modified: branches/db4o/freenet/src/freenet/client/async/USKInserter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKInserter.java
2009-03-07 18:21:49 UTC (rev 25941)
+++ branches/db4o/freenet/src/freenet/client/async/USKInserter.java
2009-03-07 18:23:08 UTC (rev 25942)
@@ -54,6 +54,7 @@
/** After attempting inserts on this many slots, go back to the Fetcher
*/
private static final long MAX_TRIED_SLOTS = 10;
private boolean freeData;
+ final int hashCode;
public void schedule(ObjectContainer container, ClientContext context)
throws InsertException {
// Caller calls schedule()
@@ -78,7 +79,7 @@
if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "scheduling fetcher for
"+pubUSK.getURI());
if(finished) return;
- fetcher =
context.uskManager.getFetcherForInsertDontSchedule(pubUSK,
parent.priorityClass, this, parent.getClient(), container, context);
+ fetcher =
context.uskManager.getFetcherForInsertDontSchedule(pubUSK,
parent.priorityClass, this, parent.getClient(), container, context, persistent);
}
fetcher.schedule(container, context);
}
@@ -102,17 +103,19 @@
Logger.error(this, "Could not decode:
"+e, e);
}
}
- if(!alreadyInserted) {
- if(parent.persistent())
- fetcher.removeFrom(container, context);
+ if(parent.persistent()) {
+ fetcher.removeFrom(container, context);
+ fetcher.ctx.removeFrom(container);
fetcher = null;
}
}
if(alreadyInserted) {
// Success!
- cb.onEncode(pubUSK.copy(edition), this, container,
context);
parent.addMustSucceedBlocks(1, container);
parent.completedBlock(true, container, context);
+ if(persistent)
+ container.activate(cb, 1);
+ cb.onEncode(pubUSK.copy(edition), this, container,
context);
cb.onSuccess(this, container, context);
if(freeData) {
data.free();
@@ -148,7 +151,8 @@
}
public synchronized void onSuccess(ClientPutState state,
ObjectContainer container, ClientContext context) {
- cb.onEncode(pubUSK.copy(edition), this, container, context);
+ USK newEdition = pubUSK.copy(edition);
+ cb.onEncode(newEdition, this, container, context);
cb.onSuccess(this, container, context);
finished = true;
sbi = null;
@@ -190,9 +194,14 @@
}
}
+ public int hashCode() {
+ return hashCode;
+ }
+
public USKInserter(BaseClientPutter parent, Bucket data, short
compressionCodec, FreenetURI uri,
InsertContext ctx, PutCompletionCallback cb, boolean
isMetadata, int sourceLength, int token,
boolean getCHKOnly, boolean addToParent, Object
tokenObject, ObjectContainer container, ClientContext context, boolean
freeData, boolean persistent) throws MalformedURLException {
+ this.hashCode = super.hashCode();
this.tokenObject = tokenObject;
this.persistent = persistent;
this.parent = parent;
@@ -209,7 +218,7 @@
parent.addMustSucceedBlocks(1, container);
parent.notifyClients(container, context);
}
- privUSK = InsertableUSK.createInsertable(uri);
+ privUSK = InsertableUSK.createInsertable(uri, persistent);
pubUSK = privUSK.getUSK();
edition = pubUSK.suggestedEdition;
this.freeData = freeData;
@@ -247,8 +256,10 @@
public synchronized void onCancelled(ObjectContainer container,
ClientContext context) {
if(fetcher != null) {
- if(parent.persistent())
+ if(parent.persistent()) {
+ fetcher.ctx.removeFrom(container);
fetcher.removeFrom(container, context);
+ }
fetcher = null;
}
if(finished) return;
@@ -295,6 +306,8 @@
}
public void removeFrom(ObjectContainer container, ClientContext
context) {
+ if(Logger.shouldLog(Logger.MINOR, this))
+ Logger.minor(this, "Removing from database: "+this);
// parent will remove self
if(freeData && data != null && container.ext().isStored(data)) {
try {
@@ -310,7 +323,8 @@
privUSK.removeFrom(container);
pubUSK.removeFrom(container);
if(fetcher != null) {
- Logger.error(this, "Fetcher tag still present:
"+fetcher+" in removeFrom() for "+this);
+ Logger.error(this, "Fetcher tag still present:
"+fetcher+" in removeFrom() for "+this, new Exception("debug"));
+ fetcher.ctx.removeFrom(container);
fetcher.removeFrom(container, context);
}
if(sbi != null) {
@@ -320,4 +334,14 @@
container.delete(this);
}
+ public boolean objectCanNew(ObjectContainer container) {
+ Logger.minor(this, "objectCanNew() on "+this, new
Exception("debug"));
+ return true;
+ }
+
+ public boolean objectCanUpdate(ObjectContainer container) {
+ Logger.minor(this, "objectCanUpdate() on "+this, new
Exception("debug"));
+ return true;
+ }
+
}
Modified: branches/db4o/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKManager.java
2009-03-07 18:21:49 UTC (rev 25941)
+++ branches/db4o/freenet/src/freenet/client/async/USKManager.java
2009-03-07 18:23:08 UTC (rev 25942)
@@ -97,8 +97,8 @@
return f;
}
- public USKFetcherTag getFetcherForInsertDontSchedule(USK usk, short
prioClass, USKFetcherCallback cb, RequestClient client, ObjectContainer
container, ClientContext context) {
- return getFetcher(usk, backgroundFetchContext, true,
client.persistent(), cb, container, context);
+ public USKFetcherTag getFetcherForInsertDontSchedule(USK usk, short
prioClass, USKFetcherCallback cb, RequestClient client, ObjectContainer
container, ClientContext context, boolean persistent) {
+ return getFetcher(usk, persistent ? new
FetchContext(backgroundFetchContext, FetchContext.IDENTICAL_MASK, false, null)
: backgroundFetchContext, true, client.persistent(), cb, container, context);
}
public void startTemporaryBackgroundFetcher(USK usk, ClientContext
context) {
Modified: branches/db4o/freenet/src/freenet/keys/InsertableUSK.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/InsertableUSK.java 2009-03-07
18:21:49 UTC (rev 25941)
+++ branches/db4o/freenet/src/freenet/keys/InsertableUSK.java 2009-03-07
18:23:08 UTC (rev 25942)
@@ -5,6 +5,8 @@
import java.net.MalformedURLException;
+import com.db4o.ObjectContainer;
+
import freenet.crypt.DSAGroup;
import freenet.crypt.DSAPrivateKey;
import freenet.crypt.DSAPublicKey;
@@ -24,12 +26,12 @@
public final DSAPrivateKey privKey;
public final DSAGroup group;
- public static InsertableUSK createInsertable(FreenetURI uri) throws
MalformedURLException {
+ public static InsertableUSK createInsertable(FreenetURI uri, boolean
persistent) throws MalformedURLException {
if(!uri.getKeyType().equalsIgnoreCase("USK"))
throw new MalformedURLException();
InsertableClientSSK ssk =
InsertableClientSSK.create(uri.setKeyType("SSK"));
- return new InsertableUSK(ssk.docName, ssk.pubKeyHash,
ssk.cryptoKey, ssk.privKey, ssk.getCryptoGroup(), uri.getSuggestedEdition(),
ssk.cryptoAlgorithm);
+ return new InsertableUSK(ssk.docName, ssk.pubKeyHash,
ssk.cryptoKey, ssk.privKey, persistent ? ssk.getCryptoGroup().cloneKey() :
ssk.getCryptoGroup(), uri.getSuggestedEdition(), ssk.cryptoAlgorithm);
}
InsertableUSK(String docName, byte[] pubKeyHash, byte[] cryptoKey,
DSAPrivateKey key, DSAGroup group, long suggestedEdition, byte cryptoAlgorithm)
throws MalformedURLException {
@@ -68,4 +70,9 @@
}
}
+ public void removeFrom(ObjectContainer container) {
+ privKey.removeFrom(container);
+ group.removeFrom(container);
+ super.removeFrom(container);
+ }
}
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs