github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/ackhandler/cc_adapter.go (about)

     1  package ackhandler
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/metacubex/quic-go/congestion"
     7  	cgInternal "github.com/metacubex/quic-go/internal/congestion"
     8  	"github.com/metacubex/quic-go/internal/protocol"
     9  )
    10  
    11  var _ cgInternal.SendAlgorithmWithDebugInfos = &ccAdapter{}
    12  
    13  type ccAdapter struct {
    14  	CC congestion.CongestionControl
    15  }
    16  
    17  func (a *ccAdapter) TimeUntilSend(bytesInFlight protocol.ByteCount) time.Time {
    18  	return a.CC.TimeUntilSend(congestion.ByteCount(bytesInFlight))
    19  }
    20  
    21  func (a *ccAdapter) HasPacingBudget(now time.Time) bool {
    22  	return a.CC.HasPacingBudget(now)
    23  }
    24  
    25  func (a *ccAdapter) OnPacketSent(sentTime time.Time, bytesInFlight protocol.ByteCount, packetNumber protocol.PacketNumber, bytes protocol.ByteCount, isRetransmittable bool) {
    26  	a.CC.OnPacketSent(sentTime, congestion.ByteCount(bytesInFlight), congestion.PacketNumber(packetNumber), congestion.ByteCount(bytes), isRetransmittable)
    27  }
    28  
    29  func (a *ccAdapter) CanSend(bytesInFlight protocol.ByteCount) bool {
    30  	return a.CC.CanSend(congestion.ByteCount(bytesInFlight))
    31  }
    32  
    33  func (a *ccAdapter) MaybeExitSlowStart() {
    34  	a.CC.MaybeExitSlowStart()
    35  }
    36  
    37  func (a *ccAdapter) OnPacketAcked(number protocol.PacketNumber, ackedBytes protocol.ByteCount, priorInFlight protocol.ByteCount, eventTime time.Time) {
    38  	a.CC.OnPacketAcked(congestion.PacketNumber(number), congestion.ByteCount(ackedBytes), congestion.ByteCount(priorInFlight), eventTime)
    39  }
    40  
    41  func (a *ccAdapter) OnCongestionEvent(number protocol.PacketNumber, lostBytes protocol.ByteCount, priorInFlight protocol.ByteCount) {
    42  	a.CC.OnCongestionEvent(congestion.PacketNumber(number), congestion.ByteCount(lostBytes), congestion.ByteCount(priorInFlight))
    43  }
    44  
    45  func (a *ccAdapter) OnRetransmissionTimeout(packetsRetransmitted bool) {
    46  	a.CC.OnRetransmissionTimeout(packetsRetransmitted)
    47  }
    48  
    49  func (a *ccAdapter) SetMaxDatagramSize(size protocol.ByteCount) {
    50  	a.CC.SetMaxDatagramSize(congestion.ByteCount(size))
    51  }
    52  
    53  func (a *ccAdapter) InSlowStart() bool {
    54  	return a.CC.InSlowStart()
    55  }
    56  
    57  func (a *ccAdapter) InRecovery() bool {
    58  	return a.CC.InRecovery()
    59  }
    60  
    61  func (a *ccAdapter) GetCongestionWindow() protocol.ByteCount {
    62  	return protocol.ByteCount(a.CC.GetCongestionWindow())
    63  }