Changeset 554a3a6


Ignore:
Timestamp:
Jul 19, 2013 9:31:25 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
90cc71d
Parents:
8505e8a
Message:
  • 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
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java

    r8505e8a r554a3a6  
    140140                doFill(aBuff.buffer);
    141141                long after = System.currentTimeMillis();
     142                boolean shouldWait = _fullBuffers.size() > 1;
    142143                _fullBuffers.offer(aBuff);
    143144                _context.statManager().addRateData("prng.bufferFillTime", after - before, 0);
    144                 Thread.yield();
    145                 long waitTime = (after-before)*5;
    146                 if (waitTime <= 0) // somehow postman saw waitTime show up as negative
    147                     waitTime = 50;
    148                 try { Thread.sleep(waitTime); } catch (InterruptedException ie) {}
     145                if (shouldWait) {
     146                    Thread.yield();
     147                    long waitTime = (after-before)*5;
     148                    if (waitTime <= 0) // somehow postman saw waitTime show up as negative
     149                        waitTime = 50;
     150                    else if (waitTime > 5000)
     151                        waitTime = 5000;
     152                    try { Thread.sleep(waitTime); } catch (InterruptedException ie) {}
     153                }
    149154        }
    150155    }
  • core/java/src/net/i2p/util/FortunaRandomSource.java

    r8505e8a r554a3a6  
    263263    }
    264264   
    265 /*****
     265    /**
     266     *  Outputs to stdout for dieharder:
     267     *  <code>
     268     *  java -cp build/i2p.jar net.i2p.util.FortunaRandomSource | dieharder -a -g 200
     269     *  </code>
     270     */
    266271    public static void main(String args[]) {
    267272        try {
    268             RandomSource rand = I2PAppContext.getGlobalContext().random();
    269             if (true) {
    270                 for (int i = 0; i < 1000; i++)
    271                     if (rand.nextFloat() < 0)
    272                         throw new RuntimeException("negative!");
    273                 System.out.println("All positive");
    274                 return;
     273            java.util.Properties props = new java.util.Properties();
     274            props.setProperty("prng.buffers", "12");
     275            I2PAppContext ctx = new I2PAppContext(props);
     276            RandomSource rand = ctx.random();
     277            byte[] buf = new byte[65536];
     278            while (true) {
     279                rand.nextBytes(buf);
     280                System.out.write(buf);
    275281            }
    276             java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
    277             java.util.zip.GZIPOutputStream gos = new java.util.zip.GZIPOutputStream(baos);
    278             for (int i = 0; i < 1024*1024; i++) {
    279                 int c = rand.nextInt(256);
    280                 gos.write((byte)c);
    281             }
    282             gos.finish();
    283             byte compressed[] = baos.toByteArray();
    284             System.out.println("Compressed size of 1MB: " + compressed.length);
    285282        } catch (Exception e) { e.printStackTrace(); }
    286283    }
    287 *****/
    288284}
  • history.txt

    r8505e8a r554a3a6  
     12012-07-19 zzz
     2 * PRNG:
     3   - Don't delay the refiller if we need more (don't limit max output)
     4   - Add FortunaRandomSource.main() to output to stdout for testing e.g. with dieharder
     5
    162012-07-19 zab
    2 * Streaming:
    3   - initialize streaming RTT from sample, trac #979, RFC 6298
    4   - store rttDev in TCBCache
     7 * Streaming:
     8   - initialize streaming RTT from sample, trac #979, RFC 6298
     9   - store rttDev in TCBCache
    510
    611* 2013-07-15 0.9.7 released
Note: See TracChangeset for help on using the changeset viewer.