diff --git a/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java b/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java index ba68e3d148..148c2467c9 100644 --- a/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java +++ b/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java @@ -139,13 +139,18 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl long before = System.currentTimeMillis(); doFill(aBuff.buffer); long after = System.currentTimeMillis(); + boolean shouldWait = _fullBuffers.size() > 1; _fullBuffers.offer(aBuff); _context.statManager().addRateData("prng.bufferFillTime", after - before, 0); - Thread.yield(); - long waitTime = (after-before)*5; - if (waitTime <= 0) // somehow postman saw waitTime show up as negative - waitTime = 50; - try { Thread.sleep(waitTime); } catch (InterruptedException ie) {} + if (shouldWait) { + Thread.yield(); + long waitTime = (after-before)*5; + if (waitTime <= 0) // somehow postman saw waitTime show up as negative + waitTime = 50; + else if (waitTime > 5000) + waitTime = 5000; + try { Thread.sleep(waitTime); } catch (InterruptedException ie) {} + } } } diff --git a/core/java/src/net/i2p/util/FortunaRandomSource.java b/core/java/src/net/i2p/util/FortunaRandomSource.java index 2209785cf6..54a93b2a04 100644 --- a/core/java/src/net/i2p/util/FortunaRandomSource.java +++ b/core/java/src/net/i2p/util/FortunaRandomSource.java @@ -262,27 +262,23 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste } } -/***** + /** + * Outputs to stdout for dieharder: + * + * java -cp build/i2p.jar net.i2p.util.FortunaRandomSource | dieharder -a -g 200 + * + */ public static void main(String args[]) { try { - RandomSource rand = I2PAppContext.getGlobalContext().random(); - if (true) { - for (int i = 0; i < 1000; i++) - if (rand.nextFloat() < 0) - throw new RuntimeException("negative!"); - System.out.println("All positive"); - return; + java.util.Properties props = new java.util.Properties(); + props.setProperty("prng.buffers", "12"); + I2PAppContext ctx = new I2PAppContext(props); + RandomSource rand = ctx.random(); + byte[] buf = new byte[65536]; + while (true) { + rand.nextBytes(buf); + System.out.write(buf); } - java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); - java.util.zip.GZIPOutputStream gos = new java.util.zip.GZIPOutputStream(baos); - for (int i = 0; i < 1024*1024; i++) { - int c = rand.nextInt(256); - gos.write((byte)c); - } - gos.finish(); - byte compressed[] = baos.toByteArray(); - System.out.println("Compressed size of 1MB: " + compressed.length); } catch (Exception e) { e.printStackTrace(); } } -*****/ } diff --git a/history.txt b/history.txt index 706420e851..88cc03b33c 100644 --- a/history.txt +++ b/history.txt @@ -1,7 +1,12 @@ +2012-07-19 zzz + * PRNG: + - Don't delay the refiller if we need more (don't limit max output) + - Add FortunaRandomSource.main() to output to stdout for testing e.g. with dieharder + 2012-07-19 zab -* Streaming: - - initialize streaming RTT from sample, trac #979, RFC 6298 - - store rttDev in TCBCache + * Streaming: + - initialize streaming RTT from sample, trac #979, RFC 6298 + - store rttDev in TCBCache * 2013-07-15 0.9.7 released