Author: nextgens
Date: 2008-08-01 20:45:14 +0000 (Fri, 01 Aug 2008)
New Revision: 21569
Modified:
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/NodeStarter.java
Log:
Pass the weakRandom in the Node's constructor so that both PRNGs can be set to
the same source for simulation purposes
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2008-08-01 20:37:10 UTC (rev
21568)
+++ trunk/freenet/src/freenet/node/Node.java 2008-08-01 20:45:14 UTC (rev
21569)
@@ -611,10 +611,12 @@
* @param random The random number generator for this node. Passed in
because we may want
* to use a non-secure RNG for e.g. one-JVM live-code simulations.
Should be a Yarrow in
* a production node. Yarrow will be used if that parameter is null
+ * @param weakRandom The fast random number generator the node will
use. If null a MT
+ * instance will be used, seeded from the secure PRNG.
* @param the loggingHandler
* @throws NodeInitException If the node initialization fails.
*/
- Node(PersistentConfig config, RandomSource r, LoggingConfigHandler lc,
NodeStarter ns, Executor executor) throws NodeInitException {
+ Node(PersistentConfig config, RandomSource r, RandomSource weakRandom,
LoggingConfigHandler lc, NodeStarter ns, Executor executor) throws
NodeInitException {
// Easy stuff
logMINOR = Logger.shouldLog(Logger.MINOR, this);
String tmp = "Initializing Node using Freenet Build
#"+Version.buildNumber()+" r"+Version.cvsRevision+" and freenet-ext Build
#"+NodeStarter.extBuildNumber+" r"+NodeStarter.extRevisionNumber+" with
"+System.getProperty("java.vendor")+" JVM version
"+System.getProperty("java.version")+" running on
"+System.getProperty("os.arch")+' '+System.getProperty("os.name")+'
'+System.getProperty("os.version");
@@ -698,13 +700,17 @@
entropyGatheringThread.start();
this.random = new Yarrow();
DiffieHellman.init(random);
+
} else // if it's not null it's because we are running in the
simulator
this.random = r;
isPRNGReady = true;
toadlets.getStartupToadlet().setIsPRNGReady();
- byte buffer[] = new byte[16];
- random.nextBytes(buffer);
- this.fastWeakRandom = new MersenneTwister(buffer);
+ if(weakRandom == null) {
+ byte buffer[] = new byte[16];
+ random.nextBytes(buffer);
+ this.fastWeakRandom = new MersenneTwister(buffer);
+ }else
+ this.fastWeakRandom = weakRandom;
nodeNameUserAlert = new MeaningfulNodeNameUserAlert(this);
recentlyCompletedIDs = new LRUQueue();
Modified: trunk/freenet/src/freenet/node/NodeStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStarter.java 2008-08-01 20:37:10 UTC
(rev 21568)
+++ trunk/freenet/src/freenet/node/NodeStarter.java 2008-08-01 20:45:14 UTC
(rev 21569)
@@ -149,7 +149,7 @@
SSL.init(sslConfig);
try {
- node = new Node(cfg, null, logConfigHandler, this,
executor);
+ node = new Node(cfg, null, null, logConfigHandler,
this, executor);
node.start(false);
System.out.println("Node initialization completed.");
} catch(NodeInitException e) {
@@ -396,7 +396,7 @@
PersistentConfig config = new PersistentConfig(configFS);
- Node node = new Node(config, random, null, null, executor);
+ Node node = new Node(config, random, random, null, null,
executor);
//All testing environments connect the nodes as they want, even
if the old setup is restored, it is not desired.
node.peers.removeAllPeers();