Author: toad
Date: 2005-11-07 20:17:23 +0000 (Mon, 07 Nov 2005)
New Revision: 7494
Added:
trunk/freenet/src/freenet/node/LowLevelGetException.java
trunk/freenet/src/freenet/node/LowLevelPutException.java
Modified:
trunk/freenet/src/freenet/client/FetchException.java
trunk/freenet/src/freenet/client/Fetcher.java
trunk/freenet/src/freenet/client/Segment.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/SimpleLowLevelClient.java
trunk/freenet/src/freenet/node/TextModeClientInterface.java
trunk/freenet/src/freenet/node/Version.java
Log:
143:
SimpleLowLevelClient now throws rather than returning null or returning
silently (in the case of inserts).
Modified: trunk/freenet/src/freenet/client/FetchException.java
===================================================================
--- trunk/freenet/src/freenet/client/FetchException.java 2005-11-07
19:06:46 UTC (rev 7493)
+++ trunk/freenet/src/freenet/client/FetchException.java 2005-11-07
20:17:23 UTC (rev 7494)
@@ -68,4 +68,8 @@
public static final int ROUTE_NOT_FOUND = 14;
/** Downstream overload */
public static final int REJECTED_OVERLOAD = 15;
+ /** An internal error occurred */
+ public static final int INTERNAL_ERROR = 17;
+ /** The node found the data but the transfer failed */
+ public static final int TRANSFER_FAILED = 18;
}
Modified: trunk/freenet/src/freenet/client/Fetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/Fetcher.java 2005-11-07 19:06:46 UTC
(rev 7493)
+++ trunk/freenet/src/freenet/client/Fetcher.java 2005-11-07 20:17:23 UTC
(rev 7494)
@@ -7,6 +7,7 @@
import freenet.keys.FreenetURI;
import freenet.keys.KeyBlock;
import freenet.keys.KeyDecodeException;
+import freenet.node.LowLevelGetException;
import freenet.support.Bucket;
import freenet.support.BucketTools;
import freenet.support.Logger;
@@ -93,7 +94,32 @@
throw new
FetchException(FetchException.TOO_MUCH_RECURSION);
// Do the fetch
- KeyBlock block = ctx.client.getKey(key, ctx.localRequestOnly);
+ KeyBlock block;
+ try {
+ block = ctx.client.getKey(key, ctx.localRequestOnly);
+ } catch (LowLevelGetException e) {
+ switch(e.code) {
+ case LowLevelGetException.DATA_NOT_FOUND:
+ throw new
FetchException(FetchException.DATA_NOT_FOUND);
+ case LowLevelGetException.DATA_NOT_FOUND_IN_STORE:
+ throw new
FetchException(FetchException.DATA_NOT_FOUND);
+ case LowLevelGetException.DECODE_FAILED:
+ throw new
FetchException(FetchException.BLOCK_DECODE_ERROR);
+ case LowLevelGetException.INTERNAL_ERROR:
+ throw new
FetchException(FetchException.INTERNAL_ERROR);
+ case LowLevelGetException.REJECTED_OVERLOAD:
+ throw new
FetchException(FetchException.REJECTED_OVERLOAD);
+ case LowLevelGetException.ROUTE_NOT_FOUND:
+ throw new
FetchException(FetchException.ROUTE_NOT_FOUND);
+ case LowLevelGetException.TRANSFER_FAILED:
+ throw new
FetchException(FetchException.TRANSFER_FAILED);
+ case LowLevelGetException.VERIFY_FAILED:
+ throw new
FetchException(FetchException.BLOCK_DECODE_ERROR);
+ default:
+ Logger.error(this, "Unknown
LowLevelGetException code: "+e.code);
+ throw new
FetchException(FetchException.INTERNAL_ERROR);
+ }
+ }
byte[] data;
try {
Modified: trunk/freenet/src/freenet/client/Segment.java
===================================================================
--- trunk/freenet/src/freenet/client/Segment.java 2005-11-07 19:06:46 UTC
(rev 7493)
+++ trunk/freenet/src/freenet/client/Segment.java 2005-11-07 20:17:23 UTC
(rev 7494)
@@ -88,10 +88,12 @@
case FetchException.DATA_NOT_FOUND:
case FetchException.ROUTE_NOT_FOUND:
case FetchException.REJECTED_OVERLOAD:
+ case FetchException.TRANSFER_FAILED:
// Non-fatal
nonfatalError(e);
case FetchException.BUCKET_ERROR:
+ case FetchException.INTERNAL_ERROR:
// Maybe fatal
nonfatalError(e);
}
Added: trunk/freenet/src/freenet/node/LowLevelGetException.java
===================================================================
--- trunk/freenet/src/freenet/node/LowLevelGetException.java 2005-11-07
19:06:46 UTC (rev 7493)
+++ trunk/freenet/src/freenet/node/LowLevelGetException.java 2005-11-07
20:17:23 UTC (rev 7494)
@@ -0,0 +1,48 @@
+package freenet.node;
+
+public class LowLevelGetException extends Exception {
+
+ /** Decode of data failed, probably was bogus at source */
+ public static final int DECODE_FAILED = 1;
+ /** Data was not in store and request was local-only */
+ public static final int DATA_NOT_FOUND_IN_STORE = 2;
+ /** An internal error occurred */
+ public static final int INTERNAL_ERROR = 3;
+ /** The request went to many hops, but could not find the data. Maybe
+ * it doesn't exist. */
+ public static final int DATA_NOT_FOUND = 4;
+ /** The request could not find enough nodes to visit while looking for
+ * the datum. */
+ public static final int ROUTE_NOT_FOUND = 5;
+ /** A downstream node is overloaded, and rejected the request. We should
+ * reduce our rate of sending requests.
+ */
+ public static final int REJECTED_OVERLOAD = 6;
+ /** Transfer of data started, but then failed. */
+ public static final int TRANSFER_FAILED = 7;
+ /** Data successfully transferred, but was not valid (at the node key
level
+ * i.e. before decode) */
+ public static final int VERIFY_FAILED = 8;
+
+ static final String getMessage(int reason) {
+ if(reason == DECODE_FAILED)
+ return "Decode of data failed, probably was bogus at
source";
+ else if(reason == DATA_NOT_FOUND_IN_STORE)
+ return "Data was not in store and request was
local-only";
+ return "Unknown error code: "+reason;
+ }
+
+ /** Failure code */
+ public final int code;
+
+ LowLevelGetException(int code, String message, Throwable t) {
+ super(message, t);
+ this.code = code;
+ }
+
+ LowLevelGetException(int reason) {
+ super(getMessage(reason));
+ this.code = reason;
+ }
+
+}
Added: trunk/freenet/src/freenet/node/LowLevelPutException.java
===================================================================
--- trunk/freenet/src/freenet/node/LowLevelPutException.java 2005-11-07
19:06:46 UTC (rev 7493)
+++ trunk/freenet/src/freenet/node/LowLevelPutException.java 2005-11-07
20:17:23 UTC (rev 7494)
@@ -0,0 +1,30 @@
+package freenet.node;
+
+public class LowLevelPutException extends Exception {
+
+ /** An internal error occurred */
+ public static final int INTERNAL_ERROR = 3;
+ /** The request could not go enough hops to store the data properly. */
+ public static final int ROUTE_NOT_FOUND = 5;
+ /** A downstream node is overloaded, and rejected the insert. We should
+ * reduce our rate of sending inserts. */
+ public static final int REJECTED_OVERLOAD = 6;
+
+ /** Failure code */
+ public final int code;
+
+ static final String getMessage(int reason) {
+ return "Unknown error code: "+reason;
+ }
+
+ LowLevelPutException(int code, String message, Throwable t) {
+ super(message, t);
+ this.code = code;
+ }
+
+ LowLevelPutException(int reason) {
+ super(getMessage(reason));
+ this.code = reason;
+ }
+
+}
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2005-11-07 19:06:46 UTC (rev
7493)
+++ trunk/freenet/src/freenet/node/Node.java 2005-11-07 20:17:23 UTC (rev
7494)
@@ -338,7 +338,7 @@
usm.start();
}
- public KeyBlock getKey(ClientKey key, boolean localOnly) {
+ public KeyBlock getKey(ClientKey key, boolean localOnly) throws
LowLevelGetException {
if(key instanceof ClientCHK)
return getCHK((ClientCHK)key, localOnly);
else
@@ -349,17 +349,19 @@
* Really trivially simple client interface.
* Either it succeeds or it doesn't.
*/
- public ClientCHKBlock getCHK(ClientCHK key, boolean localOnly) {
+ public ClientCHKBlock getCHK(ClientCHK key, boolean localOnly) throws
LowLevelGetException {
Object o = makeRequestSender(key.getNodeCHK(), MAX_HTL,
random.nextLong(), null, lm.loc.getValue(), localOnly);
if(o instanceof CHKBlock) {
try {
return new ClientCHKBlock((CHKBlock)o, key);
} catch (CHKVerifyException e) {
Logger.error(this, "Does not verify: "+e, e);
- return null;
+ throw new
LowLevelGetException(LowLevelGetException.DECODE_FAILED);
}
}
- if(o == null) return null;
+ if(o == null) {
+ throw new
LowLevelGetException(LowLevelGetException.DATA_NOT_FOUND_IN_STORE);
+ }
RequestSender rs = (RequestSender)o;
rs.waitUntilFinished();
if(rs.getStatus() == RequestSender.SUCCESS) {
@@ -367,15 +369,31 @@
return new ClientCHKBlock(rs.getPRB().getBlock(),
rs.getHeaders(), key, true);
} catch (CHKVerifyException e) {
Logger.error(this, "Does not verify: "+e, e);
- return null;
+ throw new
LowLevelGetException(LowLevelGetException.DECODE_FAILED);
}
} else {
- Logger.normal(this, "getCHK failed: "+rs.getStatus());
- return null;
+ switch(rs.getStatus()) {
+ case RequestSender.NOT_FINISHED:
+ Logger.error(this, "RS still running in getCHK!: "+rs);
+ throw new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR);
+ case RequestSender.DATA_NOT_FOUND:
+ throw new
LowLevelGetException(LowLevelGetException.DATA_NOT_FOUND);
+ case RequestSender.REJECTED_OVERLOAD:
+ throw new
LowLevelGetException(LowLevelGetException.REJECTED_OVERLOAD);
+ case RequestSender.ROUTE_NOT_FOUND:
+ throw new
LowLevelGetException(LowLevelGetException.ROUTE_NOT_FOUND);
+ case RequestSender.TRANSFER_FAILED:
+ throw new
LowLevelGetException(LowLevelGetException.TRANSFER_FAILED);
+ case RequestSender.VERIFY_FAILURE:
+ throw new
LowLevelGetException(LowLevelGetException.VERIFY_FAILED);
+ default:
+ Logger.error(this, "Unknown RequestSender code in
getCHK: "+rs.getStatus()+" on "+rs);
+ throw new
LowLevelGetException(LowLevelGetException.INTERNAL_ERROR);
+ }
}
}
- public void putCHK(ClientCHKBlock block) {
+ public void putCHK(ClientCHKBlock block) throws LowLevelPutException {
byte[] data = block.getData();
byte[] headers = block.getHeader();
PartiallyReceivedBlock prb = new
PartiallyReceivedBlock(PACKETS_IN_BLOCK, PACKET_SIZE, data);
@@ -401,6 +419,19 @@
if(status == is.ROUTE_NOT_FOUND)
msg += " - this is normal on small networks; the data will
still be propagated, but it can't find the 20+ nodes needed for full success";
Logger.error(this, msg);
+ switch(is.getStatus()) {
+ case InsertSender.NOT_FINISHED:
+ Logger.error(this, "IS still running in putCHK!: "+is);
+ throw new
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
+ case InsertSender.REJECTED_OVERLOAD:
+ throw new
LowLevelPutException(LowLevelPutException.REJECTED_OVERLOAD);
+ case InsertSender.ROUTE_NOT_FOUND:
+ throw new
LowLevelPutException(LowLevelPutException.ROUTE_NOT_FOUND);
+ default:
+ Logger.error(this, "Unknown InsertSender code in
putCHK: "+is.getStatus()+" on "+is);
+ throw new
LowLevelPutException(LowLevelPutException.INTERNAL_ERROR);
+
+ }
}
}
Modified: trunk/freenet/src/freenet/node/SimpleLowLevelClient.java
===================================================================
--- trunk/freenet/src/freenet/node/SimpleLowLevelClient.java 2005-11-07
19:06:46 UTC (rev 7493)
+++ trunk/freenet/src/freenet/node/SimpleLowLevelClient.java 2005-11-07
20:17:23 UTC (rev 7494)
@@ -15,12 +15,12 @@
public interface SimpleLowLevelClient {
/**
- * Fetch a key. Return null if cannot retrieve it.
+ * Fetch a key. Throws if it cannot fetch it.
*/
- public KeyBlock getKey(ClientKey key, boolean localOnly);
+ public KeyBlock getKey(ClientKey key, boolean localOnly) throws
LowLevelGetException;
/**
* Insert a key.
*/
- public void putCHK(ClientCHKBlock key);
+ public void putCHK(ClientCHKBlock key) throws LowLevelPutException;
}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-07
19:06:46 UTC (rev 7493)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2005-11-07
20:17:23 UTC (rev 7494)
@@ -204,7 +204,11 @@
ClientCHK chk = block.getClientKey();
FreenetURI uri =
chk.getURI();
- n.putCHK(block);
+ try {
+ n.putCHK(block);
+ } catch (LowLevelPutException e) {
+ System.err.println("Error: "+e.getMessage());
+ }
// Definitely interface
System.out.println("URI: "+uri);
} else if(uline.startsWith("PUTFILE:")) {
@@ -243,6 +247,8 @@
} catch (IOException e) {
System.out.println("Could not read: "+e);
e.printStackTrace();
+ } catch (LowLevelPutException e) {
+ System.err.println("Error: "+e.getMessage());
} catch (Throwable t) {
System.out.println("Threw: "+t);
t.printStackTrace();
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-11-07 19:06:46 UTC (rev
7493)
+++ trunk/freenet/src/freenet/node/Version.java 2005-11-07 20:17:23 UTC (rev
7494)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 142;
+ public static final int buildNumber = 143;
/** Oldest build of Fred we will talk to */
public static final int lastGoodBuild = 139;