nquic_protocol_timer (nquic v1.2.0)
View SourceTimer-action orchestration for the QUIC protocol state.
Pure functions over #conn_state{} that translate connection state
into the set_timer / cancel_timer actions the owner must schedule:
the ACK-delay timer, the idle timer (RFC 9000 Section 10.1), the loss
detection timer, the path-validation timer (RFC 9000 Section 8.2), and
the PMTUD probe timer (RFC 8899).
The loss detection timer uses the pto timer type. It runs to the loss
time of nquic_loss:get_loss_timer/1 when one is set, and to the PTO
(RFC 9002 Section 6.2) otherwise, as in RFC 9002 Appendix A.8.
compute_timer_actions/1 is the aggregate entry point used after
nquic_protocol:handle_packet/3 and nquic_protocol:flush/1. The
idle and loss detection timer values are cached in #conn_state{} so
unchanged timers do not re-emit actions. External side effects are limited to
delegating into nquic_loss, nquic_pmtud, and nquic_path; the
idle bound is resolved via nquic_protocol:get_idle_timeout/2.
Summary
Functions
Compute the loss detection timer action unconditionally, and record it in
the cache that compute_timer_actions/1 reads. Use it after a send of an
ack-eliciting packet or after the timer fired, where the timer restarts
even when its value did not change.
Compute timer actions based on current state.
Returns idle and PTO timer actions the caller should schedule.
Call after nquic_protocol:handle_packet/3 or nquic_protocol:flush/1
to keep timers up to date. Caches idle and PTO values to skip
unchanged timer actions. Uses accumulator to avoid ++ overhead.
Get the deadline of the loss detection timer in
erlang:monotonic_time(millisecond) units, or cancel when the timer
must not run. A pending loss time (nquic_loss:get_loss_timer/1) is the
deadline, rounded up to the next millisecond. Otherwise the timer is the
PTO.
The deadline is one PTO period after nquic_loss:get_pto_base_time/1
(RFC 9002 Appendix A.8). A recompute that sees no new ack-eliciting
packet gives the same deadline, so received datagrams do not push the
timer out. With nothing in flight, which is the client anti-deadlock
PTO, the deadline is one PTO period after now.
Types
-type loss_detection_timer() :: {loss, integer()} | pos_integer() | cancel.
Functions
-spec arm_pto_timer(nquic_protocol:state()) -> {[nquic_protocol:timeout_action()], nquic_protocol:state()}.
Compute the loss detection timer action unconditionally, and record it in
the cache that compute_timer_actions/1 reads. Use it after a send of an
ack-eliciting packet or after the timer fired, where the timer restarts
even when its value did not change.
-spec compute_path_validation_timeout(nquic_protocol:state()) -> non_neg_integer().
-spec compute_pto_timer_actions(nquic_protocol:state()) -> [nquic_protocol:timeout_action()].
-spec compute_timer_actions(nquic_protocol:state()) -> {[nquic_protocol:timeout_action()], nquic_protocol:state()}.
Compute timer actions based on current state.
Returns idle and PTO timer actions the caller should schedule.
Call after nquic_protocol:handle_packet/3 or nquic_protocol:flush/1
to keep timers up to date. Caches idle and PTO values to skip
unchanged timer actions. Uses accumulator to avoid ++ overhead.
-spec pto_deadline_ms(nquic_protocol:state()) -> integer() | cancel.
Get the deadline of the loss detection timer in
erlang:monotonic_time(millisecond) units, or cancel when the timer
must not run. A pending loss time (nquic_loss:get_loss_timer/1) is the
deadline, rounded up to the next millisecond. Otherwise the timer is the
PTO.
The deadline is one PTO period after nquic_loss:get_pto_base_time/1
(RFC 9002 Appendix A.8). A recompute that sees no new ack-eliciting
packet gives the same deadline, so received datagrams do not push the
timer out. With nothing in flight, which is the client anti-deadlock
PTO, the deadline is one PTO period after now.