Author: toad
Date: 2005-11-09 21:59:52 +0000 (Wed, 09 Nov 2005)
New Revision: 7506
Modified:
trunk/freenet/src/freenet/client/FetchException.java
trunk/freenet/src/freenet/client/Fetcher.java
trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
trunk/freenet/src/freenet/client/InserterException.java
trunk/freenet/src/freenet/keys/ClientKey.java
trunk/freenet/src/freenet/node/LowLevelGetException.java
trunk/freenet/src/freenet/node/LowLevelPutException.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/TextModeClientInterface.java
trunk/freenet/src/freenet/node/Version.java
Log:
148:
Bugs, bugs, glorious bugs...
Modified: trunk/freenet/src/freenet/client/FetchException.java
===================================================================
--- trunk/freenet/src/freenet/client/FetchException.java 2005-11-09
20:58:30 UTC (rev 7505)
+++ trunk/freenet/src/freenet/client/FetchException.java 2005-11-09
21:59:52 UTC (rev 7506)
@@ -18,29 +18,87 @@
}
public FetchException(int m) {
+ super(getMessage(m));
mode = m;
}
public FetchException(MetadataParseException e) {
+ super(getMessage(INVALID_METADATA)+": "+e.getMessage());
mode = INVALID_METADATA;
initCause(e);
}
public FetchException(ArchiveFailureException e) {
+ super(getMessage(INVALID_METADATA)+": "+e.getMessage());
mode = ARCHIVE_FAILURE;
initCause(e);
}
public FetchException(int mode, IOException e) {
+ super(getMessage(INVALID_METADATA)+": "+e.getMessage());
this.mode = mode;
initCause(e);
}
+ public FetchException(int mode, String msg) {
+ super(getMessage(mode)+": "+msg);
+ this.mode = mode;
+ }
+
+ private static String getMessage(int mode) {
+ switch(mode) {
+ case TOO_DEEP_ARCHIVE_RECURSION:
+ return "Too many levels of recursion into archives";
+ case UNKNOWN_SPLITFILE_METADATA:
+ return "Don't know what to do with splitfile";
+ case TOO_MANY_REDIRECTS:
+ return "Too many redirects - loop?";
+ case UNKNOWN_METADATA:
+ return "Don't know what to do with metadata";
+ case INVALID_METADATA:
+ return "Failed to parse metadata";
+ case ARCHIVE_FAILURE:
+ return "Failure in extracting files from an archive";
+ case BLOCK_DECODE_ERROR:
+ return "Failed to decode a splitfile block";
+ case TOO_MANY_METADATA_LEVELS:
+ return "Too many levels of split metadata";
+ case TOO_MANY_ARCHIVE_RESTARTS:
+ return "Request was restarted too many times due to
archives changing";
+ case TOO_MUCH_RECURSION:
+ return "Too many redirects"; // FIXME: ???
+ case NOT_IN_ARCHIVE:
+ return "File not in archive";
+ case HAS_MORE_METASTRINGS:
+ return "Not a manifest";
+ case BUCKET_ERROR:
+ return "Internal error, maybe disk full or permissions
problem?";
+ case DATA_NOT_FOUND:
+ return "Data not found";
+ case ROUTE_NOT_FOUND:
+ return "Route not found - could not find enough nodes
to be sure the data doesn't exist";
+ case REJECTED_OVERLOAD:
+ return "A node was overloaded or timed out";
+ case INTERNAL_ERROR:
+ return "Internal error, probably a bug";
+ case TRANSFER_FAILED:
+ return "Found the file, but lost it while receiving the
data";
+ case SPLITFILE_ERROR:
+ return "Splitfile error";
+ case INVALID_URI:
+ return "Invalid URI";
+ default:
+ return "Unknown fetch error code: "+mode;
+ }
+ }
+
+ // FIXME many of these are not used any more
+
/** Too many levels of recursion into archives */
public static final int TOO_DEEP_ARCHIVE_RECURSION = 1;
/** Don't know what to do with splitfile */
public static final int UNKNOWN_SPLITFILE_METADATA = 2;
- /** Too many ordinary redirects */
+ /** Too many redirects */
public static final int TOO_MANY_REDIRECTS = 16;
/** Don't know what to do with metadata */
public static final int UNKNOWN_METADATA = 3;
@@ -74,4 +132,6 @@
public static final int TRANSFER_FAILED = 18;
/** Splitfile error. This should be a SplitFetchException. */
public static final int SPLITFILE_ERROR = 19;
+ /** Invalid URI. */
+ public static final int INVALID_URI = 20;
}
Modified: trunk/freenet/src/freenet/client/Fetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/Fetcher.java 2005-11-09 20:58:30 UTC
(rev 7505)
+++ trunk/freenet/src/freenet/client/Fetcher.java 2005-11-09 21:59:52 UTC
(rev 7506)
@@ -1,6 +1,7 @@
package freenet.client;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.LinkedList;
import freenet.keys.ClientKey;
@@ -32,6 +33,7 @@
* Local-only constructor, with ArchiveContext, for recursion via e.g.
archives.
*/
Fetcher(FreenetURI uri, FetcherContext fctx, ArchiveContext actx) {
+ if(uri == null) throw new NullPointerException();
origURI = uri;
ctx = fctx;
archiveContext = actx;
@@ -87,7 +89,12 @@
*/
FetchResult realRun(ClientMetadata dm, int recursionLevel, FreenetURI
uri, boolean dontEnterImplicitArchives)
throws FetchException, MetadataParseException, ArchiveFailureException,
ArchiveRestartException {
- ClientKey key = ClientKey.getBaseKey(uri);
+ ClientKey key;
+ try {
+ key = ClientKey.getBaseKey(uri);
+ } catch (MalformedURLException e2) {
+ throw new FetchException(FetchException.INVALID_URI,
"Invalid URI: "+uri);
+ }
LinkedList metaStrings = uri.listMetaStrings();
recursionLevel++;
@@ -226,7 +233,12 @@
FreenetURI uri = metadata.getSingleTarget();
dm.mergeNoOverwrite(metadata.getClientMetadata());
if((!dontEnterImplicitArchives) &&
ArchiveManager.isUsableArchiveType(dm.getMIMEType()) &&
(!metaStrings.isEmpty())) {
- ClientKey target = ClientKey.getBaseKey(uri);
+ ClientKey target;
+ try {
+ target = ClientKey.getBaseKey(uri);
+ } catch (MalformedURLException e1) {
+ throw new
FetchException(FetchException.INVALID_URI, "Invalid URI: "+uri);
+ }
if(!(target.isMetadata())) {
// Target *is not* metadata.
// Therefore target is a usable archive.
Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2005-11-09 20:58:30 UTC (rev 7505)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2005-11-09 21:59:52 UTC (rev 7506)
@@ -56,6 +56,7 @@
* Fetch a key. Either returns the data, or throws an exception.
*/
public FetchResult fetch(FreenetURI uri) throws FetchException {
+ if(uri == null) throw new NullPointerException();
FetcherContext context = new FetcherContext(client,
curMaxLength, curMaxTempLength,
MAX_RECURSION, MAX_ARCHIVE_RESTARTS,
DONT_ENTER_IMPLICIT_ARCHIVES,
SPLITFILE_THREADS, SPLITFILE_BLOCK_RETRIES,
NON_SPLITFILE_RETRIES,
Modified: trunk/freenet/src/freenet/client/InserterException.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterException.java 2005-11-09
20:58:30 UTC (rev 7505)
+++ trunk/freenet/src/freenet/client/InserterException.java 2005-11-09
21:59:52 UTC (rev 7506)
@@ -15,17 +15,20 @@
}
public InserterException(int m) {
+ super(getMessage(m));
mode = m;
errorCodes = null;
}
public InserterException(int mode, IOException e) {
+ super(getMessage(mode)+": "+e.getMessage());
this.mode = mode;
errorCodes = null;
initCause(e);
}
public InserterException(int mode, FailureCodeTracker errorCodes) {
+ super(getMessage(mode));
this.mode = mode;
this.errorCodes = errorCodes;
}
@@ -44,4 +47,23 @@
public static final int FATAL_ERRORS_IN_BLOCKS = 6;
/** Could not insert a splitfile because a block failed too many times
*/
public static final int TOO_MANY_RETRIES_IN_BLOCKS = 7;
+
+ private static String getMessage(int mode) {
+ switch(mode) {
+ case INVALID_URI:
+ return "Caller supplied a URI we cannot use";
+ case BUCKET_ERROR:
+ return "Internal bucket error: out of disk
space/permissions problem?";
+ case INTERNAL_ERROR:
+ return "Internal error";
+ case REJECTED_OVERLOAD:
+ return "A downstream node timed out or was severely
overloaded";
+ case FATAL_ERRORS_IN_BLOCKS:
+ return "Fatal errors in a splitfile insert";
+ case TOO_MANY_RETRIES_IN_BLOCKS:
+ return "Could not insert splitfile: ran out of retries
(nonfatal errors)";
+ default:
+ return "Unknown error "+mode;
+ }
+ }
}
Modified: trunk/freenet/src/freenet/keys/ClientKey.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientKey.java 2005-11-09 20:58:30 UTC
(rev 7505)
+++ trunk/freenet/src/freenet/keys/ClientKey.java 2005-11-09 21:59:52 UTC
(rev 7506)
@@ -1,14 +1,17 @@
package freenet.keys;
+import java.net.MalformedURLException;
+
/**
* Base class for client keys.
* Client keys are decodable. Node keys are not.
*/
public abstract class ClientKey {
- public static ClientKey getBaseKey(FreenetURI origURI) {
- // TODO Auto-generated method stub
- return null;
+ public static ClientKey getBaseKey(FreenetURI origURI) throws
MalformedURLException {
+ if(origURI.getKeyType().equals("CHK"))
+ return new ClientCHK(origURI);
+ throw new UnsupportedOperationException();
}
/**
Modified: trunk/freenet/src/freenet/node/LowLevelGetException.java
===================================================================
--- trunk/freenet/src/freenet/node/LowLevelGetException.java 2005-11-09
20:58:30 UTC (rev 7505)
+++ trunk/freenet/src/freenet/node/LowLevelGetException.java 2005-11-09
21:59:52 UTC (rev 7506)
@@ -25,11 +25,26 @@
public static final int VERIFY_FAILED = 8;
static final String getMessage(int reason) {
- if(reason == DECODE_FAILED)
+ switch(reason) {
+ case DECODE_FAILED:
return "Decode of data failed, probably was bogus at
source";
- else if(reason == DATA_NOT_FOUND_IN_STORE)
+ case DATA_NOT_FOUND_IN_STORE:
return "Data was not in store and request was
local-only";
- return "Unknown error code: "+reason;
+ case INTERNAL_ERROR:
+ return "Internal error - probably a bug";
+ case DATA_NOT_FOUND:
+ return "Could not find the data";
+ case ROUTE_NOT_FOUND:
+ return "Could not find enough nodes to be sure that the
data is not out there somewhere";
+ case REJECTED_OVERLOAD:
+ return "A node downstream either timed out or was
overloaded (retry)";
+ case TRANSFER_FAILED:
+ return "Started to transfer data, then failed (should
be rare)";
+ case VERIFY_FAILED:
+ return "Node sent us invalid data";
+ default:
+ return "Unknown error code: "+reason;
+ }
}
/** Failure code */
Modified: trunk/freenet/src/freenet/node/LowLevelPutException.java
===================================================================
--- trunk/freenet/src/freenet/node/LowLevelPutException.java 2005-11-09
20:58:30 UTC (rev 7505)
+++ trunk/freenet/src/freenet/node/LowLevelPutException.java 2005-11-09
21:59:52 UTC (rev 7506)
@@ -3,18 +3,28 @@
public class LowLevelPutException extends Exception {
/** An internal error occurred */
- public static final int INTERNAL_ERROR = 3;
+ public static final int INTERNAL_ERROR = 1;
/** The request could not go enough hops to store the data properly. */
- public static final int ROUTE_NOT_FOUND = 5;
+ public static final int ROUTE_NOT_FOUND = 2;
/** A downstream node is overloaded, and rejected the insert. We should
* reduce our rate of sending inserts. */
- public static final int REJECTED_OVERLOAD = 6;
+ public static final int REJECTED_OVERLOAD = 3;
/** Failure code */
public final int code;
static final String getMessage(int reason) {
- return "Unknown error code: "+reason;
+ switch(reason) {
+ case INTERNAL_ERROR:
+ return "Internal error - probably a bug";
+ case ROUTE_NOT_FOUND:
+ return "Could not store the data on enough nodes";
+ case REJECTED_OVERLOAD:
+ return "A node downstream either timed out or was
overloaded (retry)";
+ default:
+ return "Unknown error code: "+reason;
+ }
+
}
LowLevelPutException(int code, String message, Throwable t) {
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2005-11-09 20:58:30 UTC (rev
7505)
+++ trunk/freenet/src/freenet/node/Node.java 2005-11-09 21:59:52 UTC (rev
7506)
@@ -321,7 +321,8 @@
localStreamContexts = new Hashtable();
peers.writePeers();
try {
- tempFilenameGenerator = new FilenameGenerator(random,
true, new File("temp"), "temp-");
+ String dirName = "temp-"+portNumber;
+ tempFilenameGenerator = new FilenameGenerator(random,
true, new File(dirName), "temp-");
} catch (IOException e) {
Logger.error(this, "Could not create temp bucket
factory: "+e, e);
System.exit(EXIT_TEMP_INIT_ERROR);
@@ -342,7 +343,7 @@
if(key instanceof ClientCHK)
return getCHK((ClientCHK)key, localOnly);
else
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Not a CHK: "+key);
}
/**
@@ -769,6 +770,6 @@
}
public HighLevelSimpleClient makeClient() {
- return new HighLevelSimpleClientImpl(this, archiveManager,
null, random);
+ return new HighLevelSimpleClientImpl(this, archiveManager,
tempBucketFactory, random);
}
}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-09
20:58:30 UTC (rev 7505)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-09
21:59:52 UTC (rev 7506)
@@ -114,6 +114,7 @@
FreenetURI uri;
try {
uri = new FreenetURI(key);
+ Logger.normal(this, "Key: "+uri);
} catch (MalformedURLException e2) {
System.out.println("Malformed URI: "+key+" : "+e2);
return;
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-11-09 20:58:30 UTC (rev
7505)
+++ trunk/freenet/src/freenet/node/Version.java 2005-11-09 21:59:52 UTC (rev
7506)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 147;
+ public static final int buildNumber = 148;
/** Oldest build of Fred we will talk to */
public static final int lastGoodBuild = 144;