java.lang.Object
net.i2p.crypto.YKGenerator.YKPrecalcRunner
All Implemented Interfaces:
Runnable
Enclosing class:
YKGenerator

private class YKGenerator.YKPrecalcRunnerextends Object implements Runnable
Precalculation thread.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
    Check every 30 seconds whether fewer than the minimum YK pairs remain.
    private long
    Wall clock time at the end of the previous cycle.
    private int
    Pool occupancy at the end of the previous cycle.
    private final int
    Largest size of the value queue.
    private final int
    Smallest size of the value queue.
    private static final int
    Refill headroom for a pool that saw no consumption yet, covering the jitter between a drain and this thread noticing it.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    YKPrecalcRunner(int minSize, int maxSize)
    Builds one precalculation runner.
  • Method Summary

    Modifier and Type
    Method
    Description
    private int
    refillTarget(int drained, long elapsedMs)
    How far above the minimum to refill: scoped to one check interval's worth of observed consumption, so the expensive modular exponentiations track real demand.
    void
    run()
    Precalculate YK pairs until the generator is stopped.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_SLACK

      private static final int MIN_SLACK
      Refill headroom for a pool that saw no consumption yet, covering the jitter between a drain and this thread noticing it.
      See Also:
    • _minSize

      private final int _minSize
      Smallest size of the value queue.
    • _maxSize

      private final int _maxSize
      Largest size of the value queue.
    • _checkDelay

      private long _checkDelay
      Check every 30 seconds whether fewer than the minimum YK pairs remain.
    • _lastSize

      private int _lastSize
      Pool occupancy at the end of the previous cycle.
    • _lastSample

      private long _lastSample
      Wall clock time at the end of the previous cycle.
  • Constructor Details

    • YKPrecalcRunner

      private YKPrecalcRunner(int minSize, int maxSize)
      Builds one precalculation runner.
      Parameters:
      minSize - the smallest size of the value queue
      maxSize - the largest size of the value queue
  • Method Details

    • run

      public void run()
      Precalculate YK pairs until the generator is stopped.
      Specified by:
      run in interface Runnable
    • refillTarget

      private int refillTarget(int drained, long elapsedMs)
      How far above the minimum to refill: scoped to one check interval's worth of observed consumption, so the expensive modular exponentiations track real demand. Only consulted once the pool is already below the minimum, so it never changes when a refill starts, only how far it goes.
      Parameters:
      drained - how many values the pool lost since the previous cycle
      elapsedMs - how long ago the previous cycle ended
      Returns:
      the size to fill to, never above the configured maximum