turnpath

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 12 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 turnpath owns session-scoped delegated TURN paths. It consumes account authority from the application without knowing how a provider issues secrets.

Index

Constants

View Source
const (
	TransportConnectBudget        = 12 * time.Second
	TransportEvaluationBudget     = 20 * time.Second
	TransportEvaluationBytes      = 8 << 20
	TransportEvaluationDelay      = 10 * time.Second
	TransportEvaluationCooldown   = 30 * time.Second
	TransportReevaluationInterval = 2 * time.Minute
	TransportImprovementRatio     = 1.25
	TransportImprovementHold      = 2 * time.Second
)
View Source
const (
	MaximumActiveServices   = 2
	MaximumReplacementPaths = 1
	ServiceCooldown         = 30 * time.Second
	ReplacementBudget       = 90 * time.Second
	MaintenanceInterval     = time.Second
	MaximumRetiredPaths     = 128
	AdvertisementInterval   = 5 * time.Second
	ControlWriteBudget      = 5 * time.Second
)
View Source
const MaximumRecoveryReplacements = 2

Variables

View Source
var (
	ErrSuperseded = errors.New("TURN configuration superseded")
	ErrBudget     = errors.New("TURN account local usage budget exhausted")
)
View Source
var ErrAccountUnavailable = errors.New("TURN account unavailable")

Functions

func WatchTransport

func WatchTransport(parent context.Context, lease *Lease, sample func() Usage, stop func(error)) func()

WatchTransport charges actual socket deltas, including allocation traffic and retransmission. The owner joins this watcher after closing transport, before releasing the account lease, so the final sample includes shutdown traffic.

Types

type Accounts

type Accounts interface {
	Inventory() Inventory
	Acquire(context.Context, string, Subject) (*Lease, error)
}

type Admission

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

Admission is the revocable authority of one authenticated lane incarnation. A grant can outlive several attempts; closing an old admission cannot revoke the next attempt's authority.

func (*Admission) Close

func (a *Admission) Close()

type AuthorizedPath

type AuthorizedPath struct {
	*Lease
	ReplacesPeerPathID [16]byte
	// contains filtered or unexported fields
}

AuthorizedPath binds delegated credentials to their authenticated predecessor.

func (*AuthorizedPath) Relay

func (p *AuthorizedPath) Relay() iceconfig.Relay

type Event

type Event struct {
	At          time.Time
	Subject     Subject
	Provider    string
	Account     string
	Profile     string
	Milestone   connectionpath.Milestone
	Reason      string
	UsefulBytes uint64
}

type Inventory

type Inventory struct {
	Revision uint64
	Profiles []Profile
	Changed  <-chan struct{}
}

Inventory is one atomic configuration view. Changed closes when a newer view is available, so a sender cannot miss an update between reading and waiting. Its revision orders views; Profile.Revision determines issuance validity.

type Lease

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

Lease binds delegated credentials to local account capacity. Releasing it stops local authority; provider-confirmed revocation is an account observation.

func NewLease

func NewLease(config LeaseConfig) *Lease

func (*Lease) Charge

func (l *Lease) Charge(usage Usage) bool

func (*Lease) Close

func (l *Lease) Close()

func (*Lease) Loss

func (l *Lease) Loss() error

func (*Lease) Lost

func (l *Lease) Lost() <-chan struct{}

func (*Lease) Relay

func (l *Lease) Relay() iceconfig.Relay

func (*Lease) Renew

func (l *Lease) Renew(ctx context.Context, subject Subject) (*Lease, error)

func (*Lease) Renewable

func (l *Lease) Renewable() bool

type LeaseConfig

type LeaseConfig struct {
	Relay     iceconfig.Relay
	Renew     func(context.Context, Subject) (*Lease, error)
	Authority context.Context
	Charge    func(Usage) bool
	Release   func()
}

type Measurement

type Measurement struct {
	UsefulBytes  uint64
	Unhelpful    bool
	BusyTime     time.Duration
	PendingBytes uint64
}

type Profile

type Profile struct {
	Identity iceconfig.Identity
	// Revision identifies this profile's acquisition authority and endpoints.
	// An unrelated inventory publication must retain it, including across retries.
	Revision uint64
}

type Receiver

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

func NewReceiver

func NewReceiver(config ReceiverConfig) *Receiver

func (*Receiver) Handle

func (r *Receiver) Handle(ctx context.Context, body []byte) error

func (*Receiver) Recover

func (r *Receiver) Recover(path [16]byte, reason turncontrol.RecoveryReason)

func (*Receiver) Run

func (r *Receiver) Run(ctx context.Context)

func (*Receiver) SetDemand

func (r *Receiver) SetDemand(active bool)

type ReceiverConfig

type ReceiverConfig struct {
	SessionID         [16]byte
	Send              func(context.Context, []byte) error
	Open              func(context.Context, turncontrol.Grant, iceconfig.Connection) (ReceiverPath, error)
	Admitted          func(turncontrol.Grant, ReceiverPath)
	Observe           func(Event)
	Now               func() time.Time
	Tick              <-chan time.Time
	Measure           func(turncontrol.Lane) Measurement
	NetworkGeneration func() [16]byte
}

type ReceiverPath

type ReceiverPath interface {
	Lane() (turncontrol.Lane, bool)
	Done() <-chan struct{}
	Close() error
}

type Sender

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

func NewSender

func NewSender(config SenderConfig) *Sender

func (*Sender) Admit

func (s *Sender) Admit(ctx context.Context, path [16]byte, lane turncontrol.Lane, done <-chan struct{}) *Admission

func (*Sender) Handle

func (s *Sender) Handle(ctx context.Context, body []byte) error

func (*Sender) Lookup

func (s *Sender) Lookup(path [16]byte) (*AuthorizedPath, bool, error)

Lookup is the sender's authority check before constructing a native attempt. A retired grant cannot fall through to ordinary direct-path preparation.

func (*Sender) Recover

func (s *Sender) Recover(path [16]byte, reason turncontrol.RecoveryReason)

Recover is safe in transport callbacks and never waits on signaling or issuance. Maintenance consumes the durable request even if the wake is full.

func (*Sender) Run

func (s *Sender) Run(ctx context.Context)

type SenderConfig

type SenderConfig struct {
	Accounts          Accounts
	SessionID         [16]byte
	Send              func(context.Context, []byte) error
	Retire            func([16]byte)
	Now               func() time.Time
	Random            io.Reader
	Tick              <-chan time.Time
	Observe           func(Event)
	NetworkGeneration func() uint64
}

type Subject

type Subject struct {
	SessionID [16]byte
	PathID    [16]byte
}

type Usage

type Usage struct {
	// Payload is accepted application traffic, including protocol framing.
	// Useful is separately reported completed content, excluding retries.
	Payload, Useful, TransportSent, TransportReceived uint64
}

Jump to

Keyboard shortcuts

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