packetqueue

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package packetqueue implements bounded priority queues for packet ownership.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLimits indicates non-positive packet or byte limits.
	ErrInvalidLimits = errors.New("invalid queue limits")
	// ErrInvalidItem indicates a non-positive item size or missing deadline.
	ErrInvalidItem = errors.New("invalid queue item")
	// ErrFull indicates that accepting an item would exceed a queue limit.
	ErrFull = errors.New("queue full")
	// ErrExpired indicates an item already beyond its deadline.
	ErrExpired = errors.New("item expired")
	// ErrClosed indicates an operation on a closed queue.
	ErrClosed = errors.New("queue closed")
	// ErrEmpty indicates that a nonblocking dequeue found no unexpired item.
	ErrEmpty = errors.New("queue empty")
)

Functions

This section is empty.

Types

type Item

type Item[T any] struct {
	Value    T
	Size     int
	Priority Priority
	Deadline time.Time
	// contains filtered or unexported fields
}

Item owns one queued value and its scheduling metadata.

func (*Item[T]) ReleaseRetention

func (i *Item[T]) ReleaseRetention()

ReleaseRetention releases aggregate capacity retained by an item outside a queue.

func (*Item[T]) RestoreRetention

func (i *Item[T]) RestoreRetention(budget *retention.Budget, bytes int)

RestoreRetention returns a failed transfer to the item and restores its queue byte charge.

func (*Item[T]) TakeRetention

func (i *Item[T]) TakeRetention(bytes int) (*retention.Budget, bool)

TakeRetention transfers the item's aggregate reservation after resizing its byte charge.

type Limits

type Limits struct {
	Packets           int
	Bytes             int
	ControlPreemption bool
}

Limits bound a queue independently by packets and bytes.

type Priority

type Priority uint8

Priority controls dequeue order without changing packet deadlines.

const (
	// PriorityNormal carries ordinary WireGuard transport data.
	PriorityNormal Priority = iota
	// PriorityControl carries WireGuard handshake and cookie packets.
	PriorityControl
)

func (Priority) Valid

func (p Priority) Valid() bool

Valid reports whether the priority is defined.

type Queue

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

Queue is a concurrent bounded priority queue with explicit item ownership.

func New

func New[T any](limits Limits) (*Queue[T], error)

New returns an empty queue using the process wall clock for deadline decisions.

func NewWithBudget

func NewWithBudget[T any](limits Limits, budget *retention.Budget) (*Queue[T], error)

NewWithBudget returns an empty queue sharing an aggregate retention budget.

func NewWithClock

func NewWithClock[T any](limits Limits, now func() time.Time) (*Queue[T], error)

NewWithClock returns an empty queue using now for deterministic deadline decisions.

func (*Queue[T]) Bytes

func (q *Queue[T]) Bytes() int

Bytes returns the current queued byte count.

func (*Queue[T]) Close

func (q *Queue[T]) Close()

Close rejects future pushes and wakes blocked consumers.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Len returns the current queued packet count.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop(ctx context.Context) (Item[T], error)

Pop waits for and transfers ownership of the next unexpired item to the caller.

func (*Queue[T]) Push

func (q *Queue[T]) Push(item Item[T]) error

Push transfers ownership of item to the queue when all limits permit it.

func (*Queue[T]) Ready

func (q *Queue[T]) Ready() <-chan struct{}

Ready returns a coalesced notification for newly queued work.

func (*Queue[T]) TryPop

func (q *Queue[T]) TryPop() (Item[T], error)

TryPop transfers ownership of the next unexpired item without blocking.

func (*Queue[T]) TryPopPriority

func (q *Queue[T]) TryPopPriority(priority Priority) (Item[T], error)

TryPopPriority transfers the next unexpired item at priority without considering the other priority.

Jump to

Keyboard shortcuts

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