congestion

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInitialPacketSize

func GetInitialPacketSize(addr net.Addr) congestion.ByteCount

func Max

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

func MaxFilter

func MaxFilter[O constraints.Ordered](a, b O) int

Compares two values and returns true if the first is greater than or equal to the second.

func Min

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

func MinFilter

func MinFilter[O constraints.Ordered](a, b O) int

Compares two values and returns true if the first is less than or equal to the second.

func NewBbrSender

func NewBbrSender(
	clock Clock,
	initialMaxDatagramSize congestion.ByteCount,
	initialCongestionWindowPackets congestion.ByteCount,
) *bbrSender

Types

type Bandwidth

type Bandwidth uint64

Bandwidth of a connection

const (
	// BitsPerSecond is 1 bit per second
	BitsPerSecond Bandwidth = 1
	// BytesPerSecond is 1 byte per second
	BytesPerSecond = 8 * BitsPerSecond
)

func BandwidthFromDelta

func BandwidthFromDelta(bytes congestion.ByteCount, delta time.Duration) Bandwidth

BandwidthFromDelta calculates the bandwidth from a number of bytes and a time delta

type Clock

type Clock interface {
	Now() time.Time
}

A Clock returns the current time

type DefaultClock

type DefaultClock struct{}

DefaultClock implements the Clock interface using the Go stdlib clock.

func (DefaultClock) Now

func (DefaultClock) Now() time.Time

Now gets the current time

type Pacer

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

Pacer implements a token bucket pacing algorithm.

func NewPacer

func NewPacer(getBandwidth func() congestion.ByteCount) *Pacer

func (*Pacer) Budget

func (p *Pacer) Budget(now time.Time) congestion.ByteCount

func (*Pacer) SentPacket

func (p *Pacer) SentPacket(sendTime time.Time, size congestion.ByteCount)

func (*Pacer) SetMaxDatagramSize

func (p *Pacer) SetMaxDatagramSize(s congestion.ByteCount)

func (*Pacer) TimeUntilSend

func (p *Pacer) TimeUntilSend() time.Time

TimeUntilSend returns when the next packet should be sent. It returns the zero value of time.Time if a packet can be sent immediately.

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

A RingBuffer is a ring buffer. It acts as a heap that doesn't cause any allocations.

func (*RingBuffer[T]) Back

func (r *RingBuffer[T]) Back() *T

Back returns the back element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.

func (*RingBuffer[T]) Clear

func (r *RingBuffer[T]) Clear()

Clear removes all elements.

func (*RingBuffer[T]) Empty

func (r *RingBuffer[T]) Empty() bool

Empty says if the ring buffer is empty.

func (*RingBuffer[T]) Front

func (r *RingBuffer[T]) Front() *T

Front returns the front element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.

func (*RingBuffer[T]) Init

func (r *RingBuffer[T]) Init(size int)

Init preallocs a buffer with a certain size.

func (*RingBuffer[T]) Len

func (r *RingBuffer[T]) Len() int

Len returns the number of elements in the ring buffer.

func (*RingBuffer[T]) Offset

func (r *RingBuffer[T]) Offset(index int) *T

Offset returns the offset element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first and check if the index larger than buffer length.

func (*RingBuffer[T]) PopFront

func (r *RingBuffer[T]) PopFront() T

PopFront returns the next element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.

func (*RingBuffer[T]) PushBack

func (r *RingBuffer[T]) PushBack(t T)

PushBack adds a new element. If the ring buffer is full, its capacity is increased first.

type WindowedFilter

type WindowedFilter[V WindowedFilterValue, T WindowedFilterTime] struct {
	// contains filtered or unexported fields
}

func NewWindowedFilter

func NewWindowedFilter[V WindowedFilterValue, T WindowedFilterTime](windowLength T, comparator func(V, V) int) *WindowedFilter[V, T]

func (*WindowedFilter[V, T]) Clear

func (f *WindowedFilter[V, T]) Clear()

func (*WindowedFilter[V, T]) GetBest

func (f *WindowedFilter[V, T]) GetBest() V

func (*WindowedFilter[V, T]) GetSecondBest

func (f *WindowedFilter[V, T]) GetSecondBest() V

func (*WindowedFilter[V, T]) GetThirdBest

func (f *WindowedFilter[V, T]) GetThirdBest() V

func (*WindowedFilter[V, T]) Reset

func (f *WindowedFilter[V, T]) Reset(newSample V, newTime T)

Resets all estimates to new sample.

func (*WindowedFilter[V, T]) SetWindowLength

func (f *WindowedFilter[V, T]) SetWindowLength(windowLength T)

Changes the window length. Does not update any current samples.

func (*WindowedFilter[V, T]) Update

func (f *WindowedFilter[V, T]) Update(newSample V, newTime T)

Updates best estimates with |sample|, and expires and updates best estimates as necessary.

type WindowedFilterTime

type WindowedFilterTime interface {
	constraints.Integer | constraints.Float
}

type WindowedFilterValue

type WindowedFilterValue interface {
	any
}

Jump to

Keyboard shortcuts

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