server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func NamespacedName added in v1.1.0

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

Types

type ClientFilter added in v1.1.0

type ClientFilter[T comparable] func(expectedValue T) bool

ClientFilter lets a client to filter push notifications.

type Config

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

func (*Config) DeepCopy added in v1.1.0

func (c *Config) DeepCopy() *Config

func (*Config) DeepEqual added in v1.1.0

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 ConfigNodePatcher added in v1.1.0

type ConfigNodePatcher func(conf *stnrv1.StunnerConfig, node string) *stnrv1.StunnerConfig

ConfigNodePatcher is a callback to patch config updates per node name.

type ConfigStore

type ConfigStore[T comparable] struct {
	// contains filtered or unexported fields
}

func NewConfigStore

func NewConfigStore[T comparable]() *ConfigStore[T]

func (*ConfigStore[T]) Delete

func (cs *ConfigStore[T]) Delete(namespace, name string, stnrConfig *stnrv1.StunnerConfig)

Delete removes the config from the store and optionally sends the supplied config (usually a zero-config) to affected clients.

func (*ConfigStore[_]) Get

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

Get retrieves a config

func (*ConfigStore[T]) Push added in v1.1.0

func (cs *ConfigStore[T]) Push(arg T)

Push will re-broadcast configs to interested clients.

func (*ConfigStore[_]) Snapshot

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

Snapshot copies out all configs.

func (*ConfigStore[T]) SubscribeAll added in v1.1.0

func (cs *ConfigStore[T]) SubscribeAll(filter ClientFilter[T], patcher PatchFunc) chan *Config

SubscribeAll subscribes to all config changes

func (*ConfigStore[T]) SubscribeConfig added in v1.1.0

func (cs *ConfigStore[T]) SubscribeConfig(namespace, name string, filter ClientFilter[T], patcher PatchFunc) chan *Config

SubscribeConfig subscribes to changes for a specific config

func (*ConfigStore[T]) SubscribeNamespace added in v1.1.0

func (cs *ConfigStore[T]) SubscribeNamespace(namespace string, filter ClientFilter[T], patcher PatchFunc) chan *Config

SubscribeNamespace subscribes to all config changes in a specific namespace

func (*ConfigStore[_]) Unsubscribe added in v1.1.0

func (cs *ConfigStore[_]) Unsubscribe(ch chan *Config)

Unsubscribe removes a subscription

func (*ConfigStore[T]) UnsubscribeAll added in v1.1.0

func (cs *ConfigStore[T]) UnsubscribeAll()

Unsubscribe removes a subscription

func (*ConfigStore[T]) Upsert

func (cs *ConfigStore[T]) Upsert(namespace, name string, stnrConfig *stnrv1.StunnerConfig)

Upsert sets or updates a config and notifies 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 FilterFunc added in v1.1.0

type FilterFunc func(config *Config) bool

FilterFunc allows clients to filter configs.

type LicenseStore added in v1.1.0

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

func NewLicenseStore added in v1.1.0

func NewLicenseStore() *LicenseStore

func (*LicenseStore) Get added in v1.1.0

func (*LicenseStore) Upsert added in v1.1.0

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

type PatchFunc added in v1.1.0

type PatchFunc func(conf *stnrv1.StunnerConfig) *stnrv1.StunnerConfig

PatchFunc is a callback to patch config updates for a client.

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, patch ConfigNodePatcher, logger logr.Logger) *Server

New creates a new config discovery server instance for the specified address.

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 abruprly kill all listeners with all active connections allocated to them.

func (*Server) GetConfigStore

func (s *Server) GetConfigStore() *ConfigStore[string]

GetConfigStore returns the dataplane configs stores in 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 added in v1.1.0

(GET /api/v1/license)

func (*Server) ListV1Configs

(GET /api/v1/configs)

func (*Server) ListV1ConfigsNamespace

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

func (*Server) PushNodeConfig added in v1.1.0

func (s *Server) PushNodeConfig(node string)

PusNodeConfig updates the config at each known client that is subscribed for updates on a given node. This is useful for force pushing a new config when some node address changes.

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 added in v1.1.0

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

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

func (*Server) UpsertConfig

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

func (*Server) WSUpgradeMiddleware added in v0.17.1

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

type Subscription added in v1.1.0

type Subscription[T comparable] struct {
	// contains filtered or unexported fields
}

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