Class FIFOBandwidthLimiter

java.lang.Object
net.i2p.router.transport.FIFOBandwidthLimiter

public class FIFOBandwidthLimiter extends Object
Concurrent plan: It's difficult to get rid of the locks on _pendingInboundRequests since locked_satisyInboundAvailable() leaves Requests on the head of the queue. When we go to Java 6, we can convert from a locked ArrayList to a LinkedBlockingDeque, where locked_sIA will poll() from the head of the queue, and if the request is not fully satisfied, offerFirst() (i.e. push) it back on the head. Ditto outbound of course. In the meantime, for Java 5, we have lockless 'shortcut' methods for the common case where we are under the bandwidth limits. And the volatile counters are now AtomicIntegers / AtomicLongs.
  • Constructor Details

    • FIFOBandwidthLimiter

      public FIFOBandwidthLimiter(RouterContext context)
  • Method Details

    • now

      public long now()
    • getTotalAllocatedInboundBytes

      public long getTotalAllocatedInboundBytes()
    • getTotalAllocatedOutboundBytes

      public long getTotalAllocatedOutboundBytes()
    • setInboundUnlimited

      @Deprecated void setInboundUnlimited(boolean isUnlimited)
      Deprecated.
      unused for now, we are always limited
    • setOutboundUnlimited

      @Deprecated void setOutboundUnlimited(boolean isUnlimited)
      Deprecated.
      unused for now, we are always limited
    • getSendBps

      public float getSendBps()
      Returns:
      smoothed one second rate
    • getReceiveBps

      public float getReceiveBps()
      Returns:
      smoothed one second rate
    • getSendBps15s

      public float getSendBps15s()
      Returns:
      smoothed 15 second rate
    • getReceiveBps15s

      public float getReceiveBps15s()
      Returns:
      smoothed 15 second rate
    • getOutboundKBytesPerSecond

      public int getOutboundKBytesPerSecond()
      The configured maximum, not the current rate. In binary K, i.e. rate / 1024.
    • getInboundKBytesPerSecond

      public int getInboundKBytesPerSecond()
      The configured maximum, not the current rate. In binary K, i.e. rate / 1024.
    • getOutboundBurstKBytesPerSecond

      public int getOutboundBurstKBytesPerSecond()
      The configured maximum, not the current rate. In binary K, i.e. rate / 1024.
    • getInboundBurstKBytesPerSecond

      public int getInboundBurstKBytesPerSecond()
      The configured maximum, not the current rate. In binary K, i.e. rate / 1024.
    • reinitialize

      public void reinitialize()
    • shutdown

      public void shutdown()
      Since:
      0.8.8
    • sentParticipatingMessage

      public boolean sentParticipatingMessage(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
      Since:
      0.8.12
    • getCurrentParticipatingBandwidth

      public int getCurrentParticipatingBandwidth()
      Out bandwidth. Actual bandwidth, not smoothed, not bucketed.
      Returns:
      Bps in recent period (a few seconds)
      Since:
      0.8.12
    • requestInbound

      public FIFOBandwidthLimiter.Request requestInbound(int bytesIn, String purpose)
      Request some bytes. Does not block.
    • requestOutbound

      public FIFOBandwidthLimiter.Request requestOutbound(int bytesOut, int priority, String purpose)
      Request some bytes. Does not block.
    • setInboundBurstKBps

      void setInboundBurstKBps(int kbytesPerSecond)
    • setOutboundBurstKBps

      void setOutboundBurstKBps(int kbytesPerSecond)
    • getInboundBurstBytes

      public int getInboundBurstBytes()
    • getOutboundBurstBytes

      public int getOutboundBurstBytes()
    • setInboundBurstBytes

      void setInboundBurstBytes(int bytes)
    • setOutboundBurstBytes

      void setOutboundBurstBytes(int bytes)
    • getStatus

      StringBuilder getStatus()
    • refillBandwidthQueues

      final void refillBandwidthQueues(List<FIFOBandwidthLimiter.Request> buf, long bytesInbound, long bytesOutbound, long maxBurstIn, long maxBurstOut)
      More bytes are available - add them to the queue and satisfy any requests we can
      Parameters:
      buf - contains satisfied outbound requests, really just to avoid object thrash, not really used
      maxBurstIn - allow up to this many bytes in from the burst section for this time period (may be negative)
      maxBurstOut - allow up to this many bytes in from the burst section for this time period (may be negative)
    • renderStatusHTML

      @Deprecated public void renderStatusHTML(Writer out) throws IOException
      Deprecated.
      not worth translating
      Throws:
      IOException