bandwidth.go 584 B

12345678910111213141516171819202122
  1. package congestion
  2. import (
  3. "time"
  4. "v2ray.com/core/external/github.com/lucas-clemente/quic-go/internal/protocol"
  5. )
  6. // Bandwidth of a connection
  7. type Bandwidth uint64
  8. const (
  9. // BitsPerSecond is 1 bit per second
  10. BitsPerSecond Bandwidth = 1
  11. // BytesPerSecond is 1 byte per second
  12. BytesPerSecond = 8 * BitsPerSecond
  13. )
  14. // BandwidthFromDelta calculates the bandwidth from a number of bytes and a time delta
  15. func BandwidthFromDelta(bytes protocol.ByteCount, delta time.Duration) Bandwidth {
  16. return Bandwidth(bytes) * Bandwidth(time.Second) / Bandwidth(delta) * BytesPerSecond
  17. }