Author: toad
Date: 2008-04-11 18:30:14 +0000 (Fri, 11 Apr 2008)
New Revision: 19198
Modified:
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/PeerManager.java
Log:
When deciding whether we are a sink for a key (and therefore whether we should
put it in the store rather than the cache), ignore nodes whose uptime is less
than Node.MIN_UPTIME_STORE_KEY.
For now this is zero, but once the code is widely deployed it will be increased.
This should help to ensure that data is stored on nodes which are likely to
still be around when it is fetched, and minimise the impact of a slashdotting
on data persistence.
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2008-04-11 18:22:17 UTC (rev
19197)
+++ trunk/freenet/src/freenet/node/Node.java 2008-04-11 18:30:14 UTC (rev
19198)
@@ -469,6 +469,13 @@
// Debugging stuff
private static final boolean USE_RAM_PUBKEYS_CACHE = true;
+
+ /**
+ * Minimum uptime for us to consider a node an acceptable place to
store a key. We store a key
+ * to the datastore only if it's from an insert, and we are a sink, but
when calculating whether
+ * we are a sink we ignore nodes which have less uptime (percentage)
than this parameter.
+ */
+ private static final int MIN_UPTIME_STORE_KEY = 0;
/**
* Read all storable settings (identity etc) from the node file.
@@ -2108,7 +2115,7 @@
* closest node to the target; see the description of chkDatastore.
*/
public void store(CHKBlock block, double loc) {
- boolean deep = !peers.isCloserLocation(loc);
+ boolean deep = !peers.isCloserLocation(loc,
MIN_UPTIME_STORE_KEY);
store(block, deep);
}
@@ -2190,7 +2197,7 @@
* closest node to the target; see the description of chkDatastore.
*/
public void store(SSKBlock block, double loc) throws
KeyCollisionException {
- boolean deep = !peers.isCloserLocation(loc);
+ boolean deep = !peers.isCloserLocation(loc,
MIN_UPTIME_STORE_KEY);
store(block, deep);
}
@@ -2323,7 +2330,7 @@
throw new IllegalArgumentException("No pub key when
inserting");
}
if(cache)
- cacheKey(key.getPubKeyHash(), key.getPubKey(),
!peers.isCloserLocation(block.getKey().toNormalizedDouble()));
+ cacheKey(key.getPubKeyHash(), key.getPubKey(),
!peers.isCloserLocation(block.getKey().toNormalizedDouble(),
Node.MIN_UPTIME_STORE_KEY));
Logger.minor(this, "makeInsertSender("+key+ ',' +htl+ ',' +uid+
',' +source+",...,"+fromStore);
KeyHTLPair kh = new KeyHTLPair(key, htl, uid);
SSKInsertSender is = null;
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2008-04-11 18:22:17 UTC
(rev 19197)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2008-04-11 18:30:14 UTC
(rev 19198)
@@ -708,7 +708,7 @@
return getRandomPeer(null);
}
- public double closestPeerLocation(double loc, double ignoreLoc) {
+ public double closestPeerLocation(double loc, double ignoreLoc, int
minUptimePercent) {
PeerNode[] peers;
synchronized (this) {
peers = connectedPeers;
@@ -720,6 +720,7 @@
PeerNode p = peers[i];
if(!p.isRoutable()) continue;
if(p.isRoutingBackedOff()) continue;
+ if(p.getUptime() < minUptimePercent) continue;
double peerloc = p.getLocation();
if(Math.abs(peerloc - ignoreLoc) < Double.MIN_VALUE*2)
continue;
@@ -734,6 +735,7 @@
for(int i=0;i<peers.length;i++) {
PeerNode p = peers[i];
if(!p.isRoutable()) continue;
+ if(p.getUptime() < minUptimePercent) continue;
// Ignore backoff state
double peerloc = p.getLocation();
if(Math.abs(peerloc - ignoreLoc) < Double.MIN_VALUE*2)
@@ -749,10 +751,10 @@
return bestLoc;
}
- public boolean isCloserLocation(double loc) {
+ public boolean isCloserLocation(double loc, int minUptimePercent) {
double nodeLoc = node.lm.getLocation();
double nodeDist = Location.distance(nodeLoc, loc);
- double closest = closestPeerLocation(loc, nodeLoc);
+ double closest = closestPeerLocation(loc, nodeLoc, minUptimePercent);
if(closest > 1.0) {
// No peers found
return false;