Author: toad
Date: 2006-03-24 15:50:24 +0000 (Fri, 24 Mar 2006)
New Revision: 8296
Modified:
trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
trunk/freenet/src/freenet/clients/http/FproxyToadlet.java
trunk/freenet/src/freenet/clients/http/Toadlet.java
trunk/freenet/src/freenet/keys/FreenetURI.java
trunk/freenet/src/freenet/keys/USK.java
trunk/freenet/src/freenet/node/Version.java
Log:
559:
USK bugfixes.
Make USKs work in fproxy.
Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
2006-03-24 03:19:44 UTC (rev 8295)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
2006-03-24 15:50:24 UTC (rev 8296)
@@ -540,7 +540,7 @@
ctx.uskManager.getFetcher(usk, ctx,
parent);
return sf;
} else {
- cb.onFailure(new
FetchException(FetchException.PERMANENT_REDIRECT, usk.copy(edition).getURI()),
null);
+ cb.onFailure(new
FetchException(FetchException.PERMANENT_REDIRECT,
usk.copy(edition).getURI().addMetaStrings(metaStrings)), null);
return null;
}
} else {
@@ -593,7 +593,7 @@
token, false,
returnBucket);
sf.schedule();
} else {
- cb.onFailure(new
FetchException(FetchException.PERMANENT_REDIRECT, usk.copy(l).getURI()), null);
+ cb.onFailure(new
FetchException(FetchException.PERMANENT_REDIRECT,
usk.copy(l).getURI().addMetaStrings(metaStrings)), null);
}
} catch (FetchException e) {
cb.onFailure(e, null);
Modified: trunk/freenet/src/freenet/clients/http/FproxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FproxyToadlet.java 2006-03-24
03:19:44 UTC (rev 8295)
+++ trunk/freenet/src/freenet/clients/http/FproxyToadlet.java 2006-03-24
15:50:24 UTC (rev 8296)
@@ -161,10 +161,14 @@
} catch (FetchException e) {
String msg = e.getMessage();
String extra = "";
- if(e.errorCodes != null)
- extra =
"<pre>"+e.errorCodes.toVerboseString()+"</pre>";
- this.writeReply(ctx, 500 /* close enough - FIXME
probably should depend on status code */,
- "text/html", msg,
"<html><head><title>"+msg+"</title></head><body>Error:
"+HTMLEncoder.encode(msg)+extra+"</body></html>");
+ if(e.newURI != null) {
+ this.writePermanentRedirect(ctx, msg,
"/"+e.newURI.toString());
+ } else {
+ if(e.errorCodes != null)
+ extra =
"<pre>"+e.errorCodes.toVerboseString()+"</pre>";
+ this.writeReply(ctx, 500 /* close enough -
FIXME probably should depend on status code */,
+ "text/html", msg,
"<html><head><title>"+msg+"</title></head><body>Error:
"+HTMLEncoder.encode(msg)+extra+"</body></html>");
+ }
} catch (Throwable t) {
Logger.error(this, "Caught "+t, t);
String msg = "<html><head><title>Internal
Error</title></head><body><h1>Internal Error: please report</h1><pre>";
Modified: trunk/freenet/src/freenet/clients/http/Toadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-03-24 03:19:44 UTC
(rev 8295)
+++ trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-03-24 15:50:24 UTC
(rev 8296)
@@ -1,6 +1,7 @@
package freenet.clients.http;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.URI;
import freenet.client.FetchException;
@@ -11,6 +12,7 @@
import freenet.keys.FreenetURI;
import freenet.support.Bucket;
import freenet.support.BucketTools;
+import freenet.support.HTMLEncoder;
import freenet.support.Logger;
import freenet.support.MultiValueTable;
@@ -138,6 +140,25 @@
ctx.writeData(buf, 0, buf.length);
}
+ protected void writePermanentRedirect(ToadletContext ctx, String msg,
String string) throws ToadletContextClosedException, IOException {
+ MultiValueTable mvt = new MultiValueTable();
+ mvt.put("Location", string);
+ if(msg == null) msg = "";
+ else msg = HTMLEncoder.encode(msg);
+ String redirDoc =
+
"<html><head><title>"+msg+"</title></head><body><h1>Permanent redirect: "+
+ msg+"</h1><a href=\""+string+"\">Click
here</a></body></html>";
+ byte[] buf;
+ try {
+ buf = redirDoc.getBytes("ISO-8859-1");
+ } catch (UnsupportedEncodingException e) {
+ // No way!
+ throw new Error(e);
+ }
+ ctx.sendReplyHeaders(301, "Permanent redirect", mvt,
"text/html;charset=ISO-8859-1", buf.length);
+ ctx.writeData(buf, 0, buf.length);
+ }
+
/**
* Send a simple error page.
*/
Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java 2006-03-24 03:19:44 UTC
(rev 8295)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java 2006-03-24 15:50:24 UTC
(rev 8296)
@@ -131,6 +131,22 @@
this.extra = extra2;
}
+ public FreenetURI(
+ String keyType,
+ String docName,
+ String[] metaStr,
+ byte[] routingKey,
+ byte[] cryptoKey, byte[] extra2,
+ long suggestedEdition) {
+ this.keyType = keyType.trim().toUpperCase();
+ this.docName = docName;
+ this.metaStr = metaStr;
+ this.routingKey = routingKey;
+ this.cryptoKey = cryptoKey;
+ this.extra = extra2;
+ this.suggestedEdition = suggestedEdition;
+ }
+
public FreenetURI(String URI) throws MalformedURLException {
if (URI == null) {
throw new MalformedURLException("No URI specified");
@@ -214,10 +230,11 @@
}
/** USK constructor from components. */
- public FreenetURI(byte[] pubKeyHash, byte[] cryptoKey2, String
siteName, long suggestedEdition2) {
+ public FreenetURI(byte[] pubKeyHash, byte[] cryptoKey, byte[] extra,
String siteName, long suggestedEdition2) {
this.keyType = "USK";
this.routingKey = pubKeyHash;
- this.cryptoKey = cryptoKey2;
+ this.cryptoKey = cryptoKey;
+ this.extra = extra;
this.docName = siteName;
this.suggestedEdition = suggestedEdition2;
}
@@ -327,6 +344,10 @@
}
}
+ public FreenetURI addMetaStrings(LinkedList metaStrings) {
+ return addMetaStrings((String[])metaStrings.toArray(new
String[metaStrings.size()]));
+ }
+
/**
* Returns a copy of this URI with a new Document name set.
*/
@@ -348,7 +369,8 @@
newMetaStr,
routingKey,
cryptoKey,
- extra);
+ extra,
+ suggestedEdition);
}
public String toString() {
@@ -531,4 +553,5 @@
return suggestedEdition;
else throw new IllegalArgumentException("Not a USK requesting
suggested edition");
}
+
}
Modified: trunk/freenet/src/freenet/keys/USK.java
===================================================================
--- trunk/freenet/src/freenet/keys/USK.java 2006-03-24 03:19:44 UTC (rev
8295)
+++ trunk/freenet/src/freenet/keys/USK.java 2006-03-24 15:50:24 UTC (rev
8296)
@@ -62,7 +62,7 @@
}
public FreenetURI getURI() {
- return new FreenetURI(pubKeyHash, cryptoKey, siteName,
suggestedEdition);
+ return new FreenetURI(pubKeyHash, cryptoKey,
ClientSSK.getExtraBytes(), siteName, suggestedEdition);
}
public ClientSSK getSSK(long ver) {
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-03-24 03:19:44 UTC (rev
8295)
+++ trunk/freenet/src/freenet/node/Version.java 2006-03-24 15:50:24 UTC (rev
8296)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 558;
+ private static final int buildNumber = 559;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 507;