Class AckFrequencyState
java.lang.Object
io.github.mahmoudimus.quic.connection.AckFrequencyState
State of the QUIC ACK frequency extension, as quinn implements it: the
max_ack_delay the
peer uses (its transport parameter, or what we last asked for in an ACK_FREQUENCY frame once it
is acknowledged) and the one we use (ours, or what the peer asked for). Durations are
nanoseconds.
Without the extension this simply holds both endpoints' max_ack_delay.
Threads. Not thread-safe; owned by one connection.
-
Constructor Summary
ConstructorsConstructorDescriptionAckFrequencyState(long defaultMaxAckDelay) The state before any ACK_FREQUENCY frame. -
Method Summary
Modifier and TypeMethodDescriptionbooleanackFrequencyReceived(Frame.AckFrequency frame, PendingAcks pendingAcks) Applies a received ACK_FREQUENCY frame, unless an equal or newer one was applied already.voidackFrequencySent(long pn, long requestedMaxAckDelay) Records that a packet carried an ACK_FREQUENCY frame.longcandidateMaxAckDelay(long rtt, long configuredMaxAckDelay, long peerMinAckDelayMicros) Themax_ack_delayto ask the peer for: the configured one or the peer's own, at most the RTT (but not below 25 ms) and at least the peer'smin_ack_delay.longOurmax_ack_delay.longThemax_ack_delayto compute the PTO with: the larger of the peer's and any requested but unacknowledged one, which the peer may already use.longAllocates the next ACK_FREQUENCY sequence number.voidonAcked(long pn) Records an acknowledged application data packet; acknowledging the ACK_FREQUENCY frame makes its delay the peer's.longThe peer'smax_ack_delay.voidsetMaxAckDelay(long delay) Sets ourmax_ack_delay.voidsetPeerMaxAckDelay(long delay) Sets the peer'smax_ack_delay, from its transport parameters.booleanshouldSendAckFrequency(long rtt, long configuredMaxAckDelay, long peerMinAckDelayMicros) Whether to send an ACK_FREQUENCY frame: always first, then when the desired delay differs from the current request by more than 20%.
-
Constructor Details
-
AckFrequencyState
public AckFrequencyState(long defaultMaxAckDelay) The state before any ACK_FREQUENCY frame.- Parameters:
defaultMaxAckDelay- the defaultmax_ack_delay, 25 ms, used for both endpoints until their transport parameters are known
-
-
Method Details
-
peerMaxAckDelay
public long peerMaxAckDelay()The peer'smax_ack_delay.- Returns:
- nanoseconds
-
setPeerMaxAckDelay
public void setPeerMaxAckDelay(long delay) Sets the peer'smax_ack_delay, from its transport parameters.- Parameters:
delay- nanoseconds
-
maxAckDelay
public long maxAckDelay()Ourmax_ack_delay.- Returns:
- nanoseconds
-
setMaxAckDelay
public void setMaxAckDelay(long delay) Sets ourmax_ack_delay.- Parameters:
delay- nanoseconds
-
candidateMaxAckDelay
public long candidateMaxAckDelay(long rtt, long configuredMaxAckDelay, long peerMinAckDelayMicros) Themax_ack_delayto ask the peer for: the configured one or the peer's own, at most the RTT (but not below 25 ms) and at least the peer'smin_ack_delay.- Parameters:
rtt- the RTT estimate, in nanosecondsconfiguredMaxAckDelay- a configured delay in nanoseconds, or -1 to use the peer'speerMinAckDelayMicros- the peer'smin_ack_delayin microseconds, or -1- Returns:
- nanoseconds
-
maxAckDelayForPto
public long maxAckDelayForPto()Themax_ack_delayto compute the PTO with: the larger of the peer's and any requested but unacknowledged one, which the peer may already use.- Returns:
- nanoseconds
-
nextSequenceNumber
public long nextSequenceNumber()Allocates the next ACK_FREQUENCY sequence number.- Returns:
- the sequence number
-
shouldSendAckFrequency
public boolean shouldSendAckFrequency(long rtt, long configuredMaxAckDelay, long peerMinAckDelayMicros) Whether to send an ACK_FREQUENCY frame: always first, then when the desired delay differs from the current request by more than 20%.- Parameters:
rtt- the RTT estimate, in nanosecondsconfiguredMaxAckDelay- a configured delay in nanoseconds, or -1peerMinAckDelayMicros- the peer'smin_ack_delayin microseconds, or -1- Returns:
- true if a frame should be sent
-
ackFrequencySent
public void ackFrequencySent(long pn, long requestedMaxAckDelay) Records that a packet carried an ACK_FREQUENCY frame.- Parameters:
pn- the packet numberrequestedMaxAckDelay- the delay it asked for, in nanoseconds
-
onAcked
public void onAcked(long pn) Records an acknowledged application data packet; acknowledging the ACK_FREQUENCY frame makes its delay the peer's.- Parameters:
pn- the packet number
-
ackFrequencyReceived
public boolean ackFrequencyReceived(Frame.AckFrequency frame, PendingAcks pendingAcks) throws QuicException Applies a received ACK_FREQUENCY frame, unless an equal or newer one was applied already.- Parameters:
frame- the framependingAcks- the application data space's ACK state, which takes the thresholds- Returns:
- false if the frame was stale and ignored
- Throws:
QuicException-PROTOCOL_VIOLATIONif the requested delay is below the timer granularity, which is ourmin_ack_delay
-