Author: toad
Date: 2007-05-21 22:30:19 +0000 (Mon, 21 May 2007)
New Revision: 13292
Modified:
trunk/freenet/src/freenet/keys/FreenetURI.java
trunk/freenet/src/freenet/node/fcp/ClientPut.java
trunk/freenet/src/freenet/node/fcp/ClientPutBase.java
trunk/freenet/src/freenet/node/fcp/ClientPutDir.java
trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
Log:
Show the public URI of an SSK insert in the PersistentPut*.
Maybe there should be an option to override this, but it seems the safest
default.
Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java 2007-05-21 11:11:55 UTC
(rev 13291)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java 2007-05-21 22:30:19 UTC
(rev 13292)
@@ -799,6 +799,17 @@
suggestedEdition);
}
+ public FreenetURI setRoutingKey(byte[] newRoutingKey) {
+ return new FreenetURI(
+ keyType,
+ docName,
+ metaStr,
+ newRoutingKey,
+ cryptoKey,
+ extra,
+ suggestedEdition);
+ }
+
public void checkInsertURI() throws InsertException {
if(metaStr != null && metaStr.length > 0)
throw new
InsertException(InsertException.META_STRINGS_NOT_SUPPORTED,this);
Modified: trunk/freenet/src/freenet/node/fcp/ClientPut.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPut.java 2007-05-21 11:11:55 UTC
(rev 13291)
+++ trunk/freenet/src/freenet/node/fcp/ClientPut.java 2007-05-21 22:30:19 UTC
(rev 13292)
@@ -7,6 +7,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
import java.security.MessageDigest;
import freenet.client.ClientMetadata;
@@ -38,7 +39,7 @@
private final short uploadFrom;
/** Original filename if from disk, otherwise null. Purely for
PersistentPut. */
private final File origFilename;
- /** If uploadFrom==UPLOAD_FROM_REDIRECT, this is the target URI */
+ /** If uploadFrom==UPLOAD_FROM_REDIRECT, this is the target of the
redirect */
private final FreenetURI targetURI;
private final Bucket data;
private final ClientMetadata clientMetadata;
@@ -89,11 +90,12 @@
* @throws IdentifierCollisionException
* @throws NotAllowedException
* @throws FileNotFoundException
+ * @throws MalformedURLException
*/
public ClientPut(FCPClient globalClient, FreenetURI uri, String
identifier, int verbosity,
short priorityClass, short persistenceType, String
clientToken, boolean getCHKOnly,
boolean dontCompress, int maxRetries, short
uploadFromType, File origFilename, String contentType,
- Bucket data, FreenetURI redirectTarget, String
targetFilename, boolean earlyEncode) throws IdentifierCollisionException,
NotAllowedException, FileNotFoundException {
+ Bucket data, FreenetURI redirectTarget, String
targetFilename, boolean earlyEncode) throws IdentifierCollisionException,
NotAllowedException, FileNotFoundException, MalformedURLException {
super(uri, identifier, verbosity, null, globalClient,
priorityClass, persistenceType, null, true, getCHKOnly, dontCompress,
maxRetries, earlyEncode);
if(uploadFromType == ClientPutMessage.UPLOAD_FROM_DISK) {
if(!globalClient.core.allowUploadFrom(origFilename))
@@ -149,7 +151,7 @@
}
}
- public ClientPut(FCPConnectionHandler handler, ClientPutMessage
message) throws IdentifierCollisionException, MessageInvalidException {
+ public ClientPut(FCPConnectionHandler handler, ClientPutMessage
message) throws IdentifierCollisionException, MessageInvalidException,
MalformedURLException {
super(message.uri, message.identifier, message.verbosity,
handler,
message.priorityClass, message.persistenceType,
message.clientToken, message.global,
message.getCHKOnly, message.dontCompress,
message.maxRetries, message.earlyEncode);
@@ -403,7 +405,7 @@
}
protected FCPMessage persistentTagMessage() {
- return new PersistentPut(identifier, uri, verbosity,
priorityClass, uploadFrom, targetURI,
+ return new PersistentPut(identifier, publicURI, verbosity,
priorityClass, uploadFrom, targetURI,
persistenceType, origFilename,
clientMetadata.getMIMEType(), client.isGlobalQueue,
getDataSize(), clientToken, started,
ctx.maxInsertRetries, targetFilename);
}
Modified: trunk/freenet/src/freenet/node/fcp/ClientPutBase.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutBase.java 2007-05-21
11:11:55 UTC (rev 13291)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutBase.java 2007-05-21
22:30:19 UTC (rev 13292)
@@ -12,6 +12,7 @@
import freenet.client.events.SplitfileProgressEvent;
import freenet.client.events.StartedCompressionEvent;
import freenet.keys.FreenetURI;
+import freenet.keys.InsertableClientSSK;
import freenet.support.Fields;
import freenet.support.Logger;
import freenet.support.SimpleFieldSet;
@@ -48,12 +49,14 @@
/** Whether to force an early generation of the CHK */
protected final boolean earlyEncode;
+ protected final FreenetURI publicURI;
+
public final static String SALT = "Salt";
public final static String FILE_HASH = "FileHash";
public ClientPutBase(FreenetURI uri, String identifier, int verbosity,
FCPConnectionHandler handler,
short priorityClass, short persistenceType, String
clientToken, boolean global, boolean getCHKOnly,
- boolean dontCompress, int maxRetries, boolean
earlyEncode) {
+ boolean dontCompress, int maxRetries, boolean
earlyEncode) throws MalformedURLException {
super(uri, identifier, verbosity, handler, priorityClass,
persistenceType, clientToken, global);
this.getCHKOnly = getCHKOnly;
ctx = new InsertContext(client.defaultInsertContext, new
SimpleEventProducer(), persistenceType == ClientRequest.PERSIST_CONNECTION);
@@ -61,11 +64,12 @@
ctx.eventProducer.addEventListener(this);
ctx.maxInsertRetries = maxRetries;
this.earlyEncode = earlyEncode;
+ publicURI = getPublicURI(uri);
}
public ClientPutBase(FreenetURI uri, String identifier, int verbosity,
FCPConnectionHandler handler,
FCPClient client, short priorityClass, short
persistenceType, String clientToken, boolean global,
- boolean getCHKOnly, boolean dontCompress, int
maxRetries, boolean earlyEncode) {
+ boolean getCHKOnly, boolean dontCompress, int
maxRetries, boolean earlyEncode) throws MalformedURLException {
super(uri, identifier, verbosity, handler, client,
priorityClass, persistenceType, clientToken, global);
this.getCHKOnly = getCHKOnly;
ctx = new InsertContext(client.defaultInsertContext, new
SimpleEventProducer(), persistenceType == ClientRequest.PERSIST_CONNECTION);
@@ -73,10 +77,12 @@
ctx.eventProducer.addEventListener(this);
ctx.maxInsertRetries = maxRetries;
this.earlyEncode = earlyEncode;
+ publicURI = getPublicURI(uri);
}
public ClientPutBase(SimpleFieldSet fs, FCPClient client2) throws
MalformedURLException {
super(fs, client2);
+ publicURI = getPublicURI(uri);
getCHKOnly = Fields.stringToBool(fs.get("CHKOnly"), false);
boolean dontCompress =
Fields.stringToBool(fs.get("DontCompress"), false);
int maxRetries = Integer.parseInt(fs.get("MaxRetries"));
@@ -96,6 +102,24 @@
earlyEncode = Fields.stringToBool(fs.get("EarlyEncode"), false);
}
+ private FreenetURI getPublicURI(FreenetURI uri) throws
MalformedURLException {
+ String type = uri.getKeyType();
+ if(type.equalsIgnoreCase("CHK")) {
+ return uri;
+ } else if(type.equalsIgnoreCase("SSK") ||
type.equalsIgnoreCase("USK")) {
+ if(type.equalsIgnoreCase("USK"))
+ uri = uri.setKeyType("SSK");
+ InsertableClientSSK issk =
InsertableClientSSK.create(uri);
+ uri = uri.setRoutingKey(issk.getURI().getRoutingKey());
+ uri = uri.setKeyType(type);
+ return uri;
+ } else if(type.equalsIgnoreCase("KSK")) {
+ return uri;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
public void onLostConnection() {
if(persistenceType == PERSIST_CONNECTION)
cancel();
Modified: trunk/freenet/src/freenet/node/fcp/ClientPutDir.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutDir.java 2007-05-21
11:11:55 UTC (rev 13291)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutDir.java 2007-05-21
22:30:19 UTC (rev 13292)
@@ -5,6 +5,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
@@ -35,7 +36,7 @@
private static boolean logMINOR;
public ClientPutDir(FCPConnectionHandler handler, ClientPutDirMessage
message,
- HashMap manifestElements) throws
IdentifierCollisionException {
+ HashMap manifestElements) throws
IdentifierCollisionException, MalformedURLException {
super(message.uri, message.identifier, message.verbosity,
handler,
message.priorityClass, message.persistenceType,
message.clientToken, message.global,
message.getCHKOnly, message.dontCompress,
message.maxRetries, message.earlyEncode);
@@ -241,7 +242,7 @@
}
protected FCPMessage persistentTagMessage() {
- return new PersistentPutDir(identifier, uri, verbosity,
priorityClass,
+ return new PersistentPutDir(identifier, publicURI, verbosity,
priorityClass,
persistenceType, global, defaultName,
manifestElements, clientToken, started, ctx.maxInsertRetries);
}
Modified: trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2007-05-21 11:11:55 UTC (rev 13291)
+++ trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2007-05-21 22:30:19 UTC (rev 13292)
@@ -4,6 +4,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.Socket;
import java.util.HashMap;
import java.util.Iterator;
@@ -197,9 +198,10 @@
Logger.minor(this, "Starting insert
ID=\""+message.identifier+ '"');
String id = message.identifier;
ClientPut cp = null;
- boolean success;
boolean persistent = message.persistenceType !=
ClientRequest.PERSIST_CONNECTION;
+ FCPMessage failedMessage = null;
synchronized(this) {
+ boolean success;
if(isClosed) return;
// We need to track non-persistent requests anyway, so
we may as well check
if(persistent)
@@ -214,15 +216,19 @@
} catch (MessageInvalidException e) {
outputHandler.queue(new
ProtocolErrorMessage(e.protocolCode, false, e.getMessage(), e.ident, false));
return;
+ } catch (MalformedURLException e) {
+ failedMessage = new
ProtocolErrorMessage(ProtocolErrorMessage.URI_PARSE_ERROR, true, null, id,
message.global);
}
if(!persistent)
requestsByIdentifier.put(id, cp);
}
+ if(!success) {
+ Logger.normal(this, "Identifier collision on
"+this);
+ failedMessage = new
IdentifierCollisionMessage(id, message.global);
+ }
}
- if(!success) {
- Logger.normal(this, "Identifier collision on "+this);
- FCPMessage msg = new IdentifierCollisionMessage(id,
message.global);
- outputHandler.queue(msg);
+ if(failedMessage != null) {
+ outputHandler.queue(failedMessage);
return;
} else {
Logger.minor(this, "Starting "+cp);
@@ -241,12 +247,13 @@
Logger.minor(this, "Start ClientPutDir");
String id = message.identifier;
ClientPutDir cp = null;
- boolean success;
+ FCPMessage failedMessage = null;
boolean persistent = message.persistenceType !=
ClientRequest.PERSIST_CONNECTION;
synchronized(this) {
if(isClosed) return;
// We need to track non-persistent requests anyway, so
we may as well check
- if(persistent)
+ boolean success;
+ if(!persistent)
success = true;
else
success = !requestsByIdentifier.containsKey(id);
@@ -255,15 +262,20 @@
cp = new ClientPutDir(this, message,
buckets);
} catch (IdentifierCollisionException e) {
success = false;
+ } catch (MalformedURLException e) {
+ failedMessage = new
ProtocolErrorMessage(ProtocolErrorMessage.URI_PARSE_ERROR, true, null, id,
message.global);
}
if(!persistent)
requestsByIdentifier.put(id, cp);
+
}
+ if(!success) {
+ Logger.normal(this, "Identifier collision on
"+this);
+ failedMessage = new
IdentifierCollisionMessage(id, message.global);
+ }
}
- if(!success) {
- Logger.normal(this, "Identifier collision on "+this);
- FCPMessage msg = new IdentifierCollisionMessage(id,
message.global);
- outputHandler.queue(msg);
+ if(failedMessage != null) {
+ outputHandler.queue(failedMessage);
return;
} else {
// Register before starting, because it may complete
immediately, and if it does,