Author: nextgens
Date: 2006-02-03 23:24:42 +0000 (Fri, 03 Feb 2006)
New Revision: 8001
Modified:
branches/freenet-freejvms/src/freenet/client/async/SingleBlockInserter.java
branches/freenet-freejvms/src/freenet/node/Node.java
branches/freenet-freejvms/src/freenet/node/Version.java
branches/freenet-freejvms/src/freenet/node/fcp/AllDataMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/ClientGet.java
branches/freenet-freejvms/src/freenet/node/fcp/ClientGetMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/ClientHelloMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/ClientPutMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/DataFoundMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/FCPConnectionInputHandler.java
branches/freenet-freejvms/src/freenet/node/fcp/FCPMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/GenerateSSKMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/GetFailedMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/IdentifierCollisionMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/MessageInvalidException.java
branches/freenet-freejvms/src/freenet/node/fcp/ProtocolErrorMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/PutFailedMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/PutSuccessfulMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/SSKKeypairMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/SimpleProgressMessage.java
branches/freenet-freejvms/src/freenet/node/fcp/URIGeneratedMessage.java
branches/freenet-freejvms/src/freenet/support/ArrayBucket.java
branches/freenet-freejvms/src/freenet/support/Bucket.java
branches/freenet-freejvms/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
branches/freenet-freejvms/src/freenet/support/RandomAccessFileBucket.java
branches/freenet-freejvms/src/freenet/support/ReadOnlyFileSliceBucket.java
branches/freenet-freejvms/src/freenet/support/SimpleReadOnlyArrayBucket.java
branches/freenet-freejvms/src/freenet/support/io/FileBucket.java
Log:
Merged with the current trunk (r8000)
Modified:
branches/freenet-freejvms/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- branches/freenet-freejvms/src/freenet/client/async/SingleBlockInserter.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/client/async/SingleBlockInserter.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import freenet.client.FailureCodeTracker;
@@ -35,7 +36,7 @@
private final FailureCodeTracker errors;
private boolean finished;
private ClientKey key;
- private SoftReference refToClientKeyBlock;
+ private WeakReference refToClientKeyBlock;
final int token; // for e.g. splitfiles
final boolean isMetadata;
final boolean getCHKOnly;
@@ -101,7 +102,7 @@
}
ClientKeyBlock block = innerEncode();
refToClientKeyBlock =
- new SoftReference(block);
+ new WeakReference(block);
resultingURI = block.getClientKey().getURI();
cb.onEncode(block.getClientKey(), this);
return block;
Modified: branches/freenet-freejvms/src/freenet/node/Node.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/Node.java 2006-02-03
23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/Node.java 2006-02-03
23:24:42 UTC (rev 8001)
@@ -1400,7 +1400,7 @@
public void run() {
Runtime r = Runtime.getRuntime();
while(true) {
- for(int i=0;i<20;i++) {
+ for(int i=0;i<120;i++) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
Modified: branches/freenet-freejvms/src/freenet/node/Version.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/Version.java 2006-02-03
23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/Version.java 2006-02-03
23:24:42 UTC (rev 8001)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 431;
+ private static final int buildNumber = 432;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 403;
Modified: branches/freenet-freejvms/src/freenet/node/fcp/AllDataMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/AllDataMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/AllDataMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -36,7 +36,7 @@
}
public void run(FCPConnectionHandler handler, Node node) throws
MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "AllData goes
from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "AllData goes
from server to client not the other way around", identifier);
}
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/ClientGet.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/ClientGet.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/ClientGet.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -1,5 +1,10 @@
package freenet.node.fcp;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
import freenet.client.FetchException;
import freenet.client.FetchResult;
import freenet.client.FetcherContext;
@@ -12,6 +17,8 @@
import freenet.client.events.ClientEventListener;
import freenet.client.events.SplitfileProgressEvent;
import freenet.keys.FreenetURI;
+import freenet.support.Bucket;
+import freenet.support.BucketTools;
import freenet.support.Logger;
/**
@@ -27,7 +34,10 @@
private final FCPConnectionHandler handler;
private final ClientGetter getter;
private final short priorityClass;
+ private final short returnType;
private boolean finished;
+ private final File targetFile;
+ private final File tempFile;
// Verbosity bitmasks
private int VERBOSITY_SPLITFILE_PROGRESS = 1;
@@ -50,10 +60,11 @@
this.verbosity = message.verbosity;
// FIXME do something with verbosity !!
// Has already been checked
- if(message.returnType != ClientGetMessage.RETURN_TYPE_DIRECT)
- throw new IllegalStateException("Unknown return type:
"+message.returnType);
+ this.returnType = message.returnType;
fctx.maxOutputLength = message.maxSize;
fctx.maxTempLength = message.maxTempSize;
+ this.targetFile = message.diskFile;
+ this.tempFile = message.tempFile;
getter = new ClientGetter(this, handler.node.fetchScheduler,
uri, fctx, priorityClass, handler.defaultFetchContext);
try {
getter.start();
@@ -69,11 +80,52 @@
public void onSuccess(FetchResult result, ClientGetter state) {
finished = true;
FCPMessage msg = new DataFoundMessage(handler, result,
identifier);
- handler.outputHandler.queue(msg);
- // Send all the data at once
- // FIXME there should be other options
- msg = new AllDataMessage(handler, result.asBucket(),
identifier);
- handler.outputHandler.queue(msg);
+ Bucket data = result.asBucket();
+ if(returnType == ClientGetMessage.RETURN_TYPE_DIRECT) {
+ // Send all the data at once
+ // FIXME there should be other options
+ handler.outputHandler.queue(msg);
+ msg = new AllDataMessage(handler, data, identifier);
+ handler.outputHandler.queue(msg);
+ return; // don't delete the bucket yet
+ } else if(returnType == ClientGetMessage.RETURN_TYPE_NONE) {
+ // Do nothing
+ handler.outputHandler.queue(msg);
+ data.free();
+ return;
+ } else if(returnType == ClientGetMessage.RETURN_TYPE_DISK) {
+ // Write to temp file, then rename over filename
+ FileOutputStream fos;
+ try {
+ fos = new FileOutputStream(tempFile);
+ } catch (FileNotFoundException e) {
+ ProtocolErrorMessage pm = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null,
identifier);
+ handler.outputHandler.queue(pm);
+ data.free();
+ return;
+ }
+ try {
+ BucketTools.copyTo(data, fos, data.size());
+ } catch (IOException e) {
+ ProtocolErrorMessage pm = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null,
identifier);
+ handler.outputHandler.queue(pm);
+ data.free();
+ return;
+ }
+ try {
+ fos.close();
+ } catch (IOException e) {
+ Logger.error(this, "Caught "+e+" closing file
"+tempFile, e);
+ }
+ if(!tempFile.renameTo(targetFile)) {
+ ProtocolErrorMessage pm = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_RENAME_FILE, false, null,
identifier);
+ handler.outputHandler.queue(pm);
+ // Don't delete temp bucket, might want it
+ }
+ data.free();
+ handler.outputHandler.queue(msg);
+ return;
+ }
}
public void onFailure(FetchException e, ClientGetter state) {
Modified: branches/freenet-freejvms/src/freenet/node/fcp/ClientGetMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/ClientGetMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/ClientGetMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -1,5 +1,7 @@
package freenet.node.fcp;
+import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import freenet.keys.FreenetURI;
@@ -33,26 +35,32 @@
final FreenetURI uri;
final String identifier;
final int verbosity;
- final int returnType;
+ final short returnType;
final long maxSize;
final long maxTempSize;
final int maxRetries;
final short priorityClass;
+ final File diskFile;
+ final File tempFile;
// FIXME move these to the actual getter process
- static final int RETURN_TYPE_DIRECT = 0;
+ static final short RETURN_TYPE_DIRECT = 0; // over FCP
+ static final short RETURN_TYPE_NONE = 1; // not at all; to cache only;
prefetch?
+ static final short RETURN_TYPE_DISK = 2; // to a file
+ static final short RETURN_TYPE_CHUNKED = 3; // FIXME implement: over
FCP, as decoded
public ClientGetMessage(SimpleFieldSet fs) throws
MessageInvalidException {
+ short defaultPriority;
ignoreDS = Boolean.getBoolean(fs.get("IgnoreDS"));
dsOnly = Boolean.getBoolean(fs.get("DSOnly"));
+ identifier = fs.get("Identifier");
+ if(identifier == null)
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier",
null);
try {
uri = new FreenetURI(fs.get("URI"));
} catch (MalformedURLException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.URI_PARSE_ERROR, e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.URI_PARSE_ERROR, e.getMessage(),
identifier);
}
- identifier = fs.get("Identifier");
- if(identifier == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier");
String verbosityString = fs.get("Verbosity");
if(verbosityString == null)
verbosity = 0;
@@ -60,14 +68,44 @@
try {
verbosity = Integer.parseInt(verbosityString,
10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Verbosity field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Verbosity field: "+e.getMessage(), identifier);
}
}
String returnTypeString = fs.get("ReturnType");
- if(returnTypeString == null ||
returnTypeString.equalsIgnoreCase("direct"))
+ if(returnTypeString == null ||
returnTypeString.equalsIgnoreCase("direct")) {
returnType = RETURN_TYPE_DIRECT;
- else
- throw new
MessageInvalidException(ProtocolErrorMessage.MESSAGE_PARSE_ERROR, "Unknown
return-type");
+ diskFile = null;
+ tempFile = null;
+ // default just below fproxy
+ defaultPriority =
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+ } else if(returnTypeString.equalsIgnoreCase("none")) {
+ diskFile = null;
+ tempFile = null;
+ returnType = RETURN_TYPE_NONE;
+ defaultPriority =
RequestStarter.PREFETCH_PRIORITY_CLASS;
+ } else if(returnTypeString.equalsIgnoreCase("disk")) {
+ defaultPriority =
RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS;
+ returnType = RETURN_TYPE_DISK;
+ String filename = fs.get("Filename");
+ if(filename == null)
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Missing Filename",
identifier);
+ diskFile = new File(filename);
+ String tempFilename = fs.get("TempFilename");
+ if(tempFilename == null)
+ tempFilename = filename + ".freenet-tmp";
+ tempFile = new File(tempFilename);
+
if(!diskFile.getParentFile().equals(tempFile.getParentFile()))
+ throw new
MessageInvalidException(ProtocolErrorMessage.FILENAME_AND_TEMP_FILENAME_MUST_BE_IN_SAME_DIR,
null, identifier);
+ if(diskFile.exists())
+ throw new
MessageInvalidException(ProtocolErrorMessage.DISK_TARGET_EXISTS, null,
identifier);
+ try {
+ if(!tempFile.createNewFile())
+ throw new
MessageInvalidException(ProtocolErrorMessage.COULD_NOT_CREATE_FILE, null,
identifier);
+ } catch (IOException e) {
+ throw new
MessageInvalidException(ProtocolErrorMessage.COULD_NOT_CREATE_FILE,
e.getMessage(), identifier);
+ }
+ } else
+ throw new
MessageInvalidException(ProtocolErrorMessage.MESSAGE_PARSE_ERROR, "Unknown
return-type", identifier);
String maxSizeString = fs.get("MaxSize");
if(maxSizeString == null)
// default to unlimited
@@ -76,7 +114,7 @@
try {
maxSize = Long.parseLong(maxSizeString, 10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage(), identifier);
}
}
String maxTempSizeString = fs.get("MaxTempSize");
@@ -87,7 +125,7 @@
try {
maxTempSize = Long.parseLong(maxTempSizeString,
10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage(), identifier);
}
}
String maxRetriesString = fs.get("MaxRetries");
@@ -98,20 +136,20 @@
try {
maxRetries = Integer.parseInt(maxRetriesString,
10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage(), identifier);
}
}
String priorityString = fs.get("PriorityClass");
if(priorityString == null) {
// defaults to the one just below fproxy
- priorityClass =
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
+ priorityClass = defaultPriority;
} else {
try {
priorityClass =
Short.parseShort(priorityString, 10);
if(priorityClass <
RequestStarter.MAXIMUM_PRIORITY_CLASS || priorityClass >
RequestStarter.MINIMUM_PRIORITY_CLASS)
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "Valid priorities
are from "+RequestStarter.MAXIMUM_PRIORITY_CLASS+" to
"+RequestStarter.MINIMUM_PRIORITY_CLASS);
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "Valid priorities
are from "+RequestStarter.MAXIMUM_PRIORITY_CLASS+" to
"+RequestStarter.MINIMUM_PRIORITY_CLASS, identifier);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing PriorityClass field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing PriorityClass field: "+e.getMessage(), identifier);
}
}
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/ClientHelloMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/ClientHelloMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/ClientHelloMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -19,9 +19,9 @@
clientName = fs.get("Name");
clientExpectedVersion = fs.get("ExpectedVersion");
if(clientName == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "ClientHello must
contain a Name field");
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "ClientHello must
contain a Name field", null);
if(clientExpectedVersion == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "ClientHello must
contain a ExpectedVersion field");
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "ClientHello must
contain a ExpectedVersion field", null);
// FIXME check the expected version
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/ClientPutMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/ClientPutMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -43,17 +43,17 @@
final boolean fromDisk;
public ClientPutMessage(SimpleFieldSet fs) throws
MessageInvalidException {
+ identifier = fs.get("Identifier");
+ if(identifier == null)
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier",
null);
try {
String u = fs.get("URI");
if(u == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No URI");
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No URI",
identifier);
uri = new FreenetURI(fs.get("URI"));
} catch (MalformedURLException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.URI_PARSE_ERROR, e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.URI_PARSE_ERROR, e.getMessage(),
identifier);
}
- identifier = fs.get("Identifier");
- if(identifier == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier");
String verbosityString = fs.get("Verbosity");
if(verbosityString == null)
verbosity = 0;
@@ -61,7 +61,7 @@
try {
verbosity = Integer.parseInt(verbosityString,
10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Verbosity field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Verbosity field: "+e.getMessage(), identifier);
}
}
contentType = fs.get("Metadata.ContentType");
@@ -73,7 +73,7 @@
try {
maxRetries = Integer.parseInt(maxRetriesString,
10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage(), identifier);
}
}
getCHKOnly = Boolean.getBoolean(fs.get("GetCHKOnly"));
@@ -85,9 +85,9 @@
try {
priorityClass =
Short.parseShort(priorityString, 10);
if(priorityClass <
RequestStarter.MAXIMUM_PRIORITY_CLASS || priorityClass >
RequestStarter.MINIMUM_PRIORITY_CLASS)
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "Valid priorities
are from "+RequestStarter.MAXIMUM_PRIORITY_CLASS+" to
"+RequestStarter.MINIMUM_PRIORITY_CLASS);
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "Valid priorities
are from "+RequestStarter.MAXIMUM_PRIORITY_CLASS+" to
"+RequestStarter.MINIMUM_PRIORITY_CLASS, identifier);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing PriorityClass field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing PriorityClass field: "+e.getMessage(), identifier);
}
}
String uploadFrom = fs.get("UploadFrom");
@@ -95,10 +95,10 @@
fromDisk = true;
String filename = fs.get("Filename");
if(filename == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Missing field
Filename");
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Missing field
Filename", identifier);
File f = new File(filename);
if(!(f.exists() && f.isFile() && f.canRead()))
- throw new
MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, null);
+ throw new
MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, null, identifier);
dataLength = f.length();
FileBucket fileBucket = new FileBucket(f, true, false,
false);
this.bucket = fileBucket;
@@ -106,11 +106,11 @@
fromDisk = false;
String dataLengthString = fs.get("DataLength");
if(dataLengthString == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Need DataLength on
a ClientPut");
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Need DataLength on
a ClientPut", identifier);
try {
dataLength = Long.parseLong(dataLengthString,
10);
} catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing DataLength field: "+e.getMessage());
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing DataLength field: "+e.getMessage(), identifier);
}
}
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/DataFoundMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/DataFoundMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/DataFoundMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -29,7 +29,7 @@
}
public void run(FCPConnectionHandler handler, Node node) throws
MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "DataFound goes
from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "DataFound goes
from server to client not the other way around", identifier);
}
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/FCPConnectionInputHandler.java
===================================================================
---
branches/freenet-freejvms/src/freenet/node/fcp/FCPConnectionInputHandler.java
2006-02-03 23:02:41 UTC (rev 8000)
+++
branches/freenet-freejvms/src/freenet/node/fcp/FCPConnectionInputHandler.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -50,12 +50,12 @@
msg = FCPMessage.create(messageType, fs);
if(msg == null) continue;
} catch (MessageInvalidException e) {
- FCPMessage err = new
ProtocolErrorMessage(e.protocolCode, false, e.getMessage());
+ FCPMessage err = new
ProtocolErrorMessage(e.protocolCode, false, e.getMessage(), e.ident);
handler.outputHandler.queue(err);
continue;
}
if(firstMessage && !(msg instanceof
ClientHelloMessage)) {
- FCPMessage err = new
ProtocolErrorMessage(ProtocolErrorMessage.CLIENT_HELLO_MUST_BE_FIRST_MESSAGE,
true, null);
+ FCPMessage err = new
ProtocolErrorMessage(ProtocolErrorMessage.CLIENT_HELLO_MUST_BE_FIRST_MESSAGE,
true, null, null);
handler.outputHandler.queue(err);
handler.close();
continue;
@@ -64,14 +64,14 @@
((DataCarryingMessage)msg).readFrom(lis,
handler.bf);
}
if((!firstMessage) && msg instanceof
ClientHelloMessage) {
- FCPMessage err = new
ProtocolErrorMessage(ProtocolErrorMessage.NO_LATE_CLIENT_HELLOS, false, null);
+ FCPMessage err = new
ProtocolErrorMessage(ProtocolErrorMessage.NO_LATE_CLIENT_HELLOS, false, null,
null);
handler.outputHandler.queue(err);
continue;
}
try {
msg.run(handler, handler.node);
} catch (MessageInvalidException e) {
- FCPMessage err = new
ProtocolErrorMessage(e.protocolCode, false, e.getMessage());
+ FCPMessage err = new
ProtocolErrorMessage(e.protocolCode, false, e.getMessage(), e.ident);
handler.outputHandler.queue(err);
continue;
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/FCPMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/FCPMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/FCPMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -32,7 +32,7 @@
if(name.equals(ClientPutMessage.name))
return new ClientPutMessage(fs);
if(name.equals(GenerateSSKMessage.name))
- return new GenerateSSKMessage();
+ return new GenerateSSKMessage(fs);
if(name.equals("Void"))
return null;
// if(name.equals("ClientPut"))
Modified: branches/freenet-freejvms/src/freenet/node/fcp/GenerateSSKMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/GenerateSSKMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/GenerateSSKMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -8,7 +8,12 @@
public class GenerateSSKMessage extends FCPMessage {
static final String name = "GenerateSSK";
+ final String identifier;
+ GenerateSSKMessage(SimpleFieldSet fs) {
+ identifier = fs.get("Identifier");
+ }
+
public SimpleFieldSet getFieldSet() {
return new SimpleFieldSet();
}
@@ -22,7 +27,7 @@
InsertableClientSSK key = InsertableClientSSK.createRandom(node.random);
FreenetURI insertURI = key.getInsertURI();
FreenetURI requestURI = key.getURI();
- SSKKeypairMessage msg = new SSKKeypairMessage(insertURI, requestURI);
+ SSKKeypairMessage msg = new SSKKeypairMessage(insertURI, requestURI,
identifier);
handler.outputHandler.queue(msg);
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/GetFailedMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/GetFailedMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/GetFailedMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -45,7 +45,7 @@
}
public void run(FCPConnectionHandler handler, Node node) throws
MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "FetchError goes
from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "FetchError goes
from server to client not the other way around", identifier);
}
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/IdentifierCollisionMessage.java
===================================================================
---
branches/freenet-freejvms/src/freenet/node/fcp/IdentifierCollisionMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++
branches/freenet-freejvms/src/freenet/node/fcp/IdentifierCollisionMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -23,7 +23,7 @@
public void run(FCPConnectionHandler handler, Node node)
throws MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE,
"IdentifierCollision goes from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE,
"IdentifierCollision goes from server to client not the other way around",
identifier);
}
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/MessageInvalidException.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/MessageInvalidException.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/MessageInvalidException.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -9,9 +9,12 @@
public class MessageInvalidException extends Exception {
int protocolCode;
+ public String ident;
- public MessageInvalidException(int protocolCode, String extra) {
+ public MessageInvalidException(int protocolCode, String extra, String
ident) {
super(extra);
+ this.protocolCode = protocolCode;
+ this.ident = ident;
}
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -5,13 +5,15 @@
import freenet.support.SimpleFieldSet;
/**
- * ProtocolError (some problem parsing the other side's FCP messages)
+ * ProtocolError (some problem parsing the other side's FCP messages, or other
+ * problem not related to Freenet)
*
* ProtocolError
* Code=1
* CodeDescription=ClientHello must be first message
* ExtraDescription=Duh
* Fatal=false // means the connection stays open
+ * [Identifier=<ident> if we managed to parse one]
* EndMessage
*/
public class ProtocolErrorMessage extends FCPMessage {
@@ -25,10 +27,16 @@
static final int INVALID_MESSAGE = 7;
static final int INVALID_FIELD = 8;
static final int FILE_NOT_FOUND = 9;
+ static final int DISK_TARGET_EXISTS = 10;
+ static final int FILENAME_AND_TEMP_FILENAME_MUST_BE_IN_SAME_DIR = 11;
+ static final int COULD_NOT_CREATE_FILE = 12;
+ static final int COULD_NOT_WRITE_FILE = 13;
+ static final int COULD_NOT_RENAME_FILE = 14;
final int code;
final String extra;
final boolean fatal;
+ final String ident;
private String codeDescription() {
switch(code) {
@@ -50,20 +58,33 @@
return "Invalid field value";
case FILE_NOT_FOUND:
return "File not found, not a file or not readable";
+ case DISK_TARGET_EXISTS:
+ return "Disk target exists, refusing to overwrite for
security reasons";
+ case FILENAME_AND_TEMP_FILENAME_MUST_BE_IN_SAME_DIR:
+ return "Filename and temp filename must be in same
directory (so can rename)";
+ case COULD_NOT_CREATE_FILE:
+ return "Could not create file";
+ case COULD_NOT_WRITE_FILE:
+ return "Could not write file";
+ case COULD_NOT_RENAME_FILE:
+ return "Could not rename file";
default:
Logger.error(this, "Unknown error code: "+code, new
Exception("debug"));
return "(Unknown)";
}
}
- public ProtocolErrorMessage(int code, boolean fatal, String extra) {
+ public ProtocolErrorMessage(int code, boolean fatal, String extra,
String ident) {
this.code = code;
this.extra = extra;
this.fatal = fatal;
+ this.ident = ident;
}
public SimpleFieldSet getFieldSet() {
SimpleFieldSet sfs = new SimpleFieldSet();
+ if(ident != null)
+ sfs.put("Identifier", ident);
sfs.put("Code", Integer.toString(code));
sfs.put("CodeDescription", codeDescription());
if(extra != null)
Modified: branches/freenet-freejvms/src/freenet/node/fcp/PutFailedMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/PutFailedMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/PutFailedMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -51,7 +51,7 @@
public void run(FCPConnectionHandler handler, Node node)
throws MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "PutFailed goes
from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "PutFailed goes
from server to client not the other way around", identifier);
}
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/PutSuccessfulMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/PutSuccessfulMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/PutSuccessfulMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -27,7 +27,7 @@
public void run(FCPConnectionHandler handler, Node node)
throws MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "InsertSuccessful
goes from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "InsertSuccessful
goes from server to client not the other way around", identifier);
}
}
Modified: branches/freenet-freejvms/src/freenet/node/fcp/SSKKeypairMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/SSKKeypairMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/SSKKeypairMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -8,16 +8,20 @@
private final FreenetURI insertURI;
private final FreenetURI requestURI;
+ private final String identifier;
- public SSKKeypairMessage(FreenetURI insertURI, FreenetURI requestURI) {
+ public SSKKeypairMessage(FreenetURI insertURI, FreenetURI requestURI,
String identifier) {
this.insertURI = insertURI;
this.requestURI = requestURI;
+ this.identifier = identifier;
}
public SimpleFieldSet getFieldSet() {
SimpleFieldSet sfs = new SimpleFieldSet();
sfs.put("InsertURI", insertURI.toString());
sfs.put("RequestURI", requestURI.toString());
+ if(identifier != null) // is optional on these two only
+ sfs.put("Identifier", identifier);
return sfs;
}
@@ -26,7 +30,7 @@
}
public void run(FCPConnectionHandler handler, Node node) throws
MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "SSKKeypair goes
from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "SSKKeypair goes
from server to client not the other way around", identifier);
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/SimpleProgressMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/SimpleProgressMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/SimpleProgressMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -31,7 +31,7 @@
}
public void run(FCPConnectionHandler handler, Node node) throws
MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "SimpleProgress
goes from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "SimpleProgress
goes from server to client not the other way around", ident);
}
}
Modified:
branches/freenet-freejvms/src/freenet/node/fcp/URIGeneratedMessage.java
===================================================================
--- branches/freenet-freejvms/src/freenet/node/fcp/URIGeneratedMessage.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/node/fcp/URIGeneratedMessage.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -27,7 +27,7 @@
public void run(FCPConnectionHandler handler, Node node)
throws MessageInvalidException {
- throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "URIGenerated
goes from server to client not the other way around");
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "URIGenerated
goes from server to client not the other way around", identifier);
}
}
Modified: branches/freenet-freejvms/src/freenet/support/ArrayBucket.java
===================================================================
--- branches/freenet-freejvms/src/freenet/support/ArrayBucket.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/support/ArrayBucket.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -15,8 +15,7 @@
*/
public class ArrayBucket implements Bucket {
- private ArrayList data;
- private boolean reset;
+ private final ArrayList data;
private String name;
private boolean readOnly;
@@ -36,7 +35,7 @@
public OutputStream getOutputStream() throws IOException {
if(readOnly) throw new IOException("Read only");
- return new ArrayBucketOutputStream(reset);
+ return new ArrayBucketOutputStream();
}
public InputStream getInputStream() {
@@ -53,7 +52,7 @@
}
public void read(InputStream in) throws IOException {
- OutputStream out = new ArrayBucketOutputStream(reset);
+ OutputStream out = new ArrayBucketOutputStream();
int i;
byte[] b = new byte[8 * 1024];
while ((i = in.read(b)) != -1) {
@@ -77,19 +76,11 @@
private class ArrayBucketOutputStream extends ByteArrayOutputStream {
- private boolean reset;
-
- public ArrayBucketOutputStream(boolean reset) {
+ public ArrayBucketOutputStream() {
super();
- this.reset = reset;
}
public void close() throws IOException {
- if (reset) {
- data.clear();
- data.trimToSize();
- }
- reset = false;
data.add(toByteArray());
if(readOnly) throw new IOException("Read only");
// FIXME maybe we should throw on write instead? :)
@@ -171,4 +162,9 @@
public void setReadOnly() {
readOnly = true;
}
+
+ public void free() {
+ data.clear();
+ // Not much else we can do.
+ }
}
Modified: branches/freenet-freejvms/src/freenet/support/Bucket.java
===================================================================
--- branches/freenet-freejvms/src/freenet/support/Bucket.java 2006-02-03
23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/support/Bucket.java 2006-02-03
23:24:42 UTC (rev 8001)
@@ -43,4 +43,9 @@
*/
public void setReadOnly();
+ /**
+ * Free the bucket, if supported.
+ */
+ public void free();
+
}
Modified:
branches/freenet-freejvms/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
===================================================================
---
branches/freenet-freejvms/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
2006-02-03 23:02:41 UTC (rev 8000)
+++
branches/freenet-freejvms/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -234,4 +234,8 @@
return bucket;
}
+ public void free() {
+ bucket.free();
+ }
+
}
Modified:
branches/freenet-freejvms/src/freenet/support/RandomAccessFileBucket.java
===================================================================
--- branches/freenet-freejvms/src/freenet/support/RandomAccessFileBucket.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/support/RandomAccessFileBucket.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -437,4 +437,8 @@
public void setReadOnly() {
readOnly = true;
}
+
+ public void free() {
+ release();
+ }
}
Modified:
branches/freenet-freejvms/src/freenet/support/ReadOnlyFileSliceBucket.java
===================================================================
--- branches/freenet-freejvms/src/freenet/support/ReadOnlyFileSliceBucket.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/support/ReadOnlyFileSliceBucket.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -99,5 +99,9 @@
}
}
+
+ public void free() {
+ // Do nothing
+ }
}
Modified:
branches/freenet-freejvms/src/freenet/support/SimpleReadOnlyArrayBucket.java
===================================================================
---
branches/freenet-freejvms/src/freenet/support/SimpleReadOnlyArrayBucket.java
2006-02-03 23:02:41 UTC (rev 8000)
+++
branches/freenet-freejvms/src/freenet/support/SimpleReadOnlyArrayBucket.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -47,4 +47,8 @@
// Already read-only
}
+ public void free() {
+ // Do nothing
+ }
+
}
Modified: branches/freenet-freejvms/src/freenet/support/io/FileBucket.java
===================================================================
--- branches/freenet-freejvms/src/freenet/support/io/FileBucket.java
2006-02-03 23:02:41 UTC (rev 8000)
+++ branches/freenet-freejvms/src/freenet/support/io/FileBucket.java
2006-02-03 23:24:42 UTC (rev 8001)
@@ -315,4 +315,8 @@
}
return buckets;
}
+
+ public void free() {
+ finalize();
+ }
}