turnruntime

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: 19 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 turnruntime owns TURN settings, shared account budgets and demand-driven discovery.

Index

Constants

View Source
const (
	MaximumProfiles          = 8
	MaximumAccounts          = 8
	MaximumOutstandingLeases = 32
	IssuanceTimeout          = 15 * time.Second
)
View Source
const (
	StaticIssuer     = "static"
	CloudflareIssuer = "cloudflare"
	CoturnIssuer     = "coturn"
)
View Source
const DelegationNotice = "" /* 214-byte string literal not displayed */
View Source
const (
	MaximumManagedServices = 64
)

Variables

View Source
var (
	ErrConfiguration = errors.New("invalid TURN settings")
	ErrBudget        = turnpath.ErrBudget
	ErrCapacity      = errors.New("TURN account lease capacity exhausted")
	ErrClosed        = errors.New("TURN runtime closed")
)

Functions

This section is empty.

Types

type AccountSettings

type AccountSettings struct {
	ID               string               `json:"id"`
	Provider         string               `json:"provider"`
	Issuer           string               `json:"issuer"`
	LocalBudgetBytes uint64               `json:"local_budget_bytes"`
	Credentials      json.RawMessage      `json:"credentials"`
	Analytics        *CloudflareAnalytics `json:"analytics,omitempty"`
}

type Cache

Cache is optional. Runtime authority changes do not depend on durable writes.

type Capability

type Capability struct {
	ServiceID string `json:"service_id"`
	Enabled   bool   `json:"enabled"`
}

Capability is a deployment observation, never a credential or a user policy.

func (Capability) Validate

func (capability Capability) Validate() error

type CloudflareAnalytics

type CloudflareAnalytics struct {
	AccountID string `json:"account_id"`
	APIToken  string `json:"api_token"`
}

type CloudflareCredentials

type CloudflareCredentials struct {
	KeyID           string `json:"key_id"`
	APIToken        string `json:"api_token"`
	LifetimeSeconds uint32 `json:"lifetime_seconds,omitempty"`
}

type CoturnCredentials

type CoturnCredentials struct {
	SharedSecret    string `json:"shared_secret"`
	LifetimeSeconds uint32 `json:"lifetime_seconds,omitempty"`
}

type Dependencies

type Dependencies struct {
	Client  HTTPClient
	Now     func() time.Time
	Observe func(Event)
	Cache   Cache
}

type Event

type Event struct {
	At                          time.Time
	Identity                    ServiceIdentity
	Subject                     SessionSubject
	Revision                    uint64
	ProfileRevision             uint64
	Milestone                   string
	ResourceID                  string
	Attempt                     int
	Reason                      string
	Usage                       TrafficUsage
	ProviderRevocationConfirmed bool
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type ManagedPolicy

type ManagedPolicy struct {
	RelayURL         string `json:"relay_url"`
	LocalBudgetBytes uint64 `json:"local_budget_bytes"`
}

func (ManagedPolicy) Validate

func (policy ManagedPolicy) Validate() error

type ManagedSettings

type ManagedSettings struct {
	Relays   []relayprofile.Candidate
	Policies []ManagedPolicy
}

ManagedSettings projects deployment authority from the application's relay profiles. TURN does not own relay selection, frontend settings or enrollment.

func (ManagedSettings) Validate

func (settings ManagedSettings) Validate() error

type ManualSettings

type ManualSettings struct {
	Accounts []AccountSettings `json:"accounts"`
	Profiles []ProfileSettings `json:"profiles"`
}

ManualSettings is the persisted, device-owned part of TURN settings.

func (ManualSettings) Clone

func (settings ManualSettings) Clone() ManualSettings

func (ManualSettings) Validate

func (settings ManualSettings) Validate() error

type ProfileSettings

type ProfileSettings struct {
	ID      string   `json:"id"`
	Account string   `json:"account"`
	URLs    []string `json:"urls"`
}

type Runtime

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

Runtime owns account ledgers and discovery for one Engine lifetime. Settings replacement never replaces this owner or resets its accumulated usage.

func New

func New(settings Settings, dependencies Dependencies) (*Runtime, error)

func (*Runtime) Close

func (runtime *Runtime) Close() error

func (*Runtime) Configure

func (runtime *Runtime) Configure(settings Settings) error

Configure validates both manual and managed settings before publishing either. It does not contact issuers; existing leases retain their issuing source.

func (*Runtime) ForShare

func (runtime *Runtime) ForShare(ctx context.Context, relays []relayprofile.Candidate) (*Selection, func())

ForShare binds the selected deployments and registers discovery demand without waiting for remote discovery. Releasing one share cannot stop another's worker.

func (*Runtime) QueryUsage

func (runtime *Runtime) QueryUsage(ctx context.Context, account string, first, last time.Time) (Usage, error)

func (*Runtime) Status

func (runtime *Runtime) Status() []Status

type Selection

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

func (*Selection) Acquire

func (selection *Selection) Acquire(ctx context.Context, id string, subject turnpath.Subject) (*turnpath.Lease, error)

func (*Selection) Inventory

func (selection *Selection) Inventory() turnpath.Inventory

type ServiceIdentity

type ServiceIdentity struct{ Provider, Account, Profile string }

ServiceIdentity and SessionSubject retain attribution without exposing provider configuration.

type SessionSubject

type SessionSubject struct{ SessionID, PathID [16]byte }

type Settings

type Settings struct {
	Manual  ManualSettings
	Managed ManagedSettings
}

Settings is one desired configuration. Discovered capabilities are observations, not user settings, so a refresh cannot overwrite a budget or restore authority.

func (Settings) Clone

func (settings Settings) Clone() Settings

func (Settings) Validate

func (settings Settings) Validate() error

type StaticCredentials

type StaticCredentials struct {
	Username  string     `json:"username"`
	Password  string     `json:"password"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

type Status

type Status struct {
	AccountID, Provider string
	LocalBudgetBytes    uint64
	Usage               TrafficUsage
	ChargedBytes        uint64
	ActiveLeases        int
	PendingCleanup      int
	Exhausted           bool
	LastFailure         string
}

type TrafficUsage

type TrafficUsage struct{ Payload, Useful, TransportSent, TransportReceived uint64 }

TrafficUsage separates accepted application traffic from useful file content and socket accounting.

type Usage

type Usage struct {
	FirstDate, LastDate       time.Time
	EgressBytes, IngressBytes uint64
	Sampled                   bool
}

Usage is a provider estimate for complete UTC dates, distinct from the local transport budget and from an invoice.

Directories

Path Synopsis
internal
provider
Package provider implements credential issuers.
Package provider implements credential issuers.

Jump to

Keyboard shortcuts

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