github.com/daeuniverse/quic-go@v0.0.0-20240413031024-943f218e0810/congestion/interface.go (about) 1 package congestion 2 3 import ( 4 "time" 5 6 "github.com/daeuniverse/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 OnCongestionEventEx(priorInFlight ByteCount, eventTime time.Time, ackedPackets []AckedPacketInfo, lostPackets []LostPacketInfo) 46 OnRetransmissionTimeout(packetsRetransmitted bool) 47 SetMaxDatagramSize(size ByteCount) 48 InSlowStart() bool 49 InRecovery() bool 50 GetCongestionWindow() ByteCount 51 } 52 53 type RTTStatsProvider interface { 54 MinRTT() time.Duration 55 LatestRTT() time.Duration 56 SmoothedRTT() time.Duration 57 MeanDeviation() time.Duration 58 MaxAckDelay() time.Duration 59 PTO(includeMaxAckDelay bool) time.Duration 60 UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) 61 SetMaxAckDelay(mad time.Duration) 62 SetInitialRTT(t time.Duration) 63 OnConnectionMigration() 64 ExpireSmoothedMetrics() 65 }