r27002 - in trunk/freenet/src/freenet: client/async keys

[email protected] Sat, 18 Apr 2009 18:00:47 +0000
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: toad
Date: 2009-04-18 18:00:47 +0000 (Sat, 18 Apr 2009)
New Revision: 27002

Modified:
   trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/keys/FreenetURI.java
Log:
Make direct SSK fetches update the USKManager if they are USK compatible.


Modified: trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java	2009-04-18 18:00:00 UTC (rev 27001)
+++ trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java	2009-04-18 18:00:47 UTC (rev 27002)
@@ -4,6 +4,7 @@
 package freenet.client.async;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 
 import com.db4o.ObjectContainer;
 
@@ -13,8 +14,11 @@
 import freenet.client.FetchResult;
 import freenet.keys.ClientKey;
 import freenet.keys.ClientKeyBlock;
+import freenet.keys.ClientSSK;
+import freenet.keys.FreenetURI;
 import freenet.keys.KeyDecodeException;
 import freenet.keys.TooBigException;
+import freenet.keys.USK;
 import freenet.node.LowLevelGetException;
 import freenet.support.Logger;
 import freenet.support.api.Bucket;
@@ -140,6 +144,21 @@
 		Bucket data = extract(block, container, context);
 		if(data == null) return; // failed
 		if(!block.isMetadata()) {
+			if(key instanceof ClientSSK) {
+				try {
+					FreenetURI uri = this.key.getURI();
+					if(uri.isSSK() && uri.isSSKForUSK()) {
+						uri = uri.uskForSSK();
+						USK u = USK.create(uri);
+						context.uskManager.updateKnownGood(u, uri.getSuggestedEdition(), context);
+					}
+				} catch (MalformedURLException e) {
+					Logger.error(this, "Caught "+e, e);
+				} catch (Throwable t) {
+					// Don't let the USK hint cause us to not succeed on the block.
+					Logger.error(this, "Caught "+t, t);
+				}
+			}
 			onSuccess(new FetchResult((ClientMetadata)null, data), container, context);
 		} else {
 			onFailure(new FetchException(FetchException.INVALID_METADATA, "Metadata where expected data"), false, container, context);

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java	2009-04-18 18:00:00 UTC (rev 27001)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java	2009-04-18 18:00:47 UTC (rev 27002)
@@ -159,6 +159,21 @@
 			Logger.error(this, "block is null! fromStore="+fromStore+", token="+token, new Exception("error"));
 			return;
 		}
+		if(key instanceof ClientSSK) {
+			try {
+				if(uri.isSSK() && uri.isSSKForUSK()) {
+					if(persistent) container.activate(uri, 5);
+					FreenetURI uu = uri.setMetaString(null).uskForSSK();
+					USK usk = USK.create(uu);
+					context.uskManager.updateKnownGood(usk, uu.getSuggestedEdition(), context);
+				}
+			} catch (MalformedURLException e) {
+				Logger.error(this, "Caught "+e, e);
+			} catch (Throwable t) {
+				// Don't let the USK hint cause us to not succeed on the block.
+				Logger.error(this, "Caught "+t, t);
+			}
+		}
 		Bucket data = extract(block, container, context);
 		if(data == null) {
 			if(logMINOR)

Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java	2009-04-18 18:00:00 UTC (rev 27001)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java	2009-04-18 18:00:47 UTC (rev 27002)
@@ -925,6 +925,10 @@
 		return new FreenetURI("SSK", docName+"-"+suggestedEdition, metaStr, routingKey, cryptoKey, extra, 0);
 	}
 
+	public boolean isSSKForUSK() {
+		return keyType.equalsIgnoreCase("SSK") && docName.matches(".*\\-[0-9]+");
+	}
+	
 	public FreenetURI uskForSSK() {
 		if(!keyType.equalsIgnoreCase("SSK")) throw new IllegalStateException();
 		if (!docName.matches(".*\\-[0-9]+"))