Skip to main content

Appendix A. Loss Recovery Pseudocode

This appendix describes an example implementation of the loss detection mechanisms described in Section 6.

The pseudocode segments in this section are licensed as Code Components; see the copyright notice.


A.1. Tracking Sent Packets

To correctly implement congestion control, a QUIC sender tracks every ack-eliciting packet until the packet is acknowledged or lost.

A.1.1. Sent Packet Fields

Key fields tracked for each sent packet:

  • packet_number: The packet number
  • ack_eliciting: Whether packet requires acknowledgment
  • in_flight: Whether packet counts toward bytes in flight
  • sent_bytes: Number of bytes sent
  • time_sent: Timestamp when packet was sent

A.2. Constants of Interest

  • kPacketThreshold: Maximum packet reordering (recommended: 3)
  • kTimeThreshold: Maximum time reordering (recommended: 9/8)
  • kGranularity: Timer granularity (recommended: 1 ms)
  • kInitialRtt: Initial RTT value (recommended: 333 ms)
  • kPacketNumberSpace: Enum for packet number spaces

A.3. Variables of Interest

Key variables for loss recovery:

  • latest_rtt, smoothed_rtt, rttvar, min_rtt
  • loss_detection_timer, pto_count
  • time_of_last_ack_eliciting_packet[kPacketNumberSpace]
  • largest_acked_packet[kPacketNumberSpace]
  • sent_packets[kPacketNumberSpace]

A.4-A.11. Algorithm Functions

The following functions implement the loss recovery algorithm:

  • A.4. Initialization: Initialize loss detection variables
  • A.5. On Sending a Packet: Store packet information
  • A.6. On Receiving a Datagram: Handle anti-amplification unblocking
  • A.7. On Receiving an Acknowledgment: Process ACK frames
  • A.8. Setting the Loss Detection Timer: Configure timer
  • A.9. On Timeout: Handle timer expiration
  • A.10. Detecting Lost Packets: Identify lost packets
  • A.11. Upon Dropping Keys: Handle key discarding

Note: For complete pseudocode implementations, please refer to the official RFC 9002 document Appendix A. All variable names, function names, and algorithm logic are preserved in the original form to ensure implementation accuracy and consistency.