- 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
This commit is contained in:
zzz
2013-07-19 21:31:25 +00:00
parent 8505e8a1ca
commit 554a3a6b0e
3 changed files with 32 additions and 26 deletions

View File

@ -139,15 +139,20 @@ 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);
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) {}
}
}
}
@Override
public void fillBlock()

View File

@ -262,27 +262,23 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
}
}
/*****
/**
* Outputs to stdout for dieharder:
* <code>
* java -cp build/i2p.jar net.i2p.util.FortunaRandomSource | dieharder -a -g 200
* </code>
*/
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(); }
}
*****/
}

View File

@ -1,5 +1,10 @@
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:
* Streaming:
- initialize streaming RTT from sample, trac #979, RFC 6298
- store rttDev in TCBCache