Author: toad
Date: 2006-03-03 16:48:24 +0000 (Fri, 03 Mar 2006)
New Revision: 8144
Modified:
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/node/fcp/ClientGet.java
trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java
trunk/freenet/src/freenet/node/fcp/DataFoundMessage.java
trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java
trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
trunk/freenet/src/freenet/node/fcp/PutFailedMessage.java
Log:
483:
Persist completion state on get's as well.
It is now illegal to do ClientGet { Persistence=forever, ReturnType!=disk }.
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-03-03 16:00:53 UTC (rev
8143)
+++ trunk/freenet/src/freenet/node/Version.java 2006-03-03 16:48:24 UTC (rev
8144)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 482;
+ private static final int buildNumber = 483;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 475;
Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java 2006-03-03 16:00:53 UTC
(rev 8143)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java 2006-03-03 16:48:24 UTC
(rev 8144)
@@ -51,8 +51,21 @@
private int VERBOSITY_SPLITFILE_PROGRESS = 1;
// Stuff waiting for reconnection
- private FCPMessage dataFoundOrGetFailedPending;
+ /** Did the request succeed? Valid if finished. */
+ private boolean succeeded;
+ /** Length of the found data */
+ private long foundDataLength;
+ /** MIME type of the found data */
+ private String foundDataMimeType;
+ /** Details of request failure */
+ private GetFailedMessage getFailedMessage;
+ /** Succeeded but failed to return data e.g. couldn't write to file */
+ private ProtocolErrorMessage postFetchProtocolErrorMessage;
+ /** AllData (the actual direct-send data) - do not persist, because the
bucket
+ * is not persistent. FIXME make the bucket persistent! */
private AllDataMessage allDataPending;
+ /** Last progress message. Not persistent - FIXME this will be made
persistent
+ * when we have proper persistence at the ClientGetter level. */
private SimpleProgressMessage progressPending;
public ClientGet(FCPConnectionHandler handler, ClientGetMessage
message) {
@@ -128,6 +141,19 @@
fctx.ignoreStore = ignoreDS;
fctx.maxNonSplitfileRetries = maxRetries;
fctx.maxSplitfileBlockRetries = maxRetries;
+ succeeded = Fields.stringToBool(fs.get("Succeeded"), false);
+ if(finished) {
+ if(succeeded) {
+ foundDataLength =
Long.parseLong(fs.get("FoundDataLength"));
+ foundDataMimeType = fs.get("FoundDataMimeType");
+ SimpleFieldSet fs1 =
fs.subset("PostFetchProtocolError");
+ if(fs1 != null)
+ postFetchProtocolErrorMessage = new
ProtocolErrorMessage(fs1);
+ } else {
+ getFailedMessage = new
GetFailedMessage(fs.subset("GetFailed"), false);
+ }
+ }
+
getter = new ClientGetter(this, client.node.fetchScheduler,
uri, fctx, priorityClass, client);
start();
}
@@ -152,13 +178,16 @@
public void onSuccess(FetchResult result, ClientGetter state) {
progressPending = null;
- finished = true;
FCPMessage msg = new DataFoundMessage(result, identifier);
Bucket data = result.asBucket();
+ this.foundDataLength = data.size();
+ this.foundDataMimeType = result.getMimeType();
+ this.succeeded = true;
+ finished = true;
if(returnType == ClientGetMessage.RETURN_TYPE_DIRECT) {
// Send all the data at once
// FIXME there should be other options
- trySendDataFoundOrGetFailed(msg);
+ trySendDataFoundOrGetFailed();
AllDataMessage m = new AllDataMessage(data, identifier);
if(persistenceType == PERSIST_CONNECTION)
m.setFreeOnSent();
@@ -167,7 +196,7 @@
return;
} else if(returnType == ClientGetMessage.RETURN_TYPE_NONE) {
// Do nothing
- trySendDataFoundOrGetFailed(msg);
+ trySendDataFoundOrGetFailed();
data.free();
finish();
return;
@@ -177,8 +206,8 @@
try {
fos = new FileOutputStream(tempFile);
} catch (FileNotFoundException e) {
- ProtocolErrorMessage pm = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null,
identifier);
- trySendDataFoundOrGetFailed(pm);
+ postFetchProtocolErrorMessage = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null,
identifier);
+ trySendDataFoundOrGetFailed();
data.free();
finish();
return;
@@ -186,8 +215,8 @@
try {
BucketTools.copyTo(data, fos, data.size());
} catch (IOException e) {
- ProtocolErrorMessage pm = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null,
identifier);
- trySendDataFoundOrGetFailed(pm);
+ postFetchProtocolErrorMessage = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null,
identifier);
+ trySendDataFoundOrGetFailed();
data.free();
try {
fos.close();
@@ -203,21 +232,29 @@
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);
- trySendDataFoundOrGetFailed(pm);
+ postFetchProtocolErrorMessage = new
ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_RENAME_FILE, false, null,
identifier);
+ trySendDataFoundOrGetFailed();
// Don't delete temp file, user might want it.
}
data.free();
- trySendDataFoundOrGetFailed(msg);
+ trySendDataFoundOrGetFailed();
finish();
return;
}
}
- private void trySendDataFoundOrGetFailed(FCPMessage msg) {
- if(persistenceType != ClientRequest.PERSIST_CONNECTION) {
- dataFoundOrGetFailedPending = msg;
+ private void trySendDataFoundOrGetFailed() {
+
+ FCPMessage msg;
+
+ if(postFetchProtocolErrorMessage != null) {
+ msg = postFetchProtocolErrorMessage;
+ } else if(succeeded) {
+ msg = new DataFoundMessage(foundDataLength,
foundDataMimeType, identifier);
+ } else {
+ msg = getFailedMessage;
}
+
FCPConnectionHandler conn = client.getConnection();
if(conn != null)
conn.outputHandler.queue(msg);
@@ -252,17 +289,18 @@
}
if(progressPending != null)
handler.queue(progressPending);
- if(dataFoundOrGetFailedPending != null)
- handler.queue(dataFoundOrGetFailedPending);
+ if(finished)
+ trySendDataFoundOrGetFailed();
if(allDataPending != null)
handler.queue(allDataPending);
}
public void onFailure(FetchException e, ClientGetter state) {
+ succeeded = false;
+ getFailedMessage = new GetFailedMessage(e, identifier);
finished = true;
Logger.minor(this, "Caught "+e, e);
- FCPMessage msg = new GetFailedMessage(e, identifier);
- trySendDataFoundOrGetFailed(msg);
+ trySendDataFoundOrGetFailed();
finish();
}
@@ -347,6 +385,21 @@
fs.put("IgnoreDS", Boolean.toString(fctx.ignoreStore));
fs.put("DSOnly", Boolean.toString(fctx.localRequestOnly));
fs.put("MaxRetries",
Integer.toString(fctx.maxNonSplitfileRetries));
+ fs.put("Finished", Boolean.toString(finished));
+ fs.put("Succeeded", Boolean.toString(succeeded));
+ if(finished) {
+ if(succeeded) {
+ fs.put("FoundDataLength",
Long.toString(foundDataLength));
+ fs.put("FoundDataMimeType", foundDataMimeType);
+ if(postFetchProtocolErrorMessage != null) {
+ fs.put("PostFetchProtocolError",
postFetchProtocolErrorMessage.getFieldSet());
+ }
+ } else {
+ if(getFailedMessage != null) {
+ fs.put("GetFailed",
getFailedMessage.getFieldSet(false));
+ }
+ }
+ }
return fs;
}
Modified: trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java 2006-03-03
16:00:53 UTC (rev 8143)
+++ trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java 2006-03-03
16:48:24 UTC (rev 8144)
@@ -171,6 +171,10 @@
} else if(persistenceString.equalsIgnoreCase("forever")) {
// Same as reboot but saved to disk, persists forever.
persistenceType = ClientRequest.PERSIST_FOREVER;
+ // FIXME for now we only support returntype=disk if
persistenceType=forever.
+ if(returnType != RETURN_TYPE_DISK) {
+ throw new
MessageInvalidException(ProtocolErrorMessage.NOT_SUPPORTED,
"PersistenceType=forever implies ReturnType=disk", identifier);
+ }
} else {
throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Persistence field: "+persistenceString, identifier);
}
Modified: trunk/freenet/src/freenet/node/fcp/DataFoundMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/DataFoundMessage.java 2006-03-03
16:00:53 UTC (rev 8143)
+++ trunk/freenet/src/freenet/node/fcp/DataFoundMessage.java 2006-03-03
16:48:24 UTC (rev 8144)
@@ -16,6 +16,12 @@
this.dataLength = fr.size();
}
+ public DataFoundMessage(long foundDataLength, String foundDataMimeType,
String identifier2) {
+ this.mimeType = foundDataMimeType;
+ this.identifier = identifier2;
+ this.dataLength = foundDataLength;
+ }
+
public SimpleFieldSet getFieldSet() {
SimpleFieldSet fs = new SimpleFieldSet(false);
fs.put("Identifier", identifier);
Modified: trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java 2006-03-03
16:00:53 UTC (rev 8143)
+++ trunk/freenet/src/freenet/node/fcp/GetFailedMessage.java 2006-03-03
16:48:24 UTC (rev 8144)
@@ -1,8 +1,12 @@
package freenet.node.fcp;
+import java.net.MalformedURLException;
+
import freenet.client.FailureCodeTracker;
import freenet.client.FetchException;
+import freenet.client.InserterException;
import freenet.node.Node;
+import freenet.support.Fields;
import freenet.support.SimpleFieldSet;
public class GetFailedMessage extends FCPMessage {
@@ -25,6 +29,38 @@
this.identifier = identifier;
}
+ /**
+ * Construct from a fieldset. Used in serialization of persistent
requests.
+ * Will need to be made more tolerant of syntax errors if is used in an
FCP
+ * client library. FIXME.
+ * @param useVerboseFields If true, read in verbose fields
(CodeDescription
+ * etc), if false, reconstruct them from the error code.
+ * @throws MalformedURLException
+ */
+ public GetFailedMessage(SimpleFieldSet fs, boolean useVerboseFields) {
+ identifier = fs.get("Identifier");
+ if(identifier == null) throw new NullPointerException();
+ code = Integer.parseInt(fs.get("Code"));
+
+ if(useVerboseFields) {
+ codeDescription = fs.get("CodeDescription");
+ isFatal = Fields.stringToBool(fs.get("Fatal"), false);
+ shortCodeDescription = fs.get("ShortCodeDescription");
+ } else {
+ codeDescription = FetchException.getMessage(code);
+ isFatal = FetchException.isFatal(code);
+ shortCodeDescription =
FetchException.getShortMessage(code);
+ }
+
+ extraDescription = fs.get("ExtraDescription");
+ SimpleFieldSet trackerSubset = fs.subset("Errors");
+ if(trackerSubset != null) {
+ tracker = new FailureCodeTracker(true, trackerSubset);
+ } else {
+ tracker = null;
+ }
+ }
+
public SimpleFieldSet getFieldSet() {
return getFieldSet(true);
}
Modified: trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-03-03 16:00:53 UTC (rev 8143)
+++ trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-03-03 16:48:24 UTC (rev 8144)
@@ -1,6 +1,7 @@
package freenet.node.fcp;
import freenet.node.Node;
+import freenet.support.Fields;
import freenet.support.Logger;
import freenet.support.SimpleFieldSet;
@@ -87,6 +88,13 @@
this.ident = ident;
}
+ public ProtocolErrorMessage(SimpleFieldSet fs) {
+ ident = fs.get("Identifier");
+ code = Integer.parseInt(fs.get("Code"));
+ extra = fs.get("ExtraDescription");
+ fatal = Fields.stringToBool(fs.get("Fatal"), false);
+ }
+
public SimpleFieldSet getFieldSet() {
SimpleFieldSet sfs = new SimpleFieldSet(false);
if(ident != null)
Modified: trunk/freenet/src/freenet/node/fcp/PutFailedMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/PutFailedMessage.java 2006-03-03
16:00:53 UTC (rev 8143)
+++ trunk/freenet/src/freenet/node/fcp/PutFailedMessage.java 2006-03-03
16:48:24 UTC (rev 8144)
@@ -14,7 +14,7 @@
final int code;
final String codeDescription;
final String extraDescription;
- final String codeShortDescription;
+ final String shortCodeDescription;
final FailureCodeTracker tracker;
final FreenetURI expectedURI;
final String identifier;
@@ -23,7 +23,7 @@
public PutFailedMessage(InserterException e, String identifier) {
this.code = e.getMode();
this.codeDescription = InserterException.getMessage(code);
- this.codeShortDescription =
InserterException.getShortMessage(code);
+ this.shortCodeDescription =
InserterException.getShortMessage(code);
this.extraDescription = e.extra;
this.tracker = e.errorCodes;
this.expectedURI = e.uri;
@@ -47,11 +47,11 @@
if(useVerboseFields) {
codeDescription = fs.get("CodeDescription");
isFatal = Fields.stringToBool(fs.get("Fatal"), false);
- codeShortDescription = fs.get("ShortCodeDescription");
+ shortCodeDescription = fs.get("ShortCodeDescription");
} else {
codeDescription = InserterException.getMessage(code);
isFatal = InserterException.isFatal(code);
- codeShortDescription =
InserterException.getShortMessage(code);
+ shortCodeDescription =
InserterException.getShortMessage(code);
}
extraDescription = fs.get("ExtraDescription");
@@ -83,7 +83,7 @@
if(verbose)
fs.put("Fatal", Boolean.toString(isFatal));
if(verbose)
- fs.put("ShortCodeDescription", codeShortDescription);
+ fs.put("ShortCodeDescription", shortCodeDescription);
if(expectedURI != null)
fs.put("ExpectedURI", expectedURI.toString());
return fs;