runtime

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package runtime is the kernel of the STUNner object system: it defines the node contracts (Runnable, Reconcilable, Object), the Registry that stores every live node keyed by (type, name) with parent edges, and the Runtime, the single cross-object access point carrying process-wide dependencies, registry-backed config/status lookups, and the readiness/shutdown flags.

Package runtime is the kernel of the STUNner object system: it defines the node contracts (Runnable, Reconcilable, Object), the Registry that stores every live node keyed by (type, name) with parent edges, and the Runtime, the single cross-object access point carrying process-wide dependencies, registry-backed config/status lookups, and the readiness/shutdown flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action is the reconciliation action an Object reports from Inspect.

const (
	// ActionNone means no object-local change is needed.
	ActionNone Action = iota
	// ActionReconcile means object-local state changes but no restart is required.
	ActionReconcile
	// ActionRestart means the object must be replaced: the reconciler closes it and starts a new
	// one built from the desired config.
	ActionRestart
)

type Config

type Config struct {
	Logger        logger.LoggerFactory
	DryRun        bool
	Resolver      resolver.DnsResolver
	Telemetry     *telemetry.Telemetry
	QuotaHandler  QuotaHandler
	License       licensecfg.ConfigManager
	OffloadEngine offload.Engine
	Net           transport.Net
	// Fifos are the in-process fifos the FIFO listeners bind and the FIFO clusters dial.
	Fifos *fifo.Fifos
	// BuildInfo is the version of the binary.
	BuildInfo buildinfo.BuildInfo
}

