Author: nextgens
Date: 2008-07-21 23:10:14 +0000 (Mon, 21 Jul 2008)
New Revision: 21299
Added:
trunk/freenet/src/freenet/node/simulator/SeednodePingTest.java
Modified:
trunk/freenet/src/freenet/node/Announcer.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/NodeStarter.java
trunk/freenet/src/freenet/node/PeerManager.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/SeedServerPeerNode.java
trunk/freenet/src/freenet/node/simulator/RealNodeBusyNetworkTest.java
trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
trunk/freenet/src/freenet/node/simulator/RealNodePingTest.java
trunk/freenet/src/freenet/node/simulator/RealNodeRequestInsertTest.java
trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
trunk/freenet/src/freenet/node/simulator/RealNodeSecretPingTest.java
trunk/freenet/src/freenet/node/simulator/RealNodeULPRTest.java
Log:
Commit the ugly piece of code I use to ping seednodes before it gets bigger
Modified: trunk/freenet/src/freenet/node/Announcer.java
===================================================================
--- trunk/freenet/src/freenet/node/Announcer.java 2008-07-21 21:47:08 UTC
(rev 21298)
+++ trunk/freenet/src/freenet/node/Announcer.java 2008-07-21 23:10:14 UTC
(rev 21299)
@@ -110,7 +110,7 @@
boolean announceNow = false;
if(logMINOR)
Logger.minor(this, "Connecting some seednodes...");
- Vector/*<SimpleFieldSet>*/ seeds = readSeednodes();
+ Vector/*<SimpleFieldSet>*/ seeds =
Announcer.readSeednodes(node.nodeDir);
long now = System.currentTimeMillis();
synchronized(this) {
if(now - timeAddedSeeds < MIN_ADDED_SEEDS_INTERVAL)
return;
@@ -212,10 +212,8 @@
return count;
}
- private Vector readSeednodes() {
- if(logMINOR)
- Logger.minor(this, "Reading seednodes");
- File file = new File(node.nodeDir, "seednodes.fref");
+ public static Vector readSeednodes(File nodeDir) {
+ File file = new File(nodeDir, "seednodes.fref");
Vector list = new Vector();
FileInputStream fis = null;
try {
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2008-07-21 21:47:08 UTC (rev
21298)
+++ trunk/freenet/src/freenet/node/Node.java 2008-07-21 23:10:14 UTC (rev
21299)
@@ -3115,6 +3115,9 @@
/**
* Connect this node to another node (for purposes of testing)
*/
+ public void connectToSeednode(SeedServerPeerNode node) throws
OpennetDisabledException, FSParseException, PeerParseException,
ReferenceSignatureVerificationException {
+
peers.addPeer(createNewSeedServerPeerNode(node.exportSeedNodeFieldSet()),false,false);
+ }
public void connect(Node node) throws FSParseException,
PeerParseException, ReferenceSignatureVerificationException {
peers.connect(node.darknetCrypto.exportPublicFieldSet(),
darknetCrypto.packetMangler);
}
@@ -3172,6 +3175,11 @@
return new OpennetPeerNode(fs, this, opennet.crypto, opennet,
peers, false, opennet.crypto.packetMangler);
}
+ public SeedServerPeerNode createNewSeedServerPeerNode(SimpleFieldSet
fs) throws FSParseException, OpennetDisabledException, PeerParseException,
ReferenceSignatureVerificationException {
+ if(opennet == null) throw new OpennetDisabledException("Opennet
is not currently enabled");
+ return new SeedServerPeerNode(fs, this, opennet.crypto, peers,
true, opennet.crypto.packetMangler);
+ }
+
public OpennetPeerNode addNewOpennetNode(SimpleFieldSet fs) throws
FSParseException, PeerParseException, ReferenceSignatureVerificationException {
// FIXME: perhaps this should throw OpennetDisabledExcemption
rather than returing false?
if(opennet == null) return null;
Modified: trunk/freenet/src/freenet/node/NodeStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStarter.java 2008-07-21 21:47:08 UTC
(rev 21298)
+++ trunk/freenet/src/freenet/node/NodeStarter.java 2008-07-21 23:10:14 UTC
(rev 21299)
@@ -331,7 +331,7 @@
* @throws NodeInitException If the node cannot start up for some
reason, most
* likely a config problem.
*/
- public static Node createTestNode(int port, String testName, boolean
doClient,
+ public static Node createTestNode(int port, int opennetPort, String
testName, boolean doClient,
boolean doSwapping, boolean disableProbabilisticHTLs, short
maxHTL,
int dropProb, RandomSource random, Executor executor, int
threadLimit,
long storeSize, boolean ramStore, boolean enableSwapping,
boolean enableARKs,
@@ -387,6 +387,8 @@
configFS.put("node.enablePacketCoalescing",
enablePacketCoalescing);
configFS.put("node.publishOurPeersLocation", enableFOAF);
configFS.put("node.routeAccordingToOurPeersLocation",
enableFOAF);
+ configFS.put("node.opennet.enabled", opennetPort > 0);
+ configFS.put("node.opennet.listenPort", opennetPort);
PersistentConfig config = new PersistentConfig(configFS);
@@ -396,5 +398,5 @@
node.peers.removeAllPeers();
return node;
- }
+ }
}
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2008-07-21 21:47:08 UTC
(rev 21298)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2008-07-21 23:10:14 UTC
(rev 21299)
@@ -1781,6 +1781,16 @@
}
return count;
}
+
+ public int countSeednodes() {
+ int count = 0;
+ for(PeerNode peer : myPeers) {
+ if(peer.isRealConnection())
+ continue;
+ count++;
+ }
+ return count;
+ }
public int countBackedOffPeers() {
PeerNode[] peers = myPeers;
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2008-07-21 21:47:08 UTC
(rev 21298)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2008-07-21 23:10:14 UTC
(rev 21299)
@@ -1492,7 +1492,7 @@
*/
public boolean ping(int pingID) throws NotConnectedException {
Message ping = DMT.createFNPPing(pingID);
- node.usm.send(this, ping, null);
+ node.usm.send(this, ping, node.dispatcher.pingCounter);
Message msg;
try {
msg =
node.usm.waitFor(MessageFilter.create().setTimeout(2000).setType(DMT.FNPPong).setField(DMT.PING_SEQNO,
pingID), null);
Modified: trunk/freenet/src/freenet/node/SeedServerPeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/SeedServerPeerNode.java 2008-07-21
21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/SeedServerPeerNode.java 2008-07-21
23:10:14 UTC (rev 21299)
@@ -117,4 +117,10 @@
// Drop the connection once we have consistently had enough
opennet peers for 5 minutes.
return System.currentTimeMillis() -
om.announcer.timeGotEnoughPeers() > 5*60*1000;
}
+
+ public SimpleFieldSet exportSeedNodeFieldSet() {
+ SimpleFieldSet sfs = super.exportFieldSet();
+ sfs.putOverwrite("opennet", "true");
+ return sfs;
+ }
}
Modified: trunk/freenet/src/freenet/node/simulator/RealNodeBusyNetworkTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeBusyNetworkTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeBusyNetworkTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -75,7 +75,7 @@
Executor executor = new PooledExecutor();
for(int i=0;i<NUMBER_OF_NODES;i++) {
nodes[i] =
- NodeStarter.createTestNode(5001+i, name, false, true, false,
MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES,
(CHKBlock.DATA_LENGTH+CHKBlock.TOTAL_HEADERS_LENGTH)*100, true,
ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES,
ENABLE_SWAP_QUEUEING, ENABLE_PACKET_COALESCING, 8000, ENABLE_FOAF);
+ NodeStarter.createTestNode(5001+i, 0, name, false, true, false,
MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES,
(CHKBlock.DATA_LENGTH+CHKBlock.TOTAL_HEADERS_LENGTH)*100, true,
ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES,
ENABLE_SWAP_QUEUEING, ENABLE_PACKET_COALESCING, 8000, ENABLE_FOAF);
Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
}
Modified:
trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -79,21 +79,21 @@
for(int i=0;i<NUMBER_OF_NODES;i++) {
allNodes[totalNodes] =
subnetA[i] =
- NodeStarter.createTestNode(5001+totalNodes, wd, false, true,
true, MAX_HTL, 0 /* no dropped packets */, random, executor,
500*NUMBER_OF_NODES, storeSize, true, true, false, false, false, false, true,
0, ENABLE_FOAF);
+ NodeStarter.createTestNode(5001+totalNodes, 0, wd, false, true,
true, MAX_HTL, 0 /* no dropped packets */, random, executor,
500*NUMBER_OF_NODES, storeSize, true, true, false, false, false, false, true,
0, ENABLE_FOAF);
totalNodes++;
Logger.normal(RealNodeRoutingTest.class, "Created 'A' node
"+totalNodes);
}
for(int i=0;i<NUMBER_OF_NODES;i++) {
allNodes[totalNodes] =
subnetB[i] =
- NodeStarter.createTestNode(5001+totalNodes, wd, false,
true, true, MAX_HTL, 0 /* no dropped packets */, random, executor,
500*NUMBER_OF_NODES, storeSize, true, true, false, false, false, false, true,
0, ENABLE_FOAF);
+ NodeStarter.createTestNode(5001+totalNodes, 0, wd,
false, true, true, MAX_HTL, 0 /* no dropped packets */, random, executor,
500*NUMBER_OF_NODES, storeSize, true, true, false, false, false, false, true,
0, ENABLE_FOAF);
totalNodes++;
Logger.normal(RealNodeRoutingTest.class, "Created 'B' node
"+totalNodes);
}
for(int i=0;i<BRIDGES;i++) {
allNodes[totalNodes] =
bridges[i] =
- NodeStarter.createTestNode(5001+totalNodes, wd, false,
true, true, MAX_HTL, 0 /* no dropped packets */, random, executor,
500*NUMBER_OF_NODES, storeSize, true, true, false, false, false, false, true,
0,ENABLE_FOAF);
+ NodeStarter.createTestNode(5001+totalNodes, 0, wd,
false, true, true, MAX_HTL, 0 /* no dropped packets */, random, executor,
500*NUMBER_OF_NODES, storeSize, true, true, false, false, false, false, true,
0,ENABLE_FOAF);
totalNodes++;
Logger.normal(RealNodeRoutingTest.class, "Created bridge node
"+totalNodes);
}
Modified: trunk/freenet/src/freenet/node/simulator/RealNodePingTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodePingTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodePingTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -33,8 +33,8 @@
RandomSource random = NodeStarter.globalTestInit("pingtest", false,
Logger.ERROR, "");
// Create 2 nodes
Executor executor = new PooledExecutor();
- Node node1 = NodeStarter.createTestNode(5001, "pingtest", false,
false, true, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 65536, true,
false, false, false, false, false, true, 0, false);
- Node node2 = NodeStarter.createTestNode(5002, "pingtest", false,
false, true, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 65536, true,
false, false, false, false, false, true, 0, false);
+ Node node1 = NodeStarter.createTestNode(5001, 0, "pingtest", false,
false, true, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 65536, true,
false, false, false, false, false, true, 0, false);
+ Node node2 = NodeStarter.createTestNode(5002, 0, "pingtest", false,
false, true, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 65536, true,
false, false, false, false, false, true, 0, false);
// Connect
node1.connect(node2);
node2.connect(node1);
Modified:
trunk/freenet/src/freenet/node/simulator/RealNodeRequestInsertTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeRequestInsertTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeRequestInsertTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -75,7 +75,7 @@
Executor executor = new PooledExecutor();
for(int i=0;i<NUMBER_OF_NODES;i++) {
nodes[i] =
- NodeStarter.createTestNode(5001+i, name, false, true, false,
MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, 256*1024, true,
ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES,
ENABLE_SWAP_QUEUEING, ENABLE_PACKET_COALESCING, 12000, ENABLE_FOAF);
+ NodeStarter.createTestNode(5001+i, 0, name, false, true, false,
MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, 256*1024, true,
ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES,
ENABLE_SWAP_QUEUEING, ENABLE_PACKET_COALESCING, 12000, ENABLE_FOAF);
Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
}
Modified: trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -56,7 +56,7 @@
Executor executor = new PooledExecutor();
for(int i = 0; i < NUMBER_OF_NODES; i++) {
System.err.println("Creating node " + i);
- nodes[i] = NodeStarter.createTestNode(5001 + i, dir,
false, true, true, MAX_HTL, 0 /* no dropped packets */, random, executor, 500 *
NUMBER_OF_NODES, 65536, true, ENABLE_SWAPPING, false, false, false,
ENABLE_SWAP_QUEUEING, true, 0, ENABLE_FOAF);
+ nodes[i] = NodeStarter.createTestNode(5001 + i, 0, dir,
false, true, true, MAX_HTL, 0 /* no dropped packets */, random, executor, 500 *
NUMBER_OF_NODES, 65536, true, ENABLE_SWAPPING, false, false, false,
ENABLE_SWAP_QUEUEING, true, 0, ENABLE_FOAF);
Logger.normal(RealNodeRoutingTest.class, "Created node
" + i);
}
Logger.normal(RealNodeRoutingTest.class, "Created " +
NUMBER_OF_NODES + " nodes");
Modified: trunk/freenet/src/freenet/node/simulator/RealNodeSecretPingTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeSecretPingTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeSecretPingTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -66,7 +66,7 @@
for(int i=0;i<NUMBER_OF_NODES;i++) {
nodes[i] =
- NodeStarter.createTestNode(5001+i, wd, false, true, true,
MAX_HTL, 0 /* no dropped packets */, random, executor, 500*NUMBER_OF_NODES,
storeSize, true, true, false, false, false, true, true, 0, true);
+ NodeStarter.createTestNode(5001+i, 0, wd, false, true, true,
MAX_HTL, 0 /* no dropped packets */, random, executor, 500*NUMBER_OF_NODES,
storeSize, true, true, false, false, false, true, true, 0, true);
Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
}
Logger.normal(RealNodeRoutingTest.class, "Created "+NUMBER_OF_NODES+"
nodes");
Modified: trunk/freenet/src/freenet/node/simulator/RealNodeULPRTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeULPRTest.java
2008-07-21 21:47:08 UTC (rev 21298)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeULPRTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -93,7 +93,7 @@
Executor executor = new PooledExecutor();
for(int i=0;i<NUMBER_OF_NODES;i++) {
nodes[i] =
- NodeStarter.createTestNode(5000+i, testName, false, true, true,
MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, 1024*1024, true,
ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES, true,
true, 0, ENABLE_FOAF);
+ NodeStarter.createTestNode(5000+i, 0, testName, false, true,
true, MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, 1024*1024,
true, ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES,
true, true, 0, ENABLE_FOAF);
Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
}
SimpleFieldSet refs[] = new SimpleFieldSet[NUMBER_OF_NODES];
Added: trunk/freenet/src/freenet/node/simulator/SeednodePingTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/SeednodePingTest.java
(rev 0)
+++ trunk/freenet/src/freenet/node/simulator/SeednodePingTest.java
2008-07-21 23:10:14 UTC (rev 21299)
@@ -0,0 +1,88 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.node.simulator;
+
+import freenet.crypt.RandomSource;
+import freenet.io.comm.NotConnectedException;
+import freenet.io.comm.PeerParseException;
+import freenet.io.comm.ReferenceSignatureVerificationException;
+import freenet.node.Announcer;
+import freenet.node.FSParseException;
+import freenet.node.Node;
+import freenet.node.NodeInitException;
+import freenet.node.NodeStarter;
+import freenet.node.OpennetDisabledException;
+import freenet.node.SeedServerPeerNode;
+import freenet.support.Executor;
+import freenet.support.Logger;
+import freenet.support.PooledExecutor;
+import freenet.support.LoggerHook.InvalidThresholdException;
+import freenet.support.SimpleFieldSet;
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+
+/**
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ */
+public class SeednodePingTest extends RealNodeTest {
+
+ public static void main(String[] args) throws FSParseException,
IOException, OpennetDisabledException, PeerParseException,
InterruptedException, ReferenceSignatureVerificationException,
NodeInitException, InvalidThresholdException {
+ RandomSource random = NodeStarter.globalTestInit("seednode-pingtest",
false, Logger.ERROR, "");
+ // Create one node
+ Executor executor = new PooledExecutor();
+ Node node = NodeStarter.createTestNode(5000, 5001, "seednode-pingtest",
true, false, false, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000,
5*1024*1024, true, false, false, false, false, false, false, 0, false);
+
+ // Connect & ping
+ Vector<SeedServerPeerNode> seedNodes = new Vector<SeedServerPeerNode>();
+ Vector<SimpleFieldSet> seedNodesAsSFS = Announcer.readSeednodes(new
File("/tmp/"));
+ int numberOfNodesInTheFile = 0;
+ for(SimpleFieldSet sfs : seedNodesAsSFS) {
+ numberOfNodesInTheFile++;
+ SeedServerPeerNode seednode =
node.createNewSeedServerPeerNode(sfs);
+ try {
+ node.connectToSeednode(seednode);
+ seedNodes.add(seednode);
+ } catch (Exception fse) {
+ System.out.println("ERROR adding "+seednode.toString()+
" "+fse.getMessage());
+ }
+ }
+ if(seedNodes.size() != numberOfNodesInTheFile)
+ System.out.println("ERROR ADDING SOME OF THE SEEDNODES!!");
+ System.out.println("Let some time for the "+ seedNodes.size() +" nodes
to connect...");
+
+ // Start it
+ node.start(true);
+ //Logger.setupStdoutLogging(Logger.MINOR,
"freenet:NORMAL,freenet.node.FNPPacketMangler:MINOR");
+ Logger.getChain().setThreshold(32); // kill logging
+ Thread.sleep(10000);
+
+ int pingID = 0;
+ while(true) {
+ int countConnectedSeednodes = 0;
+ for(SeedServerPeerNode seednode : seedNodes) {
+ try {
+ boolean isSigValid =
seednode.isSignatureVerificationSuccessfull();
+ boolean isRoutingCompatible =
seednode.isRoutingCompatible();
+ double pingTime = seednode.averagePingTime();
+ int uptime = seednode.getUptime();
+ if(seednode.isRealConnection())
+ continue;
+ countConnectedSeednodes++;
+ boolean ping = seednode.ping(pingID++);
+ System.out.println(seednode.getIdentityString()
+ " is sigValid=" + isSigValid + " isRoutingCompat=" + isRoutingCompatible + "
uptime=" + uptime + " pingTime=" + pingTime+ " uptime="+seednode.getUptime() +
" ping="+ping);
+ // sanity check
+// if(seednode.isRoutable())
+// System.out.println(seednode + " is routable!");
+// if(seednode.canAcceptAnnouncements())
+// System.out.println(seednode + " can't accept
announcements!");
+ } catch (NotConnectedException e) {
+ System.out.println(seednode.getIdentityString()
+ " is not connected "+seednode.getHandshakeCount());
+ }
+ }
+ System.out.println("##################
("+node.peers.countConnectedPeers()+")
"+countConnectedSeednodes+'/'+node.peers.countSeednodes());
+ Thread.sleep(5000);
+ }
+ }
+}