socketauthority

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 13 Imported by: 1 module, 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 socketauthority owns bounded, independent per-path UDP endpoints and optional passive TCP listeners under separate capacity ledgers. A lease survives a serialized fresh ICE attempt, while no endpoint is shared between peer paths whose remote tuples can otherwise collide in Pion's mux.

Index

Constants

View Source
const (
	// DefaultUDPCapacity and DefaultTCPCapacity each accommodate four full
	// MaxAddressesPerPath paths (three active direct paths plus one reserved
	// essential opportunity) under independent ledgers so optional passive TCP
	// listeners can never starve mandatory UDP paths.
	DefaultUDPCapacity  = 64
	DefaultTCPCapacity  = 64
	MaxAddressesPerPath = 16
)

Variables

View Source
var (
	ErrClosed   = errors.New("socket authority closed")
	ErrCapacity = errors.New("socket capacity exhausted")
	ErrRetired  = errors.New("network generation retired")
	ErrActive   = errors.New("peer path already has an ICE owner")
	ErrInvalid  = errors.New("invalid socket lease request")
)

Functions

This section is empty.

Types

type Authority

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

Authority owns physical sockets; leases own only demand references.

func New

func New(config Config) *Authority

func (*Authority) Acquire

func (a *Authority) Acquire(session [16]byte, generation uint64, path [16]byte, addresses []netip.Addr) (*Lease, error)

Acquire freezes addresses for this generation/path. Callers must allocate a newer generation for address/route changes; an existing snapshot is never edited.

func (*Authority) Close

func (a *Authority) Close() error

func (*Authority) Request

func (a *Authority) Request(session [16]byte, generation uint64, path [16]byte, addresses []netip.Addr) (*Request, error)

Request freezes the exact mandatory UDP cost without opening endpoints.

func (*Authority) Retire

func (a *Authority) Retire(generation uint64)

Retire prevents new demand but lets existing admitted lanes release normally.

type CapacityError

type CapacityError struct {
	Protocol                         string
	Used, Reserved, Requested, Limit int
}

CapacityError preserves the accounting decision across admission and tracing.

func (*CapacityError) Error

func (e *CapacityError) Error() string

func (*CapacityError) Unwrap

func (*CapacityError) Unwrap() error

type Config

type Config struct {
	UDPCapacity  int
	TCPCapacity  int
	ListenPacket ListenPacket
	ListenTCP    func(network, address string) (net.Listener, error)
}

type Lease

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

Lease is a separately releasable demand reference. Retain never revives a released lease or a retired network generation.

func (*Lease) Claim

func (l *Lease) Claim() (*Mux, func(), error)

Claim transfers exclusive ICE ownership for this path lease. The returned release must run after PeerConnection.Close completes, before replacement.

func (*Lease) Close

func (l *Lease) Close() error

func (*Lease) Endpoints

func (l *Lease) Endpoints() []netip.AddrPort

func (*Lease) GenerationID

func (l *Lease) GenerationID() uint64

func (*Lease) PathID

func (l *Lease) PathID() [16]byte

func (*Lease) PrepareTCP

func (l *Lease) PrepareTCP() error

PrepareTCP allocates optional passive TCP listeners for all lease addresses. Listeners draw from an independent TCP capacity pool so they can never starve mandatory UDP paths; optional paths additionally leave room for one essential path's TCP listeners.

func (*Lease) Retain

func (l *Lease) Retain() (*Lease, error)

func (*Lease) SessionID

func (l *Lease) SessionID() [16]byte

func (*Lease) TCP

func (l *Lease) TCP() *TCPMux

TCP returns the frozen listener set only while an ICE owner holds Claim.

func (*Lease) TCPEndpoints

func (l *Lease) TCPEndpoints() []netip.AddrPort

type ListenPacket

type ListenPacket func(network, address string) (net.PacketConn, error)

ListenPacket is injected so allocation and failure cleanup are testable.

type Mux

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

Mux routes each local interface/family to its own physical endpoint. It is immutable once published; only Authority closes it.

func (*Mux) Close

func (m *Mux) Close() error

func (*Mux) DiscoverXORMappedAddr added in v0.1.6

func (m *Mux) DiscoverXORMappedAddr(ctx context.Context, local netip.AddrPort, server *net.UDPAddr, timeout time.Duration) (netip.AddrPort, error)

The socket survives across attempts. Its current owner must cancel and drain outstanding discovery before releasing the claim to its successor.

func (*Mux) GetConn

func (m *Mux) GetConn(ufrag string, addr net.Addr) (net.PacketConn, error)

func (*Mux) GetListenAddresses

func (m *Mux) GetListenAddresses() []net.Addr

func (*Mux) RemoveConnByUfrag

func (m *Mux) RemoveConnByUfrag(ufrag string)

type Request

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

Request is immutable and can be retried by the single process admission queue.

func (*Request) Changes

func (r *Request) Changes() <-chan struct{}

Changes must be sampled before Reserve so a concurrent release cannot be lost.

func (*Request) Reserve

func (r *Request) Reserve() (*Reservation, error)

Reserve performs no network I/O and accounts exclusively against the mandatory UDP ledger. Optional passive TCP listeners use an independent capacity pool.

func (*Request) ReserveOptional

func (r *Request) ReserveOptional() (*Reservation, error)

ReserveOptional leaves a complete mandatory socket opportunity for a new receiver. The reserve uses the frozen address cost, not a guessed path count.

func (*Request) SamePool

func (r *Request) SamePool(other *Request) bool

type Reservation

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

Reservation owns either a future allocation or a retained existing lease. Activate transfers ownership once; abandonment returns only this reservation.

func (*Reservation) Activate

func (r *Reservation) Activate() (*Lease, error)

func (*Reservation) Close

func (r *Reservation) Close()

type TCPMux

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

TCPMux preserves exact local interface/listener affinity.

func (*TCPMux) Close

func (m *TCPMux) Close() error

func (*TCPMux) GetAllConns

func (m *TCPMux) GetAllConns(ufrag string, isIPv6 bool, local net.IP) ([]net.PacketConn, error)

func (*TCPMux) GetConnByUfrag

func (m *TCPMux) GetConnByUfrag(ufrag string, isIPv6 bool, local net.IP) (net.PacketConn, error)

func (*TCPMux) RemoveConnByUfrag

func (m *TCPMux) RemoveConnByUfrag(ufrag string)

Jump to

Keyboard shortcuts

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