Config carries the process-wide dependencies shared by all objects. Set once at startup. The service interface QuotaHandler is declared in api.go; its implementation lives in internal/quota. OffloadEngine is a process-wide singleton owned by the Runtime (its eBPF lifetime is the server's lifetime); internal/offload is a one-way dependency.

type Object

type Object interface {
	Runnable
	Reconcilable
}

Object is the full contract for config-driven STUNner objects.

type ObjectType

type ObjectType string

ObjectType identifies a runtime object kind.

const (
	TypeStunner  ObjectType = "stunner"
	TypeAdmin    ObjectType = "admin"
	TypeAuth     ObjectType = "auth"
	TypeHealth   ObjectType = "health"
	TypeMetrics  ObjectType = "metrics"
	TypeOffload  ObjectType = "offload"
	TypeListener ObjectType = "listener"
	TypeCluster  ObjectType = "cluster"
	TypeServer   ObjectType = "server"
	TypeFilter   ObjectType = "filter"
)

Type names for the various object kinds.

type QuotaHandler

type QuotaHandler interface {
	CheckAndIncrement(username, realm string, quota int) bool
	Decrement(username, realm string)
}

QuotaHandler tracks per-user session quotas. CheckAndIncrement reports whether a new session is admissible for the (username, realm) pair given the quota and accounts for it; Decrement releases one previously admitted session. Implemented by internal/quota.

type Reconcilable

type Reconcilable interface {
	// GetConfig returns the live running config. Implementations MUST be safe for
	// concurrent use: the dataplane reads configs from request handlers while the
	// reconciler may be writing (use an atomic snapshot, see the concrete objects).
	GetConfig() stnrv2.Config
	// Inspect compares the live state (old), desired object config (new), and the full
	// desired StunnerConfig (full) and reports the object-local decision. Recursion into
	// children is handled by the reconciler walk, not Inspect.
	Inspect(old, new stnrv2.Config, full *stnrv2.StunnerConfig) (Action, error)
	// Reconcile applies a new config to the Object in place; a restart replaces the Object
	// instead.
	Reconcile(conf stnrv2.Config) error
	// Status returns the live status of the Object.
	Status() stnrv2.Status
}

Reconcilable is the desired-state convergence contract for config-driven objects.

type Registry

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

Registry stores every live node in the dataplane keyed by (Type, Name), plus a parent edge per node so the reconciler can walk subtrees. Thread-safe.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a new empty Registry.

func (*Registry) Add

func (r *Registry) Add(o Runnable, parent Runnable) error

Add registers a node under the given parent (nil for the root). Returns an error if a node with the same (type, name) already exists.

func (*Registry) ChildrenOf

func (r *Registry) ChildrenOf(parent Runnable, typ ObjectType) []Runnable

ChildrenOf returns the nodes of the given type whose parent is the given node, in stable (by name) order.

func (*Registry) Get

func (r *Registry) Get(typ ObjectType, name string) (Runnable, bool)

Get returns the named node of the given type, if present.

func (*Registry) List

func (r *Registry) List(typ ObjectType) []Runnable

List returns every node of the given type in stable (by name) order.

func (*Registry) Remove

func (r *Registry) Remove(o Runnable) error

Remove unregisters a node.

func (*Registry) Replace

func (r *Registry) Replace(old, o Runnable) error

Replace puts a node in place of the node of the same type and name, keeping its parent edge.

type Runnable

type Runnable interface {
	Name() string
	Type() ObjectType
	// Start brings the node online.
	Start() error
	// Close shuts the node down. The shutdown flag distinguishes terminate (true) from
	// reconcile-driven restart (false).
	Close(shutdown bool) error
}

Runnable is the minimal node contract in the object tree: identity plus lifecycle. The reconciler drives every node through it; config-driven objects add Reconcilable on top.

type Runtime

type Runtime struct {
	Config

	// Registry stores every live node in the dataplane.
	Registry *Registry
	// contains filtered or unexported fields
}

Runtime is the single cross-object access point: process-wide dependencies, the object Registry, and the process readiness/shutdown flags.

func New

func New(deps Config) *Runtime

New creates a Runtime with an empty Registry.

func (*Runtime) AuthConfig

func (rt *Runtime) AuthConfig(name string) *stnrv2.AuthConfig

AuthConfig returns the live config of the authentication policy of a name, nil if there is none.

func (*Runtime) ClusterConfig

func (rt *Runtime) ClusterConfig(name string) *stnrv2.ClusterConfig

ClusterConfig returns the config of the cluster of a name, nil if there is none.

func (*Runtime) Dialer

func (rt *Runtime) Dialer(name string) (api.Dialer, bool)

Dialer returns the dialer of the cluster of a name, false if there is none.

func (*Runtime) Filter

func (rt *Runtime) Filter(name string) (api.Filter, bool)

Filter returns the filter of a name.

func (*Runtime) GetConfig

func (rt *Runtime) GetConfig(objType ObjectType, name string) stnrv2.Config

GetConfig returns the live config of a node. An empty name resolves to the canonical singleton name of the type. Returns nil if the node is missing or not Reconcilable.

func (*Runtime) GetConfigs

func (rt *Runtime) GetConfigs(objType ObjectType) []stnrv2.Config

GetConfigs returns the live configs of every Reconcilable node of a type, in stable order. Lifecycle-only nodes are skipped.

func (*Runtime) GetStatus

func (rt *Runtime) GetStatus(objType ObjectType, name string) stnrv2.Status

GetStatus returns the live status of a node. An empty name resolves to the canonical singleton name of the type. Returns nil if the node is missing or not Reconcilable.

func (*Runtime) GetStatuses

func (rt *Runtime) GetStatuses(objType ObjectType) []stnrv2.Status

GetStatuses returns the live statuses of every Reconcilable node of a type, in stable order. Lifecycle-only nodes are skipped.

func (*Runtime) IsReady

func (rt *Runtime) IsReady() bool

IsReady returns true from the first config until the daemon closes, through the graceful shutdown; it backs the readiness probe.

func (*Runtime) IsShutdown

func (rt *Runtime) IsShutdown() bool

IsShutdown returns true if STUNner is in shutdown mode.

func (*Runtime) ListenerConfig

func (rt *Runtime) ListenerConfig(name string) *stnrv2.ListenerConfig

ListenerConfig returns the config of the listener of a name, nil if there is none.

func (*Runtime) Match

func (rt *Runtime) Match(names []string, addr net.Addr) (allow, matched bool)

Match runs the filters of the names, in order, on the traffic of an address: allow is the verdict of the first rule that matches it, matched is false when no rule does, and what that means is up to the caller. A missing filter has no rules.

func (*Runtime) Router

func (rt *Runtime) Router(name string) (api.Router, bool)

Router returns the router of the cluster of a name, false if there is none.

func (*Runtime) Server

func (rt *Runtime) Server(name string) (api.Server, bool)

Server returns the server of a name, false if there is none.

func (*Runtime) ServerConfig

func (rt *Runtime) ServerConfig(name string) *stnrv2.ServerConfig

ServerConfig returns the config of the server of a name, nil if there is none.

func (*Runtime) SetReady

func (rt *Runtime) SetReady(v bool)

SetReady updates the runtime readiness flag.

func (*Runtime) SetShutdown

func (rt *Runtime) SetShutdown(v bool)

SetShutdown updates shutdown mode. The graceful shutdown keeps the readiness on purpose: kube-proxy deletes the UDP conntrack entries of an endpoint that stops serving, which would cut the live UDP sessions, while a terminating pod gets no new traffic anyway. See the readiness probe in internal/object/health.go for the full story before changing this.

func (*Runtime) Tracing

func (rt *Runtime) Tracing(scope string) bool

Tracing tells whether the logger of a scope logs at the trace level: a hot path builds a trace message only then.

Jump to

Keyboard shortcuts

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