Author: toad
Date: 2005-11-18 16:06:58 +0000 (Fri, 18 Nov 2005)
New Revision: 7564
Modified:
trunk/freenet/src/freenet/client/Fetcher.java
trunk/freenet/src/freenet/client/FetcherContext.java
trunk/freenet/src/freenet/client/FileInserter.java
trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
trunk/freenet/src/freenet/client/InserterContext.java
trunk/freenet/src/freenet/node/InsertHandler.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/PeerManager.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/QueuedDataRequest.java
trunk/freenet/src/freenet/node/QueuedInsertRequest.java
trunk/freenet/src/freenet/node/QueueingSimpleLowLevelClient.java
trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java
trunk/freenet/src/freenet/node/RequestHandler.java
trunk/freenet/src/freenet/node/RequestStarterClient.java
trunk/freenet/src/freenet/node/SimpleLowLevelClient.java
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/store/BaseFreenetStore.java
trunk/freenet/src/freenet/store/DataStore.java
trunk/freenet/src/freenet/store/FreenetStore.java
Log:
194: (mandatory)
Support for dont-cache-local-requests (should be turned OFF on opennet).
Move routing bias calculation into PeerNode.
Show it on STATUS.
Try to ensure that new nodes have a chance, even if they are unlucky the first
time.
Modified: trunk/freenet/src/freenet/client/Fetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/Fetcher.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/client/Fetcher.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -109,7 +109,7 @@
// Do the fetch
KeyBlock block;
try {
- block = ctx.client.getKey(key, localOnly,
ctx.starterClient);
+ block = ctx.client.getKey(key, localOnly,
ctx.starterClient, ctx.cacheLocalRequests);
} catch (LowLevelGetException e) {
switch(e.code) {
case LowLevelGetException.DATA_NOT_FOUND:
Modified: trunk/freenet/src/freenet/client/FetcherContext.java
===================================================================
--- trunk/freenet/src/freenet/client/FetcherContext.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/client/FetcherContext.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -36,6 +36,7 @@
final int maxDataBlocksPerSegment;
final int maxCheckBlocksPerSegment;
final RequestStarterClient starterClient;
+ final boolean cacheLocalRequests;
public FetcherContext(SimpleLowLevelClient client, long curMaxLength,
@@ -45,7 +46,7 @@
boolean allowSplitfiles, boolean followRedirects,
boolean localRequestOnly,
int maxDataBlocksPerSegment, int
maxCheckBlocksPerSegment,
RandomSource random, ArchiveManager archiveManager,
BucketFactory bucketFactory,
- ClientEventProducer producer, RequestStarterClient
starter) {
+ ClientEventProducer producer, RequestStarterClient
starter, boolean cacheLocalRequests) {
this.client = client;
this.maxOutputLength = curMaxLength;
this.maxTempLength = curMaxTempLength;
@@ -67,6 +68,7 @@
this.maxDataBlocksPerSegment = maxDataBlocksPerSegment;
this.maxCheckBlocksPerSegment = maxCheckBlocksPerSegment;
this.starterClient = starter;
+ this.cacheLocalRequests = cacheLocalRequests;
}
public FetcherContext(FetcherContext ctx, int maskID) {
@@ -92,6 +94,7 @@
this.maxDataBlocksPerSegment = 0;
this.maxCheckBlocksPerSegment = 0;
this.starterClient = ctx.starterClient;
+ this.cacheLocalRequests = ctx.cacheLocalRequests;
} else if(maskID == SPLITFILE_DEFAULT_MASK) {
this.client = ctx.client;
this.maxOutputLength = ctx.maxOutputLength;
@@ -114,6 +117,7 @@
this.maxDataBlocksPerSegment =
ctx.maxDataBlocksPerSegment;
this.maxCheckBlocksPerSegment =
ctx.maxCheckBlocksPerSegment;
this.starterClient = ctx.starterClient;
+ this.cacheLocalRequests = ctx.cacheLocalRequests;
} else if(maskID == SPLITFILE_USE_LENGTHS_MASK) {
this.client = ctx.client;
this.maxOutputLength = ctx.maxOutputLength;
@@ -136,6 +140,7 @@
this.maxDataBlocksPerSegment =
ctx.maxDataBlocksPerSegment;
this.maxCheckBlocksPerSegment =
ctx.maxCheckBlocksPerSegment;
this.starterClient = ctx.starterClient;
+ this.cacheLocalRequests = ctx.cacheLocalRequests;
} else throw new IllegalArgumentException();
}
Modified: trunk/freenet/src/freenet/client/FileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/FileInserter.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/client/FileInserter.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -122,7 +122,7 @@
try {
ctx.eventProducer.produceEvent(new
SimpleBlockPutEvent(chk.getClientKey()));
if(!getCHKOnly)
- ctx.client.putCHK(chk, ctx.starterClient);
+ ctx.client.putCHK(chk, ctx.starterClient,
ctx.cacheLocalRequests);
} catch (LowLevelPutException e) {
le = e;
}
Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2005-11-18 15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2005-11-18 16:06:58 UTC (rev 7564)
@@ -24,6 +24,8 @@
private final RandomSource random;
private final RequestStarterClient requestStarter;
private final RequestStarterClient insertStarter;
+ /** See comments in Node */
+ private final boolean cacheLocalRequests;
static final int MAX_RECURSION = 10;
static final int MAX_ARCHIVE_RESTARTS = 2;
static final boolean DONT_ENTER_IMPLICIT_ARCHIVES = true;
@@ -53,7 +55,7 @@
static final int SPLITFILE_CHECK_BLOCKS_PER_SEGMENT = 64;
- public HighLevelSimpleClientImpl(SimpleLowLevelClient client,
ArchiveManager mgr, BucketFactory bf, RandomSource r, RequestStarterClient
requestStarterClient, RequestStarterClient insertStarterClient) {
+ public HighLevelSimpleClientImpl(SimpleLowLevelClient client,
ArchiveManager mgr, BucketFactory bf, RandomSource r, RequestStarterClient
requestStarterClient, RequestStarterClient insertStarterClient, boolean
cacheLocalRequests) {
this.client = client;
archiveManager = mgr;
bucketFactory = bf;
@@ -65,6 +67,7 @@
curMaxMetadataLength = 1024 * 1024;
this.requestStarter = requestStarterClient;
this.insertStarter = insertStarterClient;
+ this.cacheLocalRequests = cacheLocalRequests;
}
public void setMaxLength(long maxLength) {
@@ -85,14 +88,14 @@
SPLITFILE_THREADS, SPLITFILE_BLOCK_RETRIES,
NON_SPLITFILE_RETRIES,
FETCH_SPLITFILES, FOLLOW_REDIRECTS,
LOCAL_REQUESTS_ONLY,
MAX_SPLITFILE_BLOCKS_PER_SEGMENT,
MAX_SPLITFILE_CHECK_BLOCKS_PER_SEGMENT,
- random, archiveManager, bucketFactory,
globalEventProducer, requestStarter);
+ random, archiveManager, bucketFactory,
globalEventProducer, requestStarter, cacheLocalRequests);
Fetcher f = new Fetcher(uri, context);
return f.run();
}
public FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws
InserterException {
InserterContext context = new InserterContext(client,
bucketFactory, random, SPLITFILE_INSERT_RETRIES,
- SPLITFILE_INSERT_THREADS,
SPLITFILE_BLOCKS_PER_SEGMENT, SPLITFILE_CHECK_BLOCKS_PER_SEGMENT,
globalEventProducer, insertStarter);
+ SPLITFILE_INSERT_THREADS,
SPLITFILE_BLOCKS_PER_SEGMENT, SPLITFILE_CHECK_BLOCKS_PER_SEGMENT,
globalEventProducer, insertStarter, cacheLocalRequests);
FileInserter i = new FileInserter(context);
return i.run(insert, false, getCHKOnly);
}
Modified: trunk/freenet/src/freenet/client/InserterContext.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterContext.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/client/InserterContext.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -21,10 +21,12 @@
final int splitfileSegmentCheckBlocks;
final ClientEventProducer eventProducer;
final RequestStarterClient starterClient;
+ /** Interesting tradeoff, see comments at top of Node.java. */
+ final boolean cacheLocalRequests;
public InserterContext(SimpleLowLevelClient client, BucketFactory bf,
RandomSource random,
int maxRetries, int maxThreads, int
splitfileSegmentDataBlocks, int splitfileSegmentCheckBlocks,
- ClientEventProducer eventProducer, RequestStarterClient
sctx) {
+ ClientEventProducer eventProducer, RequestStarterClient
sctx, boolean cacheLocalRequests) {
this.client = client;
this.bf = bf;
this.random = random;
@@ -36,6 +38,7 @@
this.splitfileSegmentDataBlocks = splitfileSegmentDataBlocks;
this.splitfileSegmentCheckBlocks = splitfileSegmentCheckBlocks;
this.starterClient = sctx;
+ this.cacheLocalRequests = cacheLocalRequests;
}
}
Modified: trunk/freenet/src/freenet/node/InsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/InsertHandler.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/node/InsertHandler.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -106,7 +106,7 @@
prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK,
Node.PACKET_SIZE);
if(htl > 0)
- sender = node.makeInsertSender(key, htl, uid, source, headers,
prb, false, closestLoc);
+ sender = node.makeInsertSender(key, htl, uid, source, headers,
prb, false, closestLoc, true);
br = new BlockReceiver(node.usm, source, uid, prb);
// Receive the data, off thread
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2005-11-18 15:49:05 UTC (rev
7563)
+++ trunk/freenet/src/freenet/node/Node.java 2005-11-18 16:06:58 UTC (rev
7564)
@@ -66,6 +66,19 @@
static final long serialVersionUID = -1;
+ /** If true, local requests and inserts aren't cached.
+ * This opens up a glaring vulnerability; connected nodes
+ * can then probe the store, and if the node doesn't have the
+ * content, they know for sure that it was a local request.
+ * HOWEVER, if we don't do this, then a non-full seized
+ * datastore will contain everything requested by the user...
+ * Also, remote probing is possible.
+ *
+ * So it may be useful on some darknets, and is useful for
+ * debugging, but in general should be off on opennet and
+ * most darknets.
+ */
+ public static final boolean DONT_CACHE_LOCAL_REQUESTS = true;
public static final int PACKETS_IN_BLOCK = 32;
public static final int PACKET_SIZE = 1024;
public static final double DECREMENT_AT_MIN_PROB = 0.2;
@@ -360,16 +373,16 @@
usm.start();
}
- public KeyBlock getKey(ClientKey key, boolean localOnly,
RequestStarterClient client) throws LowLevelGetException {
+ public KeyBlock getKey(ClientKey key, boolean localOnly,
RequestStarterClient client, boolean cache) throws LowLevelGetException {
if(localOnly)
- return realGetKey(key, localOnly);
+ return realGetKey(key, localOnly, cache);
else
- return client.getKey(key, localOnly);
+ return client.getKey(key, localOnly, cache);
}
- public KeyBlock realGetKey(ClientKey key, boolean localOnly) throws
LowLevelGetException {
+ public KeyBlock realGetKey(ClientKey key, boolean localOnly, boolean
cache) throws LowLevelGetException {
if(key instanceof ClientCHK)
- return realGetCHK((ClientCHK)key, localOnly);
+ return realGetCHK((ClientCHK)key, localOnly, cache);
else
throw new IllegalArgumentException("Not a CHK: "+key);
}
@@ -378,8 +391,8 @@
* Really trivially simple client interface.
* Either it succeeds or it doesn't.
*/
- ClientCHKBlock realGetCHK(ClientCHK key, boolean localOnly) throws
LowLevelGetException {
- Object o = makeRequestSender(key.getNodeCHK(), MAX_HTL,
random.nextLong(), null, lm.loc.getValue(), localOnly);
+ ClientCHKBlock realGetCHK(ClientCHK key, boolean localOnly, boolean cache)
throws LowLevelGetException {
+ Object o = makeRequestSender(key.getNodeCHK(), MAX_HTL,
random.nextLong(), null, lm.loc.getValue(), localOnly, cache);
if(o instanceof CHKBlock) {
try {
return new ClientCHKBlock((CHKBlock)o, key);
@@ -425,11 +438,11 @@
}
}
- public void putCHK(ClientCHKBlock block, RequestStarterClient starter)
throws LowLevelPutException {
- starter.putCHK(block);
+ public void putCHK(ClientCHKBlock block, RequestStarterClient starter,
boolean cache) throws LowLevelPutException {
+ starter.putCHK(block, cache);
}
- public void realPutCHK(ClientCHKBlock block) throws LowLevelPutException {
+ public void realPutCHK(ClientCHKBlock block, boolean cache) throws
LowLevelPutException {
byte[] data = block.getData();
byte[] headers = block.getHeader();
PartiallyReceivedBlock prb = new
PartiallyReceivedBlock(PACKETS_IN_BLOCK, PACKET_SIZE, data);
@@ -438,13 +451,15 @@
if(!lockUID(uid))
Logger.error(this, "Could not lock UID just randomly generated:
"+uid+" - probably indicates broken PRNG");
synchronized(this) {
- try {
- datastore.put(block);
- } catch (IOException e) {
- Logger.error(this, "Datastore failure: "+e, e);
- }
+ if(cache) {
+ try {
+ datastore.put(block);
+ } catch (IOException e) {
+ Logger.error(this, "Datastore failure: "+e, e);
+ }
+ }
is = makeInsertSender(block.getClientKey().getNodeCHK(),
- MAX_HTL, uid, null, headers, prb, false,
lm.getLocation().getValue());
+ MAX_HTL, uid, null, headers, prb, false,
lm.getLocation().getValue(), cache);
}
is.waitUntilFinished();
if(is.getStatus() == InsertSender.SUCCESS) {
@@ -553,12 +568,12 @@
* a RequestSender, unless the HTL is 0, in which case NULL.
* RequestSender.
*/
- public synchronized Object makeRequestSender(NodeCHK key, short htl, long
uid, PeerNode source, double closestLocation, boolean localOnly) {
+ public synchronized Object makeRequestSender(NodeCHK key, short htl, long
uid, PeerNode source, double closestLocation, boolean localOnly, boolean cache)
{
Logger.minor(this,
"makeRequestSender("+key+","+htl+","+uid+","+source+") on "+portNumber);
// In store?
CHKBlock chk = null;
try {
- chk = datastore.fetch(key);
+ chk = datastore.fetch(key, !cache);
} catch (IOException e) {
Logger.error(this, "Error accessing store: "+e, e);
}
@@ -643,15 +658,6 @@
}
}
- public synchronized CHKBlock fetchFromStore(NodeCHK key) {
- try {
- return datastore.fetch(key);
- } catch (IOException e) {
- Logger.error(this, "Cannot fetch: "+e, e);
- return null;
- }
- }
-
/**
* Remove a sender from the set of currently transferring senders.
*/
@@ -721,7 +727,7 @@
* if it originated locally.
*/
public synchronized InsertSender makeInsertSender(NodeCHK key, short htl,
long uid, PeerNode source,
- byte[] headers, PartiallyReceivedBlock prb, boolean fromStore,
double closestLoc) {
+ byte[] headers, PartiallyReceivedBlock prb, boolean fromStore,
double closestLoc, boolean cache) {
Logger.minor(this,
"makeInsertSender("+key+","+htl+","+uid+","+source+",...,"+fromStore);
KeyHTLPair kh = new KeyHTLPair(key, htl);
InsertSender is = (InsertSender) insertSenders.get(kh);
@@ -729,6 +735,8 @@
Logger.minor(this, "Found "+is+" for "+kh);
return is;
}
+ if(fromStore && !cache)
+ throw new IllegalArgumentException("From store = true but cache
= false !!!");
is = new InsertSender(key, uid, headers, htl, source, this, prb,
fromStore, closestLoc);
Logger.minor(this, is.toString()+" for "+kh.toString());
insertSenders.put(kh, is);
@@ -809,7 +817,7 @@
}
public HighLevelSimpleClient makeClient(short prioClass, short prio) {
- return new HighLevelSimpleClientImpl(this, archiveManager,
tempBucketFactory, random, makeStarterClient(prioClass, prio, false),
makeStarterClient(prioClass, prio, true));
+ return new HighLevelSimpleClientImpl(this, archiveManager,
tempBucketFactory, random, makeStarterClient(prioClass, prio, false),
makeStarterClient(prioClass, prio, true), !DONT_CACHE_LOCAL_REQUESTS);
}
private static class MemoryChecker implements Runnable {
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -265,10 +265,7 @@
static double distance(PeerNode p, double loc) {
double d = distance(p.getLocation().getValue(), loc);
- double pSummaryFailure = p.getPRejectedOverload();
- double denom = 1.0 - pSummaryFailure;
- if(denom == 0.0) denom = 0.000001;
- return d / denom;
+ return d / p.getBias();
}
/**
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -845,7 +845,8 @@
public String getStatus() {
return
- (isConnected ? "CONNECTED " : "DISCONNECTED") + " " +
getPeer().toString()+" "+myName+" "+currentLocation.getValue()+" "+getVersion()
+ " "+pRejectOverload.currentValue()+" ("+pRejectOverload.countReports()+") "+
pInsertRejectOverload.currentValue()+"
("+pInsertRejectOverload.countReports()+")";
+ (isConnected ? "CONNECTED " : "DISCONNECTED") + " " +
getPeer().toString()+" "+myName+" "+currentLocation.getValue()+" "+getVersion()
+ " reqs: pRO="+pRejectOverload.currentValue()+"
(h="+pRejectOverload.countReports()+",b="+getBias()+") ins: pRO="+
pInsertRejectOverload.currentValue()+
+ " (h="+pInsertRejectOverload.countReports()+")";
}
public String getVersion(){
@@ -964,4 +965,23 @@
public double getPInsertRejectedOverload() {
return pInsertRejectOverload.currentValue();
}
+
+ /**
+ * Return the bias value for routing for this node.
+ * The idea is simply that if a node is overloaded,
+ * its specialization shrinks.
+ * Essentially this is 1.0-P(RejectedOverload or timeout).
+ */
+ public double getBias() {
+ double pSummaryFailure = pRejectOverload.currentValue();
+ long hits = pRejectOverload.countReports();
+ if(hits > 10) {
+ double max = ((double) hits) / ((double) (hits+1));
+ double denom = 1.0 - pSummaryFailure;
+ if(denom == 0.0) denom = 0.000001;
+ return denom;
+ } else {
+ return 1.0;
+ }
+ }
}
Modified: trunk/freenet/src/freenet/node/QueuedDataRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/QueuedDataRequest.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/node/QueuedDataRequest.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -7,17 +7,19 @@
private final ClientKey key;
private final boolean localOnly;
+ private final boolean cache;
private QueueingSimpleLowLevelClient client;
- public QueuedDataRequest(ClientKey key, boolean localOnly,
QueueingSimpleLowLevelClient client) {
+ public QueuedDataRequest(ClientKey key, boolean localOnly, boolean
cache, QueueingSimpleLowLevelClient client) {
this.key = key;
this.localOnly = localOnly;
this.client = client;
+ this.cache = cache;
}
public KeyBlock waitAndFetch() throws LowLevelGetException {
waitForSendClearance();
- return client.realGetKey(key, localOnly);
+ return client.realGetKey(key, localOnly, cache);
}
}
Modified: trunk/freenet/src/freenet/node/QueuedInsertRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/QueuedInsertRequest.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/node/QueuedInsertRequest.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -5,15 +5,17 @@
public class QueuedInsertRequest extends QueuedRequest {
private final ClientCHKBlock block;
+ private final boolean cache;
private QueueingSimpleLowLevelClient client;
- public QueuedInsertRequest(ClientCHKBlock block,
QueueingSimpleLowLevelClient client) {
+ public QueuedInsertRequest(ClientCHKBlock block,
QueueingSimpleLowLevelClient client, boolean cache) {
this.block = block;
this.client = client;
+ this.cache = cache;
}
public void waitAndPut() throws LowLevelPutException {
waitForSendClearance();
- client.realPutCHK(block);
+ client.realPutCHK(block, cache);
}
}
Modified: trunk/freenet/src/freenet/node/QueueingSimpleLowLevelClient.java
===================================================================
--- trunk/freenet/src/freenet/node/QueueingSimpleLowLevelClient.java
2005-11-18 15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/node/QueueingSimpleLowLevelClient.java
2005-11-18 16:06:58 UTC (rev 7564)
@@ -8,9 +8,9 @@
interface QueueingSimpleLowLevelClient extends SimpleLowLevelClient {
/** Unqueued version. Only call from QueuedDataRequest ! */
- KeyBlock realGetKey(ClientKey key, boolean localOnly) throws
LowLevelGetException;
+ KeyBlock realGetKey(ClientKey key, boolean localOnly, boolean cache)
throws LowLevelGetException;
/** Ditto */
- void realPutCHK(ClientCHKBlock block) throws LowLevelPutException;
+ void realPutCHK(ClientCHKBlock block, boolean cache) throws
LowLevelPutException;
}
Modified: trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java
===================================================================
--- trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java
2005-11-18 15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/node/RealNodeRequestInsertTest.java
2005-11-18 16:06:58 UTC (rev 7564)
@@ -181,7 +181,7 @@
Logger.error(RealNodeRequestInsertTest.class, "Decoded: "+new
String(newBlock.memoryDecode(chk)));
Logger.error(RealNodeRequestInsertTest.class,"CHK:
"+chk.getURI());
Logger.error(RealNodeRequestInsertTest.class,"Headers:
"+HexUtil.bytesToHex(block.getHeader()));
- randomNode.putCHK(block, starters[node1]);
+ randomNode.putCHK(block, starters[node1], true);
Logger.error(RealNodeRequestInsertTest.class, "Inserted to
"+node1);
Logger.error(RealNodeRequestInsertTest.class, "Data:
"+Fields.hashCode(encData)+", Headers: "+Fields.hashCode(encHeaders));
// Pick random node to request from
@@ -190,7 +190,7 @@
node2 = random.nextInt(NUMBER_OF_NODES);
} while(node2 == node1);
Node fetchNode = nodes[node2];
- block = (ClientCHKBlock) fetchNode.getKey((ClientKey) chk,
false, starters[node2]);
+ block = (ClientCHKBlock) fetchNode.getKey((ClientKey) chk,
false, starters[node2], true);
if(block == null) {
Logger.error(RealNodeRequestInsertTest.class, "Fetch
FAILED from "+node2);
requestsAvg.report(0.0);
Modified: trunk/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestHandler.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/node/RequestHandler.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -49,7 +49,7 @@
Message accepted = DMT.createFNPAccepted(uid);
source.send(accepted);
- Object o = node.makeRequestSender(key, htl, uid, source, closestLoc,
false);
+ Object o = node.makeRequestSender(key, htl, uid, source, closestLoc,
false, true);
if(o instanceof CHKBlock) {
CHKBlock block = (CHKBlock) o;
Message df = DMT.createFNPDataFound(uid, block.getHeader());
Modified: trunk/freenet/src/freenet/node/RequestStarterClient.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestStarterClient.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/node/RequestStarterClient.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -42,8 +42,8 @@
* Blocking fetch of a key.
* @throws LowLevelGetException If the fetch failed for some reason.
*/
- public KeyBlock getKey(ClientKey key, boolean localOnly) throws
LowLevelGetException {
- QueuedDataRequest qdr = new QueuedDataRequest(key, localOnly,
client);
+ public KeyBlock getKey(ClientKey key, boolean localOnly, boolean cache)
throws LowLevelGetException {
+ QueuedDataRequest qdr = new QueuedDataRequest(key, localOnly,
cache, client);
addRequest(qdr);
return qdr.waitAndFetch();
}
@@ -52,8 +52,8 @@
* Blocking insert of a key.
* @throws LowLevelPutException If the fetch failed for some reason.
*/
- public void putCHK(ClientCHKBlock block) throws LowLevelPutException {
- QueuedInsertRequest qir = new QueuedInsertRequest(block,
client);
+ public void putCHK(ClientCHKBlock block, boolean cache) throws
LowLevelPutException {
+ QueuedInsertRequest qir = new QueuedInsertRequest(block,
client, cache);
addRequest(qir);
qir.waitAndPut();
}
Modified: trunk/freenet/src/freenet/node/SimpleLowLevelClient.java
===================================================================
--- trunk/freenet/src/freenet/node/SimpleLowLevelClient.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/node/SimpleLowLevelClient.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -16,11 +16,15 @@
/**
* Fetch a key. Throws if it cannot fetch it.
+ * @param cache If false, don't cache the data. See the comments at the top
+ * of Node.java.
*/
- public KeyBlock getKey(ClientKey key, boolean localOnly,
RequestStarterClient client) throws LowLevelGetException;
+ public KeyBlock getKey(ClientKey key, boolean localOnly,
RequestStarterClient client, boolean cache) throws LowLevelGetException;
/**
* Insert a key.
+ * @param cache If false, don't cache the data. See the comments at the top
+ * of Node.java.
*/
- public void putCHK(ClientCHKBlock key, RequestStarterClient sctx) throws
LowLevelPutException;
+ public void putCHK(ClientCHKBlock key, RequestStarterClient sctx, boolean
cache) throws LowLevelPutException;
}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-11-18 15:49:05 UTC (rev
7563)
+++ trunk/freenet/src/freenet/node/Version.java 2005-11-18 16:06:58 UTC (rev
7564)
@@ -20,10 +20,10 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 193;
+ public static final int buildNumber = 194;
/** Oldest build of Fred we will talk to */
- public static final int lastGoodBuild = 193;
+ public static final int lastGoodBuild = 194;
/** The highest reported build of fred */
public static int highestSeenBuild = buildNumber;
Modified: trunk/freenet/src/freenet/store/BaseFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BaseFreenetStore.java 2005-11-18
15:49:05 UTC (rev 7563)
+++ trunk/freenet/src/freenet/store/BaseFreenetStore.java 2005-11-18
16:06:58 UTC (rev 7564)
@@ -50,16 +50,16 @@
* Retrieve a block.
* @return null if there is no such block stored, otherwise the block.
*/
- public synchronized CHKBlock fetch(NodeCHK chk) throws IOException {
- byte[] data = dataStore.getDataForBlock(chk);
+ public synchronized CHKBlock fetch(NodeCHK chk, boolean dontPromote)
throws IOException {
+ byte[] data = dataStore.getDataForBlock(chk, dontPromote);
if(data == null) {
- if(headersStore.getDataForBlock(chk) != null) {
+ if(headersStore.getDataForBlock(chk, true) != null) {
Logger.normal(this, "Deleting: "+chk+" headers, no data");
headersStore.delete(chk);
}
return null;
}
- byte[] headers = headersStore.getDataForBlock(chk);
+ byte[] headers = headersStore.getDataForBlock(chk, dontPromote);
if(headers == null) {
// No headers, delete
Logger.normal(this, "Deleting: "+chk+" data, no headers");
Modified: trunk/freenet/src/freenet/store/DataStore.java
===================================================================
--- trunk/freenet/src/freenet/store/DataStore.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/store/DataStore.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -148,13 +148,13 @@
getRecordNumberList().add(recnum, b);
}
- public synchronized byte[] getDataForBlock(Key key) throws IOException {
+ public synchronized byte[] getDataForBlock(Key key, boolean
dontPromote) throws IOException {
DataBlock b = getBlockByKey(key);
if (b == null) {
return null;
} else {
Logger.minor(this, "Reading block: "+b.getRecordNumber());
- return readData(b);
+ return readData(b, dontPromote);
}
}
@@ -162,16 +162,18 @@
return ((Map)getKeyMap().clone()).keySet();
}
- private byte[] readData(DataBlock dataBlock) throws IOException {
+ private byte[] readData(DataBlock dataBlock, boolean dontPromote)
throws IOException {
byte[] ba = new byte[blockSize];
getBlockStore().seek(dataBlock.positionInDataFile());
getBlockStore().readFully(ba);
dataBlock.setLastAccessTime(System.currentTimeMillis()) ;
- getAccessTimeList().remove(dataBlock);
- getAccessTimeList().addLast(dataBlock);
- _index.seek(dataBlock.positionInIndexFile() +
DataBlock.KEY_SIZE);
- _index.writeLong(dataBlock.getLastAccessTime());
+ if(!dontPromote) {
+ getAccessTimeList().remove(dataBlock);
+ getAccessTimeList().addLast(dataBlock);
+ _index.seek(dataBlock.positionInIndexFile() +
DataBlock.KEY_SIZE);
+ _index.writeLong(dataBlock.getLastAccessTime());
+ }
return ba;
}
Modified: trunk/freenet/src/freenet/store/FreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/FreenetStore.java 2005-11-18 15:49:05 UTC
(rev 7563)
+++ trunk/freenet/src/freenet/store/FreenetStore.java 2005-11-18 16:06:58 UTC
(rev 7564)
@@ -12,9 +12,10 @@
/**
* Retrieve a block.
+ * @param dontPromote If true, don't promote data if fetched.
* @return null if there is no such block stored, otherwise the block.
*/
- public CHKBlock fetch(NodeCHK chk) throws IOException;
+ public CHKBlock fetch(NodeCHK chk, boolean dontPromote) throws IOException;
/**
* Store a block.