github.com/tumi8/quic-go@v0.37.4-tum/noninternal/congestion/bandwidth.go (about) 1 package congestion 2 3 import ( 4 "math" 5 "time" 6 7 "github.com/tumi8/quic-go/noninternal/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 }