github.com/sagernet/quic-go@v0.43.1-beta.1/congestion/interface.go (about)

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