Author: robert
Date: 2008-02-11 18:26:43 +0000 (Mon, 11 Feb 2008)
New Revision: 17781
Modified:
trunk/freenet/src/freenet/node/LocationManager.java
trunk/freenet/src/freenet/node/NetworkIDManager.java
trunk/freenet/src/freenet/node/PeerManager.java
trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
Log:
testable swap-space isolation (disabled)
Modified: trunk/freenet/src/freenet/node/LocationManager.java
===================================================================
--- trunk/freenet/src/freenet/node/LocationManager.java 2008-02-11 18:12:34 UTC
(rev 17780)
+++ trunk/freenet/src/freenet/node/LocationManager.java 2008-02-11 18:26:43 UTC
(rev 17781)
@@ -818,7 +818,7 @@
if(logMINOR) Logger.minor(this, "Forwarding... "+oldID);
while(true) {
// Forward
- PeerNode randomPeer = node.peers.getRandomPeer(pn);
+ PeerNode randomPeer =
node.peers.getRandomPeerInSwappingNetworkOf(pn);
if(randomPeer == null) {
if(logMINOR) Logger.minor(this, "Late reject "+oldID);
Message reject = DMT.createFNPSwapRejected(oldID);
Modified: trunk/freenet/src/freenet/node/NetworkIDManager.java
===================================================================
--- trunk/freenet/src/freenet/node/NetworkIDManager.java 2008-02-11
18:12:34 UTC (rev 17780)
+++ trunk/freenet/src/freenet/node/NetworkIDManager.java 2008-02-11
18:26:43 UTC (rev 17781)
@@ -29,6 +29,7 @@
public class NetworkIDManager implements Runnable {
public static boolean disableSecretPings=true;
public static boolean disableSecretPinger=true;
+ public static boolean disableSwapSegregation=true;
private static final int ACCEPTED_TIMEOUT = 5000;
private static final int SECRETPONG_TIMEOUT = 20000;
@@ -935,4 +936,20 @@
//or zero if we don't know yet
public int ourNetworkId = NO_NETWORKID;
+
+ /**
+ * Returns true if (and only if) the connectivity between two given
nodes have been computed and
+ * they have been determined to be in separate keyspace networks.
Fail-safe false, if either of the
+ * two peers have been recently added, if this class is not past its
initial startupChecks, etc.
+ */
+ public boolean inSeparateNetworks(PeerNode a, PeerNode b) {
+ if (a==null || b==null || a.assignedNetworkID == NO_NETWORKID
|| b.assignedNetworkID == NO_NETWORKID)
+ return false;
+ synchronized (dontStartPlease) {
+ if (inTransition)
+ return false;
+ //NB: Object.equal's; but they should be the very same
object. Neither should be null.
+ return !a.networkGroup.equals(b.networkGroup);
+ }
+ }
}
\ No newline at end of file
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2008-02-11 18:12:34 UTC
(rev 17780)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2008-02-11 18:26:43 UTC
(rev 17781)
@@ -570,6 +570,33 @@
} else return locPairs;
}
+ public PeerNode getRandomPeerInSwappingNetworkOf(PeerNode exclude) {
+ if (exclude==null || exclude.networkGroup==null ||
NetworkIDManager.disableSwapSegregation)
+ return getRandomPeer(exclude);
+ synchronized (this) {
+ if(connectedPeers.length == 0) return null;
+ for(int i=0;i<5;i++) {
+ PeerNode pn =
connectedPeers[node.random.nextInt(connectedPeers.length)];
+ if(pn == exclude) continue;
+ if (node.netid.inSeparateNetworks(pn, exclude))
continue;
+ if(pn.isRoutable()) return pn;
+ }
+ //could not easily find a good random one... filter the
ones which are acceptable
+ ArrayList l=new ArrayList();
+ for (int i=0; i<connectedPeers.length; i++) {
+ PeerNode pn=connectedPeers[i];
+ if(pn == exclude) continue;
+ if (node.netid.inSeparateNetworks(pn, exclude))
continue;
+ if(!pn.isRoutable()) continue;
+ l.add(pn);
+ }
+ //Are there any acceptable peers?
+ if (l.size() == 0)
+ return null;
+ return (PeerNode)l.get(node.random.nextInt(l.size()));
+ }
+ }
+
/**
* @return A random routable connected peer.
* FIXME: should this take performance into account?
Modified:
trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
2008-02-11 18:12:34 UTC (rev 17780)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
2008-02-11 18:26:43 UTC (rev 17781)
@@ -73,6 +73,7 @@
//Allow secret pings, and send them automatically, must be done
before creating the nodes.
freenet.node.NetworkIDManager.disableSecretPings=false;
freenet.node.NetworkIDManager.disableSecretPinger=false;
+ //freenet.node.NetworkIDManager.disableSwapSegregation=false;
for(int i=0;i<NUMBER_OF_NODES;i++) {
allNodes[totalNodes] =