Author: toad
Date: 2006-02-02 19:10:00 +0000 (Thu, 02 Feb 2006)
New Revision: 7993
Modified:
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
trunk/freenet/src/freenet/node/fcp/DataCarryingMessage.java
trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
Log:
429:
Upload from disk via FCP support.
Yes, this applies to /etc/shadow, so don't run Fred as a privelidged user, and
don't open FCP to the world until I have implemented a no-dangerous-ops switch!
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-02 18:22:21 UTC (rev
7992)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-02 19:10:00 UTC (rev
7993)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 428;
+ private static final int buildNumber = 429;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 403;
Modified: trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java 2006-02-02
18:22:21 UTC (rev 7992)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java 2006-02-02
19:10:00 UTC (rev 7993)
@@ -1,22 +1,29 @@
package freenet.node.fcp;
+import java.io.File;
import java.net.MalformedURLException;
import freenet.keys.FreenetURI;
import freenet.node.Node;
import freenet.node.RequestStarter;
import freenet.support.SimpleFieldSet;
+import freenet.support.io.FileBucket;
/**
*
* ClientPut
* URI=CHK@ // could as easily be an insertable SSK URI
* Metadata.ContentType=text/html
- * DataLength=100 // 100kB
* Identifier=Insert-1 // identifier, as always
* Verbosity=0 // just report when complete
* MaxRetries=999999 // lots of retries
* PriorityClass=1 // fproxy priority level
+ *
+ * UploadFrom=direct // attached directly to this message
+ * DataLength=100 // 100kB
+ * or
+ * UploadFrom=disk // upload a file from disk
+ * Filename=/home/toad/something.html
* Data
*
* Neither IgnoreDS nor DSOnly make sense for inserts.
@@ -33,6 +40,7 @@
final int maxRetries;
final boolean getCHKOnly;
final short priorityClass;
+ final boolean fromDisk;
public ClientPutMessage(SimpleFieldSet fs) throws
MessageInvalidException {
try {
@@ -56,14 +64,6 @@
throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Verbosity field: "+e.getMessage());
}
}
- String dataLengthString = fs.get("DataLength");
- if(dataLengthString == null)
- throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Need DataLength on
a ClientPut");
- try {
- dataLength = Long.parseLong(dataLengthString, 10);
- } catch (NumberFormatException e) {
- throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing DataLength field: "+e.getMessage());
- }
contentType = fs.get("Metadata.ContentType");
String maxRetriesString = fs.get("MaxRetries");
if(maxRetriesString == null)
@@ -90,6 +90,29 @@
throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing PriorityClass field: "+e.getMessage());
}
}
+ String uploadFrom = fs.get("UploadFrom");
+ if(uploadFrom != null && uploadFrom.equalsIgnoreCase("disk")) {
+ fromDisk = true;
+ String filename = fs.get("Filename");
+ if(filename == null)
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Missing field
Filename");
+ File f = new File(filename);
+ if(!(f.exists() && f.isFile() && f.canRead()))
+ throw new
MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, null);
+ dataLength = f.length();
+ FileBucket fileBucket = new FileBucket(f, true, false,
false);
+ this.bucket = fileBucket;
+ } else {
+ fromDisk = false;
+ String dataLengthString = fs.get("DataLength");
+ if(dataLengthString == null)
+ throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Need DataLength on
a ClientPut");
+ try {
+ dataLength = Long.parseLong(dataLengthString,
10);
+ } catch (NumberFormatException e) {
+ throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing DataLength field: "+e.getMessage());
+ }
+ }
}
public SimpleFieldSet getFieldSet() {
@@ -113,6 +136,7 @@
}
long dataLength() {
+ if(fromDisk) return 0;
return dataLength;
}
Modified: trunk/freenet/src/freenet/node/fcp/DataCarryingMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/DataCarryingMessage.java 2006-02-02
18:22:21 UTC (rev 7992)
+++ trunk/freenet/src/freenet/node/fcp/DataCarryingMessage.java 2006-02-02
19:10:00 UTC (rev 7993)
@@ -19,6 +19,7 @@
long len = dataLength();
if(len < 0)
throw new IllegalArgumentException("Invalid length:
"+len);
+ if(len == 0) return;
Bucket bucket = bf.makeBucket(len);
BucketTools.copyFrom(bucket, is, len);
this.bucket = bucket;
Modified: trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-02-02 18:22:21 UTC (rev 7992)
+++ trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-02-02 19:10:00 UTC (rev 7993)
@@ -24,6 +24,7 @@
static final int ERROR_PARSING_NUMBER = 6;
static final int INVALID_MESSAGE = 7;
static final int INVALID_FIELD = 8;
+ static final int FILE_NOT_FOUND = 9;
final int code;
final String extra;
@@ -47,6 +48,8 @@
return "Don't know what to do with message";
case INVALID_FIELD:
return "Invalid field value";
+ case FILE_NOT_FOUND:
+ return "File not found, not a file or not readable";
default:
Logger.error(this, "Unknown error code: "+code, new
Exception("debug"));
return "(Unknown)";