nativepeer

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: 30 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 nativepeer assembles demand-owned native connectivity resources. It reports changed facts; the PeerSet alone decides whether to start an attempt.

Index

Constants

View Source
const (
	ConcurrentAttempts             = 4
	DirectAttemptReserve           = 1
	StartsPerWindow                = 16
	STUNEndpointsPerWindow         = 32
	MaximumQueuedAttempts          = 64
	AdmissionWindow                = time.Minute
	AttemptBudget                  = 85 * time.Second
	ActiveTimePerWindow            = ConcurrentAttempts * AttemptBudget
	QueueBudget                    = time.Minute
	MinimumPreparationOpportunity  = 50 * time.Second
	MaximumSTUNEndpointsPerAttempt = icepolicy.EndpointsPerProfile
)

These application limits mirror browser tab admission. The injected authority survives manager, authenticated-session and network-generation replacement.

View Source
const (
	InitialCheckingBudget = 40 * time.Second
	MaximumPaths          = 64
	WaveLifetime          = 120 * time.Second
)
View Source
const (
	DefaultObservationCapacity = 256
	SideSender                 = "sender"
	SideReceiver               = "receiver"
)
View Source
const ControlLifetime = 60 * time.Second
View Source
const ControlRefresh = 30 * time.Second
View Source
const MaintenanceInterval = 250 * time.Millisecond

Variables

View Source
var ErrAdmission = errors.New("native attempt admission unavailable")
View Source
var ErrCapacityRequired = errors.New("native connectivity requires admission and TURN capacity")

Functions

func GenerationIdentity

func GenerationIdentity(generation uint64) (identity [16]byte)

Types

type Admission

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

Admission belongs to the application; every native owner shares its allowances. Replacing a connection manager must not replenish the application's rate budget.

func NewAdmission

func NewAdmission(clock AdmissionClock) *Admission

type AdmissionClock

type AdmissionClock struct {
	Now       func() time.Time
	AfterFunc func(time.Duration, func()) func()
}

AdmissionClock permits deterministic refill and queue tests without sleeping.

type AdmissionFacts

type AdmissionFacts struct {
	Purpose                        v2signal.ConnectionPurpose
	Kind                           AdmissionKind
	At                             time.Time
	Wait                           time.Duration
	Active, Queued                 int
	StartsRemaining, STUNRemaining float64
	ActiveTimeRemaining            time.Duration
	SocketCapacity                 *socketauthority.CapacityError
}

type AdmissionKind

type AdmissionKind string
const (
	AdmissionQueued   AdmissionKind = "queued"
	AdmissionGranted  AdmissionKind = "granted"
	AdmissionReleased AdmissionKind = "released"
	AdmissionRejected AdmissionKind = "rejected"
)

type AttemptRequest

type AttemptRequest struct {
	Configuration      pion.Configuration
	ICE                iceconfig.Connection
	ProtocolSessionID  [16]byte
	ReplacesPeerPathID [16]byte
	Binding            v2signal.Binding
	OnTURNRecovery     func(turncontrol.RecoveryReason)
}

type Change

type Change struct {
	RemoteNetworkChanged bool
	Remote               bool
	Retired              bool
	NetworkGenerationID  uint64
	MappingReady         bool
}

type Config

type Config struct {
	Admission           *Admission
	TURNCapacity        *turncapacity.Pool
	Connect             func(pion.Configuration, pionpeer.AttemptConfig) (*pionpeer.Connection, error)
	Monitor             NetworkMonitor
	Sockets             *socketauthority.Authority
	Pool                func() icepolicy.ICEEndpointPool
	Reachability        *reachability.Authority
	Discovery           *gateway.Discovery
	Now                 func() time.Time
	ObservationCapacity int
	Side                string
}

type LifecycleFacts

type LifecycleFacts struct {
	Kind               LifecycleKind
	At                 time.Time
	Content            bool
	Direct             bool
	PreviousGeneration uint64
}

type LifecycleKind

type LifecycleKind string
const (
	DemandChanged            LifecycleKind = "demand_changed"
	NetworkChanged           LifecycleKind = "network_changed"
	PathClosed               LifecycleKind = "path_closed"
	ContentRecoveryRequested LifecycleKind = "content_recovery_requested"
)

type NativePeerConnectivity

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

func New

func New(config Config) (*NativePeerConnectivity, error)

func (*NativePeerConnectivity) ApplyControl

func (n *NativePeerConnectivity) ApplyControl(session [16]byte, body []byte) (protocolsession.PeerPathControl, bool)

ApplyControl sees only the core runtime's authenticated canonical body. A watermark survives expiry/revoke so late delivery cannot resurrect demand.

func (*NativePeerConnectivity) BeginWave

func (n *NativePeerConnectivity) BeginWave(session [16]byte, pathID v2signal.PeerPathID)

func (*NativePeerConnectivity) ClaimPrewarm

func (n *NativePeerConnectivity) ClaimPrewarm(session [16]byte) bool

A speculative opportunity belongs to the authenticated session, even when its receiver constructs another PeerSet after the first path finishes.

func (*NativePeerConnectivity) Close

func (*NativePeerConnectivity) ClosePath

