socketauthority

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 10 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. 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 (
	DefaultCapacity       = 64
	MaxAddressesPerPath   = 16
	DefaultIdleInterval   = 15 * time.Second
	DefaultRefreshTimeout = 500 * time.Millisecond
)
View Source
const MaxIdleHold = 2 * time.Minute
View Source
const MaxIdleServers = 2

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 {
	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 {
	Capacity       int
	ListenPacket   ListenPacket
	ListenTCP      func(network, address string) (net.Listener, error)
	IdleInterval   time.Duration
	RefreshTimeout time.Duration
	// Observe must publish promptly; it is never called while holding the authority lock.
	Observe func(Event)
}

type Event

type Event struct {
	ProtocolSessionID   [16]byte
	PeerPathID          [16]byte
	NetworkGenerationID uint64
	Kind                EventKind
	At                  time.Time
	Duration            time.Duration
	Local, Server       netip.AddrPort
	Result              string
}

Socket work belongs to a path, not an ICE attempt that may already have ended.

type EventKind

type EventKind string
const (
	STUNRefreshFinished   EventKind = "stun_refresh_finished"
	SocketHandoffStarted  EventKind = "socket_handoff_started"
	SocketHandoffFinished EventKind = "socket_handoff_finished"
)

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 keepalive ownership to one ICE agent. 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(includeIPv6 bool) error

PrepareTCP is called only after a proven peer capability profile is selected. It is demand-owned and bounded by the same process socket capacity as UDP.

func (*Lease) Retain

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

func (*Lease) SessionID

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

func (*Lease) StartIdle

func (l *Lease) StartIdle(ctx context.Context, servers []netip.AddrPort, deadline time.Time) error

StartIdle holds NAT discovery mappings only until the caller's already budgeted fresh attempt deadline. It does not retain a demand reference and therefore cannot keep an otherwise unused endpoint or generation alive. Repeated handoffs cancel and join the previous heartbeat before replacement.

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) GetConn

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

func (*Mux) GetConnForURL

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

func (*Mux) GetListenAddresses

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

func (*Mux) GetRelayedAddr

func (m *Mux) GetRelayedAddr(net.Addr, time.Duration) (*net.Addr, error)

func (*Mux) GetXORMappedAddr

func (m *Mux) GetXORMappedAddr(server net.Addr, deadline time.Duration) (*stun.XORMappedAddress, error)

func (*Mux) GetXORMappedAddrForLocal

func (m *Mux) GetXORMappedAddrForLocal(ctx context.Context, server, local net.Addr, deadline time.Duration) (*stun.XORMappedAddress, error)

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. Optional TCP listeners share this ledger but cannot consume capacity already promised to another path's mandatory UDP set.

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) GetConnForEndpoint

func (m *TCPMux) GetConnForEndpoint(ufrag string, local netip.AddrPort) (net.PacketConn, error)

GetConnForEndpoint prevents a mapped port from borrowing another listener.

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