net.i2p.router.transport

## Class FIFOBandwidthRefiller

- java.lang.Object
- - net.i2p.router.transport.FIFOBandwidthRefiller

- All Implemented Interfaces:
    Runnable

      public class FIFOBandwidthRefiller
      extends Object
      implements Runnable

  Bandwidth token refiller for FIFO-based bandwidth limiting. This thread periodically refills bandwidth token buckets for the FIFOBandwidthLimiter. It runs independently to ensure tokens are available at regular intervals, preventing traffic starvation and maintaining consistent throughput. Refill Strategy:
  - Fixed interval token replenishment
  - Configurable refill rates and amounts
  - Separate inbound and outbound bandwidth tracking
  - Participating bandwidth counter (since 0.8.12)
  - Thread-safe operations with atomic counters
  Configuration:
  - Configurable inbound bandwidth limits (KBps)
  - Configurable outbound bandwidth limits (KBps)
  - Adjustable refill intervals and amounts
  - System property integration for defaults
  Thread Safety:
  - Atomic counters for bandwidth tracking
  - Thread-safe refill operations
  - Non-blocking queue operations
  Note: This class was originally created to provide a dedicated thread for bandwidth refilling when the main limiter needed thread resources. As of 0.8.12, it also includes participating bandwidth counter functionality. Public only for properties and defaults.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_BURST_SECONDS`
    `static int` | `DEFAULT_INBOUND_BANDWIDTH`
    `static int` | `DEFAULT_INBOUND_BURST_BANDWIDTH`
    `static int` | `DEFAULT_OUTBOUND_BANDWIDTH` Caution, do not make DEFAULT_OUTBOUND_BANDWIDTH * DEFAULT_SHARE_PCT > 32 without thinking about the implications (default connection limits, for example) of moving the default bandwidth class from L to M, or maybe adjusting bandwidth class boundaries.
    `static int` | `DEFAULT_OUTBOUND_BURST_BANDWIDTH`
    `static int` | `MAX_OUTBOUND_BANDWIDTH` Max for reasonable Bloom filter false positive rate.
    `static int` | `MIN_INBOUND_BANDWIDTH` For now, until there is some tuning and safe throttling, we set the floor at this inbound (KBps)
    `static int` | `MIN_INBOUND_BANDWIDTH_PEAK` For now, until there is some tuning and safe throttling, we set the floor at this during burst (KBps)
    `static int` | `MIN_OUTBOUND_BANDWIDTH` For now, until there is some tuning and safe throttling, we set the floor at this outbound (KBps)
    `static int` | `MIN_OUTBOUND_BANDWIDTH_PEAK` For now, until there is some tuning and safe throttling, we set the floor at this during burst (KBps)
    `static String` | `PROP_INBOUND_BANDWIDTH`
    `static String` | `PROP_INBOUND_BANDWIDTH_PEAK`
    `static String` | `PROP_INBOUND_BURST_BANDWIDTH`
    `static String` | `PROP_OUTBOUND_BANDWIDTH`
    `static String` | `PROP_OUTBOUND_BANDWIDTH_PEAK`
    `static String` | `PROP_OUTBOUND_BURST_BANDWIDTH`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FIFOBandwidthRefiller(RouterContext context, FIFOBandwidthLimiter limiter)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) int` | `getCurrentParticipatingBandwidth()` Out bandwidth.
    `(package private) int` | `getInboundBurstKBytesPerSecond()`
    `(package private) int` | `getInboundKBytesPerSecond()`
    `(package private) int` | `getMaxShareBandwidth()` In Bytes per second
    `(package private) int` | `getOutboundBurstKBytesPerSecond()`
    `(package private) int` | `getOutboundKBytesPerSecond()`
    `(package private) boolean` | `incrementParticipatingMessageBytes(int size, float factor)` We intend to send traffic for a participating tunnel with the given size and adjustment factor.
    `(package private) void` | `reinitialize()`
    `void` | `run()`
    `(package private) void` | `shutdown()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_BURST_SECONDS

          public static final int DEFAULT_BURST_SECONDS

      See Also:
        Constant Field Values

    - #### DEFAULT_INBOUND_BANDWIDTH

          public static final int DEFAULT_INBOUND_BANDWIDTH

      See Also:
        Constant Field Values

    - #### DEFAULT_INBOUND_BURST_BANDWIDTH

          public static final int DEFAULT_INBOUND_BURST_BANDWIDTH

      See Also:
        Constant Field Values

    - #### DEFAULT_OUTBOUND_BANDWIDTH

          public static final int DEFAULT_OUTBOUND_BANDWIDTH

      Caution, do not make DEFAULT_OUTBOUND_BANDWIDTH * DEFAULT_SHARE_PCT > 32 without thinking about the implications (default connection limits, for example) of moving the default bandwidth class from L to M, or maybe adjusting bandwidth class boundaries.
      See Also:
        Constant Field Values

    - #### DEFAULT_OUTBOUND_BURST_BANDWIDTH

          public static final int DEFAULT_OUTBOUND_BURST_BANDWIDTH

      See Also:
        Constant Field Values

    - #### MAX_OUTBOUND_BANDWIDTH

          public static final int MAX_OUTBOUND_BANDWIDTH

      Max for reasonable Bloom filter false positive rate. Do not increase without adding a new Bloom filter size! See util/DecayingBloomFilter and tunnel/BloomFilterIVValidator.

    - #### MIN_INBOUND_BANDWIDTH

          public static final int MIN_INBOUND_BANDWIDTH

      For now, until there is some tuning and safe throttling, we set the floor at this inbound (KBps)
      See Also:
        Constant Field Values

    - #### MIN_INBOUND_BANDWIDTH_PEAK

          public static final int MIN_INBOUND_BANDWIDTH_PEAK

      For now, until there is some tuning and safe throttling, we set the floor at this during burst (KBps)
      See Also:
        Constant Field Values

    - #### MIN_OUTBOUND_BANDWIDTH

          public static final int MIN_OUTBOUND_BANDWIDTH

      For now, until there is some tuning and safe throttling, we set the floor at this outbound (KBps)
      See Also:
        Constant Field Values

    - #### MIN_OUTBOUND_BANDWIDTH_PEAK

          public static final int MIN_OUTBOUND_BANDWIDTH_PEAK

      For now, until there is some tuning and safe throttling, we set the floor at this during burst (KBps)
      See Also:
        Constant Field Values

    - #### PROP_INBOUND_BANDWIDTH

          public static final String PROP_INBOUND_BANDWIDTH

      See Also:
        Constant Field Values

    - #### PROP_INBOUND_BANDWIDTH_PEAK

          public static final String PROP_INBOUND_BANDWIDTH_PEAK

      See Also:
        Constant Field Values

    - #### PROP_INBOUND_BURST_BANDWIDTH

          public static final String PROP_INBOUND_BURST_BANDWIDTH

      See Also:
        Constant Field Values

    - #### PROP_OUTBOUND_BANDWIDTH

          public static final String PROP_OUTBOUND_BANDWIDTH

      See Also:
        Constant Field Values

    - #### PROP_OUTBOUND_BANDWIDTH_PEAK

          public static final String PROP_OUTBOUND_BANDWIDTH_PEAK

      See Also:
        Constant Field Values

    - #### PROP_OUTBOUND_BURST_BANDWIDTH

          public static final String PROP_OUTBOUND_BURST_BANDWIDTH

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FIFOBandwidthRefiller

          FIFOBandwidthRefiller(RouterContext context,
                                FIFOBandwidthLimiter limiter)

  - ### Method Detail

    - #### getCurrentParticipatingBandwidth

          int getCurrentParticipatingBandwidth()

      Out bandwidth. Actual bandwidth, not smoothed, not bucketed.
      Returns:
        Bps in recent period (a few seconds)

    - #### getInboundBurstKBytesPerSecond

          int getInboundBurstKBytesPerSecond()

    - #### getInboundKBytesPerSecond

          int getInboundKBytesPerSecond()

    - #### getMaxShareBandwidth

          int getMaxShareBandwidth()

      In Bytes per second

    - #### getOutboundBurstKBytesPerSecond

          int getOutboundBurstKBytesPerSecond()

    - #### getOutboundKBytesPerSecond

          int getOutboundKBytesPerSecond()

    - #### incrementParticipatingMessageBytes

          boolean incrementParticipatingMessageBytes(int size,
                                                     float factor)

      We intend to send traffic for a participating tunnel with the given size and adjustment factor. Returns true if the message can be sent within the current share bandwidth limits, or false if it should be dropped.
      Parameters:
        `size` - bytes
        `factor` - multiplier of size for the drop calculation, 1 for no adjustment
      Returns:
        true for accepted, false for drop

    - #### reinitialize

          void reinitialize()

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### shutdown

          void shutdown()