server

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 16 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

Index

Constants

View Source
const SubscribeChannelBufferSize = 256

SubscribeChannelBufferSize is the number of config updates a subscription can hold.

Variables

View Source
var (
	// SuppressConfigDeletion allows the server to suppress config deletions all together. Used
	// mostly for testing.
	SuppressConfigDeletion = false
)

Functions

func NamespacedName

func NamespacedName(id string) (string, string, bool)

Types

type Config

type Config struct {
	Namespace, Name string
	Config          *stnrv2.StunnerConfig
}

func (*Config) DeepCopy

func (c *Config) DeepCopy() *Config

func (*Config) DeepEqual

func (c *Config) DeepEqual(d *Config) bool

func (*Config) Id

func (c *Config) Id() string

func (*Config) String

func (c *Config) String() string

type ConfigList

type ConfigList = api.V1ConfigList

type ConfigStore

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

ConfigStore holds the configs and pushes every subscriber the config it would get, patched for the subscriber, whenever that differs from what the subscriber was last sent.

func NewConfigStore

func NewConfigStore(patcher Patcher) *ConfigStore

NewConfigStore creates a config store that patches the configs of its subscribers, nil for no patching.

func (*ConfigStore) Delete

func (cs *ConfigStore) Delete(namespace, name string, stnrConfig *stnrv2.StunnerConfig)

Delete removes a config and pushes the supplied config, usually a zero-config, to the subscribers; nil pushes nothing.

func (*ConfigStore) Get

func (cs *ConfigStore) Get(namespace, name string) (*Config, bool)

Get retrieves a config.

func (*ConfigStore) Patch

func (cs *ConfigStore) Patch(config *Config, labels map[string]string) *Config

Patch returns a copy of a config patched for a client with labels.

func (*ConfigStore) Refresh

func (cs *ConfigStore) Refresh()

Refresh patches every config again for every subscriber and pushes what changed: call it whenever what the patcher depends on may have changed.

func (*ConfigStore) Snapshot

func (cs *ConfigStore) Snapshot() []*Config

Snapshot copies out all configs.

func (*ConfigStore) SubscribeAll

func (cs *ConfigStore) SubscribeAll() chan *Config

SubscribeAll subscribes to all config changes, unpatched.

func (*ConfigStore) SubscribeConfig

func (cs *ConfigStore) SubscribeConfig(namespace, name string, labels map[string]string) chan *Config

SubscribeConfig subscribes to the changes of a config, patched for a client with labels.

func (*ConfigStore) SubscribeNamespace

func (cs *ConfigStore) SubscribeNamespace(namespace string) chan *Config

SubscribeNamespace subscribes to all config changes in a namespace, unpatched.

func (*ConfigStore) Unsubscribe

func (cs *ConfigStore) Unsubscribe(ch chan *Config)

Unsubscribe removes a subscription and closes its channel.

func (*ConfigStore) UnsubscribeAll

func (cs *ConfigStore) UnsubscribeAll()

UnsubscribeAll removes all subscriptions.

func (*ConfigStore) Upsert

func (cs *ConfigStore) Upsert(namespace, name string, stnrConfig *stnrv2.StunnerConfig)

Upsert sets or updates a config and pushes it to the subscribers.

type Conn

type Conn struct {
	*util.Conn
	// contains filtered or unexported fields
}

Conn represents a client WebSocket connection.

func NewConn

func NewConn(conn *websocket.Conn, ch chan *Config, cancel context.CancelFunc) *Conn

NewConn wraps a WebSocket connection.

func (*Conn) Id

func (c *Conn) Id() string

Id returns the IP 5-tuple for a client connection.

type ConnTrack

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

ConnTrack represents the server's connection tracking table.

func NewConnTrack

func NewConnTrack() *ConnTrack

NewConnTrack creates a new connection tracking table.

func (*ConnTrack) Delete

func (t *ConnTrack) Delete(conn *Conn)

Delete removes a client connection.

func (*ConnTrack) Get

func (t *ConnTrack) Get(cid string) *Conn

Get returns a client connection by the IP 5-tuple.

func (*ConnTrack) Snapshot

func (t *ConnTrack) Snapshot() []*Conn

Snapshot creates a snapshot of the connection tracking table.

func (*ConnTrack) Upsert

func (t *ConnTrack) Upsert(c *Conn)

Upsert insert a new client connection.

type LicenseStore

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

func NewLicenseStore

func NewLicenseStore() *LicenseStore

func (*LicenseStore) Get

func (*LicenseStore) Upsert

func (t *LicenseStore) Upsert(s stnrv2.LicenseStatus)

type Patcher

type Patcher func(conf *stnrv2.StunnerConfig, id string, labels map[string]string) *stnrv2.StunnerConfig

Patcher rewrites the config the server serves a client, given the config id the client watches and the labels it describes itself with; the server interprets neither the labels nor the patch. It gets a copy of its own and may modify it.

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

Server is a generic config discovery server implementation.

func New

func New(addr string, patcher Patcher, logger logr.Logger) *Server

New creates a new config discovery server instance for the specified address, patching the config it serves each client with patcher; nil patches nothing.

func (*Server) Close

func (s *Server) Close()

Close closes the server and drops all active connections.

func (*Server) DeleteConfig

func (s *Server) DeleteConfig(id string)

DeleteConfig removes a config from clients by sending a zero-config. Clients may decide to ignore the delete operation by (1) using client.IsConfigDeleted() to identify whether a config is being deleted and (2) selectively ignoring config delete updates based on the result. This is needed, e.g., in stunnerd, in order to avoid that a client being removed and entering the graceful shutdown cycle receive a zeroconfig and abruptly kill all listeners with all active connections allocated to them.

func (*Server) GetConfigStore

func (s *Server) GetConfigStore() *ConfigStore

GetConfigStore returns the dataplane config-store of the server.

func (*Server) GetConnTrack

func (s *Server) GetConnTrack() *ConnTrack

GetConnTrack returns the client connection tracking table of the server.

func (*Server) GetV1ConfigNamespaceName

(GET /api/v1/configs/{namespace}/{name})

func (*Server) GetV1LicenseStatus

(GET /api/v1/license)

func (*Server) ListV1Configs

(GET /api/v1/configs)

func (*Server) ListV1ConfigsNamespace

(GET /api/v1/configs/{namespace})

func (*Server) Refresh

func (s *Server) Refresh()

Refresh patches every config again for every client and pushes those that changed: call it whenever what the patcher depends on may have changed.

func (*Server) RemoveClient

func (s *Server) RemoveClient(id string)

RemoveClient forcefully closes a client connection. This is used mainly for testing.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start let the config discovery server listen to new client connections.

func (*Server) UpdateConfig

func (s *Server) UpdateConfig(newConfigs []Config) error

UpdateConfig receives a set of ids and newConfigs that represent the state-of-the-world at a particular instance of time and generates an update per each change.

func (*Server) UpdateLicenseStatus

func (s *Server) UpdateLicenseStatus(status stnrv2.LicenseStatus)

UpdateLicenseStatus updates the licensing status that is served by the server.

func (*Server) UpsertConfig

func (s *Server) UpsertConfig(id string, c *stnrv2.StunnerConfig)

func (*Server) WSUpgradeMiddleware

func (s *Server) WSUpgradeMiddleware(next api.StrictHandlerFunc, operationID string) api.StrictHandlerFunc

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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