forked from I2P_Developers/i2p.i2p
* 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
This commit is contained in:
@ -139,15 +139,20 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl
|
|||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
doFill(aBuff.buffer);
|
doFill(aBuff.buffer);
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
|
boolean shouldWait = _fullBuffers.size() > 1;
|
||||||
_fullBuffers.offer(aBuff);
|
_fullBuffers.offer(aBuff);
|
||||||
_context.statManager().addRateData("prng.bufferFillTime", after - before, 0);
|
_context.statManager().addRateData("prng.bufferFillTime", after - before, 0);
|
||||||
|
if (shouldWait) {
|
||||||
Thread.yield();
|
Thread.yield();
|
||||||
long waitTime = (after-before)*5;
|
long waitTime = (after-before)*5;
|
||||||
if (waitTime <= 0) // somehow postman saw waitTime show up as negative
|
if (waitTime <= 0) // somehow postman saw waitTime show up as negative
|
||||||
waitTime = 50;
|
waitTime = 50;
|
||||||
|
else if (waitTime > 5000)
|
||||||
|
waitTime = 5000;
|
||||||
try { Thread.sleep(waitTime); } catch (InterruptedException ie) {}
|
try { Thread.sleep(waitTime); } catch (InterruptedException ie) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillBlock()
|
public void fillBlock()
|
||||||
|
@ -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[]) {
|
public static void main(String args[]) {
|
||||||
try {
|
try {
|
||||||
RandomSource rand = I2PAppContext.getGlobalContext().random();
|
java.util.Properties props = new java.util.Properties();
|
||||||
if (true) {
|
props.setProperty("prng.buffers", "12");
|
||||||
for (int i = 0; i < 1000; i++)
|
I2PAppContext ctx = new I2PAppContext(props);
|
||||||
if (rand.nextFloat() < 0)
|
RandomSource rand = ctx.random();
|
||||||
throw new RuntimeException("negative!");
|
byte[] buf = new byte[65536];
|
||||||
System.out.println("All positive");
|
while (true) {
|
||||||
return;
|
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(); }
|
} catch (Exception e) { e.printStackTrace(); }
|
||||||
}
|
}
|
||||||
*****/
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
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
|
2012-07-19 zab
|
||||||
* Streaming:
|
* Streaming:
|
||||||
- initialize streaming RTT from sample, trac #979, RFC 6298
|
- initialize streaming RTT from sample, trac #979, RFC 6298
|
||||||
|
Reference in New Issue
Block a user