github.com/apernet/quic-go@v0.43.1-0.20240515053213-5e9e635fd9f0/internal/congestion/bandwidth.go (about)

     1  package congestion
     2  
     3  import (
     4  	"math"
     5  	"time"
     6  
     7  	"github.com/apernet/quic-go/internal/protocol"
     8  )
     9  
    10  // Bandwidth of a connection
    11  type Bandwidth uint64
    12  
    13  const infBandwidth Bandwidth = math.MaxUint64
    14  
    15  const (
    16  	// BitsPerSecond is 1 bit per second
    17  	BitsPerSecond Bandwidth = 1
    18  	// BytesPerSecond is 1 byte per second
    19  	BytesPerSecond = 8 * BitsPerSecond
    20  )
    21  
    22  // BandwidthFromDelta calculates the bandwidth from a number of bytes and a time delta
    23  func BandwidthFromDelta(bytes protocol.ByteCount, delta time.Duration) Bandwidth {
    24  	return Bandwidth(bytes) * Bandwidth(time.Second) / Bandwidth(delta) * BytesPerSecond
    25  }