utils

package
v0.36.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const InfDuration = time.Duration(math.MaxInt64)

InfDuration is a duration of infinite length

Variables

This section is empty.

Functions

func AbsDuration

func AbsDuration(d time.Duration) time.Duration

AbsDuration returns the absolute value of a time duration

func IsIPv4 added in v0.34.1

func IsIPv4(ip net.IP) bool

func Max

func Max[T constraints.Ordered](a, b T) T

func MaxTime added in v0.7.0

func MaxTime(a, b time.Time) time.Time

MaxTime returns the later time

func Min

func Min[T constraints.Ordered](a, b T) T

func MinNonZeroDuration added in v0.34.1

func MinNonZeroDuration(a, b time.Duration) time.Duration

MinNonZeroDuration return the minimum duration that's not zero.

func MinNonZeroTime added in v0.34.1

func MinNonZeroTime(a, b time.Time) time.Time

MinNonZeroTime returns the earlist time that is not time.Time{} If both a and b are time.Time{}, it returns time.Time{}

func MinTime

func MinTime(a, b time.Time) time.Time

MinTime returns the earlier time

func NewBufferedWriteCloser added in v0.34.1

func NewBufferedWriteCloser(writer *bufio.Writer, closer io.Closer) io.WriteCloser

NewBufferedWriteCloser creates an io.WriteCloser from a bufio.Writer and an io.Closer

Types

type ByteInterval

type ByteInterval struct {
	Start protocol.ByteCount
	End   protocol.ByteCount
}

ByteInterval is an interval from one ByteCount to the other

func (ByteInterval) Comp added in v0.34.1

func (i ByteInterval) Comp(v ByteInterval) int8

func (ByteInterval) Match added in v0.34.1

func (i ByteInterval) Match(n ByteInterval) int8

func (ByteInterval) String added in v0.34.1

func (i ByteInterval) String() string

type ByteOrder

type ByteOrder interface {
	Uint32([]byte) uint32
	Uint24([]byte) uint32
	Uint16([]byte) uint16

	ReadUint32(io.ByteReader) (uint32, error)
	ReadUint24(io.ByteReader) (uint32, error)
	ReadUint16(io.ByteReader) (uint16, error)

	WriteUint32(*bytes.Buffer, uint32)
	WriteUint24(*bytes.Buffer, uint32)
	WriteUint16(*bytes.Buffer, uint16)
}

A ByteOrder specifies how to convert byte sequences into 16-, 32-, or 64-bit unsigned integers.

var BigEndian ByteOrder = bigEndian{}

BigEndian is the big-endian implementation of ByteOrder.

type LogLevel

type LogLevel uint8

LogLevel of quic-go

const (
	// LogLevelNothing disables
	LogLevelNothing LogLevel = iota
	// LogLevelError enables err logs
	LogLevelError
	// LogLevelInfo enables info logs (e.g. packets)
	LogLevelInfo
	// LogLevelDebug enables debug logs (e.g. packet contents)
	LogLevelDebug
)

type Logger added in v0.8.0

type Logger interface {
	SetLogLevel(LogLevel)
	SetLogTimeFormat(format string)
	WithPrefix(prefix string) Logger
	Debug() bool

	Errorf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})
}

A Logger logs.

var DefaultLogger Logger

DefaultLogger is used by quic-go for logging.

type RTTStats added in v0.34.1

type RTTStats struct {
	// contains filtered or unexported fields
}

RTTStats provides round-trip statistics

func NewRTTStats added in v0.34.1

func NewRTTStats() *RTTStats

NewRTTStats makes a properly initialized RTTStats object

func (*RTTStats) ExpireSmoothedMetrics added in v0.34.1

func (r *RTTStats) ExpireSmoothedMetrics()

ExpireSmoothedMetrics causes the smoothed_rtt to be increased to the latest_rtt if the latest_rtt is larger. The mean deviation is increased to the most recent deviation if it's larger.

func (*RTTStats) LatestRTT added in v0.34.1

func (r *RTTStats) LatestRTT() time.Duration

LatestRTT returns the most recent rtt measurement. May return Zero if no valid updates have occurred.

func (*RTTStats) MaxAckDelay added in v0.34.1

func (r *RTTStats) MaxAckDelay() time.Duration

MaxAckDelay gets the max_ack_delay advertised by the peer

func (*RTTStats) MeanDeviation added in v0.34.1

func (r *RTTStats) MeanDeviation() time.Duration

MeanDeviation gets the mean deviation

func (*RTTStats) MinRTT added in v0.34.1

func (r *RTTStats) MinRTT() time.Duration

MinRTT Returns the minRTT for the entire connection. May return Zero if no valid updates have occurred.

func (*RTTStats) OnConnectionMigration added in v0.34.1

func (r *RTTStats) OnConnectionMigration()

OnConnectionMigration is called when connection migrates and rtt measurement needs to be reset.

func (*RTTStats) PTO added in v0.34.1

func (r *RTTStats) PTO(includeMaxAckDelay bool) time.Duration

PTO gets the probe timeout duration.

func (*RTTStats) SetInitialRTT added in v0.34.1

func (r *RTTStats) SetInitialRTT(t time.Duration)

SetInitialRTT sets the initial RTT. It is used during the 0-RTT handshake when restoring the RTT stats from the session state.

func (*RTTStats) SetMaxAckDelay added in v0.34.1

func (r *RTTStats) SetMaxAckDelay(mad time.Duration)

SetMaxAckDelay sets the max_ack_delay

func (*RTTStats) SmoothedRTT added in v0.34.1

func (r *RTTStats) SmoothedRTT() time.Duration

SmoothedRTT returns the smoothed RTT for the connection. May return Zero if no valid updates have occurred.

func (*RTTStats) UpdateRTT added in v0.34.1

func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time)

UpdateRTT updates the RTT based on a new sample.

type Rand added in v0.34.1

type Rand struct {
	// contains filtered or unexported fields
}

Rand is a wrapper around crypto/rand that adds some convenience functions known from math/rand.

func (*Rand) Int31 added in v0.34.1

func (r *Rand) Int31() int32

func (*Rand) Int31n added in v0.34.1

func (r *Rand) Int31n(n int32) int32

copied from the standard library math/rand implementation of Int63n

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

A Timer wrapper that behaves correctly when resetting

func NewTimer

func NewTimer() *Timer

NewTimer creates a new timer that is not set

func (*Timer) Chan

func (t *Timer) Chan() <-chan time.Time

Chan returns the channel of the wrapped timer

func (*Timer) Deadline added in v0.34.1

func (t *Timer) Deadline() time.Time

func (*Timer) Reset

func (t *Timer) Reset(deadline time.Time)

Reset the timer, no matter whether the value was read or not

func (*Timer) SetRead

func (t *Timer) SetRead()

SetRead should be called after the value from the chan was read

func (*Timer) Stop added in v0.34.1

func (t *Timer) Stop()

Stop stops the timer

Directories

Path Synopsis
Package list implements a doubly linked list.
Package list implements a doubly linked list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL