github.com/Psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/quic/gquic-go/internal/congestion/bandwidth.go (about) 1 package congestion 2 3 import ( 4 "time" 5 6 "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/internal/protocol" 7 ) 8 9 // Bandwidth of a connection 10 type Bandwidth uint64 11 12 const ( 13 // BitsPerSecond is 1 bit per second 14 BitsPerSecond Bandwidth = 1 15 // BytesPerSecond is 1 byte per second 16 BytesPerSecond = 8 * BitsPerSecond 17 ) 18 19 // BandwidthFromDelta calculates the bandwidth from a number of bytes and a time delta 20 func BandwidthFromDelta(bytes protocol.ByteCount, delta time.Duration) Bandwidth { 21 return Bandwidth(bytes) * Bandwidth(time.Second) / Bandwidth(delta) * BytesPerSecond 22 }