github.com/kelleygo/clashcore@v1.0.2/transport/tuic/congestion/bandwidth.go (about)

     1  package congestion
     2  
     3  import (
     4  	"math"
     5  	"time"
     6  
     7  	"github.com/metacubex/quic-go/congestion"
     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 congestion.ByteCount, delta time.Duration) Bandwidth {
    24  	return Bandwidth(bytes) * Bandwidth(time.Second) / Bandwidth(delta) * BytesPerSecond
    25  }