func (n *NativePeerConnectivity) ClosePath(session [16]byte, path v2signal.PeerPathID)

func (*NativePeerConnectivity) CloseSession

func (n *NativePeerConnectivity) CloseSession(session [16]byte)

func (*NativePeerConnectivity) CompleteObservations

func (n *NativePeerConnectivity) CompleteObservations() observationstream.Completion

func (*NativePeerConnectivity) Control

func (n *NativePeerConnectivity) Control(session [16]byte, pathID v2signal.PeerPathID, kind protocolsession.PeerPathControlKind, content bool) ([]byte, error)

func (*NativePeerConnectivity) Generation

func (n *NativePeerConnectivity) Generation(session [16]byte, path v2signal.PeerPathID) uint64

func (*NativePeerConnectivity) Idle

func (n *NativePeerConnectivity) Idle(ctx context.Context, session [16]byte, pathID v2signal.PeerPathID, until time.Time)

Idle transfers only a previously reserved attempt's bounded wait to the socket authority. DNS failure never turns into a transport retry decision.

func (*NativePeerConnectivity) Maintain

func (n *NativePeerConnectivity) Maintain(ctx context.Context)

Maintain is called by the demand owner. It never creates a PeerConnection or renews the application's demand lifetime.

func (*NativePeerConnectivity) NetworkGeneration

func (n *NativePeerConnectivity) NetworkGeneration() uint64

NetworkGeneration includes snapshots without a live path, so exhausted recovery budgets can be reconsidered after the network changes.

func (*NativePeerConnectivity) NewPeerConnection

func (n *NativePeerConnectivity) NewPeerConnection(ctx context.Context, request AttemptRequest) (*pionpeer.Connection, error)

func (*NativePeerConnectivity) Observations

func (n *NativePeerConnectivity) Observations() <-chan Observation

func (*NativePeerConnectivity) ObserveContentRecovery

func (n *NativePeerConnectivity) ObserveContentRecovery(subject Subject, direct bool)

func (*NativePeerConnectivity) ObserveParallelism

func (n *NativePeerConnectivity) ObserveParallelism(subject Subject, decision throughput.Decision, demand throughput.Observation)

func (*NativePeerConnectivity) ObserveTURN

func (n *NativePeerConnectivity) ObserveTURN(event turnpath.Event)

ObserveTURN shares the bounded native diagnostic stream while preserving the path's identity even before an ICE attempt exists.

func (*NativePeerConnectivity) PrepareAttempt

func (n *NativePeerConnectivity) PrepareAttempt(ctx context.Context, request AttemptRequest) (*PreparedAttempt, error)

func (*NativePeerConnectivity) Retired

func (n *NativePeerConnectivity) Retired(session [16]byte, pathID v2signal.PeerPathID) bool

func (*NativePeerConnectivity) RunSession

func (n *NativePeerConnectivity) RunSession(ctx context.Context, session [16]byte, send func(context.Context, []byte) error)

RunSession maintains demand facts only; it cannot allocate attempts.

func (*NativePeerConnectivity) SetAdmitted

func (n *NativePeerConnectivity) SetAdmitted(session [16]byte, pathID v2signal.PeerPathID, direct bool)

func (*NativePeerConnectivity) SetDemand

func (n *NativePeerConnectivity) SetDemand(session [16]byte, path v2signal.PeerPathID, content, direct bool) (<-chan Change, error)

Demand is the only authority for gateway work. Browsing can allocate an ICE path but cannot turn a speculative connection into a router mapping request.

type NetworkMonitor

type NetworkMonitor interface {
	Poll(context.Context, time.Time) (networkstate.Snapshot, bool, error)
}

type Observation

type Observation struct {
	Subject      Subject
	Provider     *pionpeer.Event
	Reachability *reachability.Event
	Lifecycle    *LifecycleFacts
	Admission    *AdmissionFacts
	Socket       *socketauthority.Event
	TURN         *turnpath.Event
	Parallelism  *ParallelismFacts
}

An absent identity means unknown attribution. A path-owned gateway operation can outlive an attempt, so it never borrows the currently active attempt ID.

func (Observation) DiagnosticRecord

func (value Observation) DiagnosticRecord() diag.Record

type ParallelismFacts

type ParallelismFacts struct {
	At       time.Time
	Decision throughput.Decision
	Demand   throughput.Observation
}

type PreparedAttempt

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

PreparedAttempt owns an admitted application opportunity. Separation from Start lets receivers queue before signaling; an incoming sender offer instead queues within its already-running preparation deadline. Neither spends ICE time.

func (*PreparedAttempt) Close

func (p *PreparedAttempt) Close()

Close abandons a preparation which has not transferred to a pionpeer. Once Start succeeds, provider close or authenticated lane admission settles it.

func (*PreparedAttempt) Matches

func (p *PreparedAttempt) Matches(session [16]byte, binding v2signal.Binding) bool

func (*PreparedAttempt) Start

type Subject

type Subject struct {
	ProtocolSessionID   [16]byte
	PeerPathID          [16]byte
	AttemptID           [16]byte
	AttemptSequence     uint64
	NetworkGenerationID uint64
	ICEProfileID        string
	Side                string
}

Jump to

Keyboard shortcuts

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