Class PendingAcks
java.lang.Object
io.github.mahmoudimus.quic.connection.PendingAcks
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongackDelay(long now) The time since the largest packet arrived, for the ACK Delay field.ackFrame(long now, long ackDelayExponent, Frame.EcnCounts ecn) Builds the ACK frame for the pending ranges.voidacksSent()Records that an ACK was sent, suppressing more until new ack-eliciting packets arrive.booleancanSend()Whether an ACK must be sent, even in a packet of its own.booleanWhether an ACK can ride along in a packet sent for other reasons.voidinsertOne(long packet, long now) Adds a packet to acknowledge.longmaxAckDelayTimeout(long maxAckDelay) When an ACK is due becausemax_ack_delayexpires.voidRequires 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.voidHandles the expiry of theTimer.MAX_ACK_DELAYtimer.booleanpacketReceived(long now, long packetNumber, boolean ackEliciting, Dedup dedup) Handles a received packet's ACK requirements; callinsertOne(long, long)for it too.ranges()The packet numbers to acknowledge.voidApplies an ACK_FREQUENCY frame's thresholds.voidRequires an immediate ACK, as for an IMMEDIATE_ACK frame or an ECN-CE mark.voidsubtractBelow(long max) Stops acknowledging packets numbered at or belowmax: the peer received an ACK of them.
-
Field Details
-
MAX_ACK_BLOCKS
public static final int MAX_ACK_BLOCKSThe most ACK ranges kept.- See Also:
-
-
Constructor Details
-
PendingAcks
public PendingAcks()Nothing to acknowledge.
-
-
Method Details
-
setAckFrequencyParams
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 theTimer.MAX_ACK_DELAYtimer. -
maxAckDelayTimeout
public long maxAckDelayTimeout(long maxAckDelay) When an ACK is due becausemax_ack_delayexpires.- Parameters:
maxAckDelay- this endpoint'smax_ack_delay, in nanoseconds- Returns:
- the deadline, or
NanoClock.NONEif 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
Handles a received packet's ACK requirements; callinsertOne(long, long)for it too.- Parameters:
now- the current timepacketNumber- the packet numberackEliciting- whether the packet is ack-elicitingdedup- the space's duplicate detector, which already holds the packet- Returns:
- true if the
Timer.MAX_ACK_DELAYtimer 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 numbernow- when it arrived
-
subtractBelow
public void subtractBelow(long max) Stops acknowledging packets numbered at or belowmax: the peer received an ACK of them.- Parameters:
max- the largest packet number to drop
-
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
Builds the ACK frame for the pending ranges.- Parameters:
now- the current timeackDelayExponent- this endpoint'sack_delay_exponentecn- the ECN counts to report, or null- Returns:
- the frame, or null if there is nothing to acknowledge
-