java.lang.Object
net.i2p.i2ptunnel.I2PTunnelRunner.ResumeBudget
Enclosing class:
I2PTunnelRunner

static final class I2PTunnelRunner.ResumeBudgetextends Object
Progress-based budget for body-resume cycles. Pure decision state so the I2PTunnelRunner.resumeIncompleteBody(OutputStream) loop stays thin and tests can pin stall-reset and absolute-cap behaviour without a live transfer.

Only consecutive no-progress cycles count against the size-scaled stall cap (I2PTunnelRunner.stallCycleLimit(long); baseline I2PTunnelRunner.MAX_EMPTY_RECONNECT_CYCLES); any forward progress resets that counter. I2PTunnelRunner.totalCycleLimit(long) bounds total attempts regardless of progress so a pathological trickle still terminates.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Clock
    The clock for the deadline checks.
    private final long
    Total time the watchdog allows.
    private long
    Byte count seen at the last check.
    private int
    Watchdog cycles seen with no data.
    private int
    Watchdog cycles counted so far.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Budget bounded by cycle caps alone, for callers that want the historical behaviour and tests that pin the cycle arithmetic.
    ResumeBudget(long deadlineMs)
    Budget bounded by wall clock, so a stalled tunnel cannot spend the sequence, or I2PTunnelRunner.NO_DEADLINE to rely on the cycle caps alone.
    ResumeBudget(long deadlineMs, Clock clock)
    When a deadline is actually set (so the cycle-only path costs no clock lookup at all).
    Production constructor: bounds the sequence by wall clock as well as by cycle count.
  • Method Summary

    Private Methods
    Modifier and Type
    Method
    Description
    private long
    Returns the current time for the watchdog.
    (package private) int
    Stall cycles consumed so far (including the in-flight one).
    (package private) int
    Total resume attempts consumed so far.
    (package private) void
    Refund the last consume's stall charge when a resume attempt failed with a transient status (408/502/503/504) rather than a real stall.
    (package private) boolean
    tryConsume(long bodyReceived, long contentLength)
    Consume one resume cycle for the given body progress.

    Methods inherited from class Object

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

    • stallCycles

      private int stallCycles
      Watchdog cycles seen with no data.
    • totalCycles

      private int totalCycles
      Watchdog cycles counted so far.
    • lastBody

      private long lastBody
      Byte count seen at the last check.
    • deadlineMs

      private final long deadlineMs
      Total time the watchdog allows.
    • _clock

      private final Clock _clock
      The clock for the deadline checks.
  • Constructor Details

    • ResumeBudget

      ResumeBudget()
      Budget bounded by cycle caps alone, for callers that want the historical behaviour and tests that pin the cycle arithmetic.
    • ResumeBudget

      ResumeBudget(long deadlineMs)
      Budget bounded by wall clock, so a stalled tunnel cannot spend the sequence, or I2PTunnelRunner.NO_DEADLINE to rely on the cycle caps alone.
      Parameters:
      deadlineMs - absolute wall-clock deadline for the whole resume
    • ResumeBudget

      ResumeBudget(Clock clock)
      Production constructor: bounds the sequence by wall clock as well as by cycle count.
      Parameters:
      clock - the context clock, used for the deadline only
    • ResumeBudget

      ResumeBudget(long deadlineMs, Clock clock)
      When a deadline is actually set (so the cycle-only path costs no clock lookup at all).
      Parameters:
      deadlineMs - absolute wall-clock deadline, or I2PTunnelRunner.NO_DEADLINE
      clock - clock to read, or null to read the system clock only
  • Method Details

    • tryConsume

      boolean tryConsume(long bodyReceived, long contentLength)
      Consume one resume cycle for the given body progress.
      Parameters:
      bodyReceived - entity-body bytes delivered so far
      contentLength - entity Content-Length in bytes, or -1 if unknown; scales both caps
      Returns:
      true if another resume attempt may proceed
    • _nowMs

      private long _nowMs()
      Returns the current time for the watchdog.
      Returns:
      the time, in ms
    • getStallCycles

      int getStallCycles()
      Stall cycles consumed so far (including the in-flight one).
      Returns:
      the number of stall cycles this budget has burned
    • getTotalCycles

      int getTotalCycles()
      Total resume attempts consumed so far.
      Returns:
      the number of resume attempts this budget has burned
    • refundLast

      void refundLast()
      Refund the last consume's stall charge when a resume attempt failed with a transient status (408/502/503/504) rather than a real stall. A gateway timeout must not eat the empty/stall budget, or the next non-Range retry would be blocked for an unrelated reason.

      Only the stall charge is refunded. The total count stays consumed so I2PTunnelRunner.totalCycleLimit(long) remains an absolute cap over ALL attempts; refunding it would let a persistently transient-failing upstream reconnect forever.