github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/congestion/interface.go (about)

     1  package congestion
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/metacubex/quic-go/internal/protocol"
     7  )
     8  
     9  type (
    10  	ByteCount    protocol.ByteCount
    11  	PacketNumber protocol.PacketNumber
    12  )
    13  
    14  // Expose some constants from protocol that congestion control algorithms may need.
    15  const (
    16  	InitialPacketSize          = protocol.InitialPacketSize
    17  	MinPacingDelay             = protocol.MinPacingDelay
    18  	MaxPacketBufferSize        = protocol.MaxPacketBufferSize
    19  	MinInitialPacketSize       = protocol.MinInitialPacketSize
    20  	MaxCongestionWindowPackets = protocol.MaxCongestionWindowPackets
    21  	PacketsPerConnectionID     = protocol.PacketsPerConnectionID
    22  )
    23  
    24  type AckedPacketInfo struct {
    25  	PacketNumber PacketNumber
    26  	BytesAcked   ByteCount
    27  	ReceivedTime time.Time
    28  }
    29  
    30  type LostPacketInfo struct {
    31  	PacketNumber PacketNumber
    32  	BytesLost    ByteCount
    33  }
    34  
    35  type CongestionControl interface {
    36  	SetRTTStatsProvider(provider RTTStatsProvider)
    37  	TimeUntilSend(bytesInFlight ByteCount) time.Time
    38  	HasPacingBudget(now time.Time) bool
    39  	OnPacketSent(sentTime time.Time, bytesInFlight ByteCount, packetNumber PacketNumber, bytes ByteCount, isRetransmittable bool)
    40  	CanSend(bytesInFlight ByteCount) bool
    41  	MaybeExitSlowStart()
    42  	OnPacketAcked(number PacketNumber, ackedBytes ByteCount, priorInFlight ByteCount, eventTime time.Time)
    43  	OnCongestionEvent(number PacketNumber, lostBytes ByteCount, priorInFlight ByteCount)
    44  	OnRetransmissionTimeout(packetsRetransmitted bool)
    45  	SetMaxDatagramSize(size ByteCount)
    46  	InSlowStart() bool
    47  	InRecovery() bool
    48  	GetCongestionWindow() ByteCount
    49  }
    50  
    51  type CongestionControlEx interface {
    52  	CongestionControl
    53  	OnCongestionEventEx(priorInFlight ByteCount, eventTime time.Time, ackedPackets []AckedPacketInfo, lostPackets []LostPacketInfo)
    54  }
    55  
    56  type RTTStatsProvider interface {
    57  	MinRTT() time.Duration
    58  	LatestRTT() time.Duration
    59  	SmoothedRTT() time.Duration
    60  	MeanDeviation() time.Duration
    61  	MaxAckDelay() time.Duration
    62  	PTO(includeMaxAckDelay bool) time.Duration
    63  	UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time)
    64  	SetMaxAckDelay(mad time.Duration)
    65  	SetInitialRTT(t time.Duration)
    66  	OnConnectionMigration()
    67  	ExpireSmoothedMetrics()
    68  }