github.com/metacubex/mihomo@v1.18.5/transport/tuic/congestion_v2/bandwidth.go (about)

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