github.com/daeuniverse/quic-go@v0.0.0-20240413031024-943f218e0810/internal/ackhandler/cc_adapter.go (about)

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