Class PendingAcks

java.lang.Object
io.github.mahmoudimus.quic.connection.PendingAcks

public final class PendingAcks extends Object
The packets of one space waiting to be acknowledged, and when an ACK must go out (RFC 9000 section 13.2): after more than ack_eliciting_threshold ack-eliciting packets (one, by default, so every second one is acknowledged at once), on reordering, or once max_ack_delay has passed since the first unacknowledged ack-eliciting packet.

At most 64 ranges are kept, so an ACK frame always fits a minimum-size packet; the oldest are dropped first.

Threads. Not thread-safe; owned by one connection.

  • Field Details

    • MAX_ACK_BLOCKS

      public static final int MAX_ACK_BLOCKS
      The most ACK ranges kept.
      See Also:
  • Constructor Details

    • PendingAcks

      public PendingAcks()
      Nothing to acknowledge.
  • Method Details

    • setAckFrequencyParams

      public void setAckFrequencyParams(Frame.AckFrequency frame)
      Applies an ACK_FREQUENCY frame's thresholds.
      Parameters:
      frame - the frame
    • setImmediateAckRequired

      public void setImmediateAckRequired()
      Requires an immediate ACK, as for an IMMEDIATE_ACK frame or an ECN-CE mark.
    • onMaxAckDelayTimeout

      public void onMaxAckDelayTimeout()
      Handles the expiry of the Timer.MAX_ACK_DELAY timer.
    • maxAckDelayTimeout

      public long maxAckDelayTimeout(long maxAckDelay)
      When an ACK is due because max_ack_delay expires.
      Parameters:
      maxAckDelay - this endpoint's max_ack_delay, in nanoseconds
      Returns:
      the deadline, or NanoClock.NONE if no ack-eliciting packet is unacknowledged
    • canSend

      public boolean canSend()
      Whether an ACK must be sent, even in a packet of its own.
      Returns:
      true if one is required and there is something to acknowledge
    • canSendWithOtherFrames

      public boolean canSendWithOtherFrames()
      Whether an ACK can ride along in a packet sent for other reasons.
      Returns:
      true if there is something to acknowledge
    • ackDelay

      public long ackDelay(long now)
      The time since the largest packet arrived, for the ACK Delay field.
      Parameters:
      now - the current time
      Returns:
      nanoseconds, zero if nothing was received
    • packetReceived

      public boolean packetReceived(long now, long packetNumber, boolean ackEliciting, Dedup dedup)
      Handles a received packet's ACK requirements; call insertOne(long, long) for it too.
      Parameters:
      now - the current time
      packetNumber - the packet number
      ackEliciting - whether the packet is ack-eliciting
      dedup - the space's duplicate detector, which already holds the packet
      Returns:
      true if the Timer.MAX_ACK_DELAY timer should be armed
    • acksSent

      public void acksSent()
      Records that an ACK was sent, suppressing more until new ack-eliciting packets arrive. The ACK is assumed to have covered everything; anything it missed is acknowledged later.
    • insertOne

      public void insertOne(long packet, long now)
      Adds a packet to acknowledge.
      Parameters:
      packet - the packet number
      now - when it arrived
    • subtractBelow

      public void subtractBelow(long max)
      Stops acknowledging packets numbered at or below max: the peer received an ACK of them.
      Parameters:
      max - the largest packet number to drop
    • ranges

      public RangeSet ranges()
      The packet numbers to acknowledge.
      Returns:
      a live view; do not modify
    • maybeAckNonEliciting

      public void maybeAckNonEliciting()
      Requires an ACK in the next packet if many non-ack-eliciting packets went unacknowledged, which helps a peer that sends nothing ack-eliciting detect loss. Call it just before building a packet that will be sent anyway.
    • ackFrame

      public Frame.Ack ackFrame(long now, long ackDelayExponent, Frame.EcnCounts ecn)
      Builds the ACK frame for the pending ranges.
      Parameters:
      now - the current time
      ackDelayExponent - this endpoint's ack_delay_exponent
      ecn - the ECN counts to report, or null
      Returns:
      the frame, or null if there is nothing to acknowledge