Author: nextgens
Date: 2008-07-18 15:50:32 +0000 (Fri, 18 Jul 2008)
New Revision: 21211

Modified:
   trunk/freenet/src/freenet/clients/http/StartupToadlet.java
   trunk/freenet/src/freenet/node/Node.java
Log:
Generate some disk accesses in case we can't get enough entropy from the OS' 
PRNG to seed Yarrow

Modified: trunk/freenet/src/freenet/clients/http/StartupToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StartupToadlet.java  2008-07-18 
13:59:27 UTC (rev 21210)
+++ trunk/freenet/src/freenet/clients/http/StartupToadlet.java  2008-07-18 
15:50:32 UTC (rev 21211)
@@ -20,6 +20,7 @@
                this.staticToadlet = staticToadlet;
        }

+       @Override
        public void handleGet(URI uri, HTTPRequest req, ToadletContext ctx) 
throws ToadletContextClosedException, IOException, RedirectException {
                // If we don't disconnect we will have pipelining issues
                ctx.forceDisconnect();

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2008-07-18 13:59:27 UTC (rev 
21210)
+++ trunk/freenet/src/freenet/node/Node.java    2008-07-18 15:50:32 UTC (rev 
21211)
@@ -118,6 +118,7 @@
 import freenet.support.io.FileUtil;
 import freenet.support.io.NativeThread;
 import freenet.support.transport.ip.HostnameSyntaxException;
+import java.io.FileFilter;

 /**
  * @author amphibian
@@ -483,6 +484,8 @@
         */
        private static final int MIN_UPTIME_STORE_KEY = 40;

+       private volatile boolean isPRNGReady = false;
+       
        /**
         * Read all storable settings (identity etc) from the node file.
         * @param filename The name of the file to read from.
@@ -662,13 +665,42 @@
                }

                // Setup RNG if needed : DO NOT USE IT BEFORE THAT POINT!
-               this.random = (r == null ? new Yarrow() : r);
-               if(r == null) // if it's not null it's because we are running 
in the simulator
+               if(r == null) {
+                       final NativeThread entropyGatheringThread = new 
NativeThread(new Runnable() {
+
+                               private void recurse(File f) {
+                                       if(isPRNGReady)
+                                               return;
+                                       File[] subDirs = f.listFiles(new 
FileFilter() {
+
+                                               public boolean accept(File 
pathname) {
+                                                       return 
pathname.exists() && pathname.canRead() && pathname.isDirectory();
+                                               }
+                                       });
+
+                                       for(File currentDir : subDirs)
+                                               recurse(currentDir);
+                               }
+
+                               public void run() {
+                                       for(File root : File.listRoots()) {
+                                               if(isPRNGReady)
+                                                       return;
+                                               recurse(root);
+                                       }
+                               }
+                       }, "Entropy Gathering Thread", 
NativeThread.MIN_PRIORITY, true);
+
+                       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);
-               toadlets.getStartupToadlet().setIsPRNGReady();

                nodeNameUserAlert = new MeaningfulNodeNameUserAlert(this);
                recentlyCompletedIDs = new LRUQueue();


Reply via email to