controllerapi

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 43 Imported by: ? 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 controllerapi is the controller half of go-fabric-server: the WebSocket API at /ws, wire-compatible with matterjs-server's (schema 14, the python-matter-server contract Home Assistant's Matter integration speaks), over go-fabric's controller facade.

The shapes are the read map's (notes/reads/read-v8-matterjs-server.md, matterjs-server 0bd06f22): the dispatch table (§1.7), the arguments (§1.8), the results (§1.9), the node data (§2), the events (§1.5-1.6) and the connection model (§3.3-3.7) — server_info on connect, events only after start_listening has answered, the backpressure send path of protocol.Conn.

Lifecycle: New → wire Server.Hooks into the controller's node configuration → build the controller → Server.Start → serve Server.ServeHTTP at /ws → Server.Shutdown. The hooks come before the controller because the controller starts its nodes while it is built.

Index

Constants

View Source
const (
	CredentialWiFi   = "wifi"
	CredentialThread = "thread"
)

Credential kinds, as Credential.Kind names them.

Variables

View Source
var (
	// ErrInvalidCredential is a credential the store refuses: a blank
	// SSID, a blank password for a new entry or a changed SSID, a dataset
	// that is not MeshCoP TLVs.
	ErrInvalidCredential = errors.New("controllerapi: invalid credential")
	// ErrUnknownCredential is a kind and id the store does not hold.
	ErrUnknownCredential = errors.New("controllerapi: no such credential")
	// ErrLabelPinned is a label change while --default-fabric-label pins
	// the label.
	ErrLabelPinned = errors.New("controllerapi: the fabric label is pinned")
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Registry is the registry of the paired nodes.
	Registry() *client.Registry
	// Fabric is our fabric.
	Fabric() *commissioner.Fabric
	// Pair commissions the device a QR or manual pairing code names.
	Pair(ctx context.Context, code string, opts controller.PairOptions) (*client.Node, error)
	// Discover finds the commissionable devices id selects within
	// timeout (controller.Controller.Discover, go-fabric v0.12.1).
	Discover(ctx context.Context, id discovery.Identifier, timeout time.Duration) ([]client.Device, error)
}

Backend is the controller the API drives — go-fabric's *controller.Controller satisfies it. Everything the API does goes through these routes and the client nodes they hand out.

type Credential added in v0.4.0

type Credential struct {
	Kind, ID, Name string
	Default        bool
}

Credential is a stored credential's name, never its secret: Name is the Wi-Fi SSID or the Thread dataset's network name ("" when it names none). Default marks the entry commission_with_code falls back to when the request names no id (the id "default", bleNetwork).

type Options

type Options struct {
	// Version is go-fabric-server's version, for server_info's sdk_version.
	Version string
	// GoFabricVersion is the go-fabric module version, for sdk_version.
	GoFabricVersion string
	// StoragePath is the directory of the server's own settings
	// (server.json: credentials, the fabric label); "" keeps them in
	// memory.
	StoragePath string
	// DisableAutoSubscription is matterjs-server's
	// --disable-auto-subscription: new nodes are paired without the
	// server's own subscription, and subscribe/unsubscribe are available.
	DisableAutoSubscription bool
	// DefaultFabricLabel pins the fabric label; set_default_fabric_label
	// then succeeds without effect (--default-fabric-label).
	DefaultFabricLabel string
	// PairTimeout bounds a commissioning; 0 is 5 minutes.
	PairTimeout time.Duration
	// Logger receives the server's logs; nil discards them.
	Logger *slog.Logger
	// LogLevel is the level get_loglevel reports and set_loglevel changes;
	// nil is a fixed info.
	LogLevel *slog.LevelVar
	// Metrics receives the send path's metrics.
	Metrics protocol.Metrics
	// Conn overrides the backpressure defaults of each connection (tests).
	Conn protocol.ConnOptions
	// MaxInFlight bounds the requests a connection runs at once; 0 is 64.
	MaxInFlight int
	// Vendors lists the vendor names of get_vendor_names; nil is the
	// production DCL's vendor records.
	Vendors VendorSource
	// Attestation decides a commissioning whose device attestation has
	// findings; the zero value is matterjs-server's rule (attestationPolicy):
	// a test certificate the trust store does not accept and any error-level
	// finding refuse, info and warning findings (a test Certification
	// Declaration) do not.
	Attestation attestation.Policy
	// BLE is the Bluetooth LE central commission_with_code finds a device
	// on BLE through (--bluetooth-adapter or --bluetooth-proxy); nil commissions over DNS-SD only.
	BLE ble.Central
}

Options configures a Server.

type Server

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

Server is the controller half. Its methods are safe for concurrent use.

func New

func New(opts Options) (*Server, error)

New returns a server; it loads the settings under opts.StoragePath.

func (*Server) CameraObserver added in v0.7.0

func (s *Server) CameraObserver() camera.Observer

CameraObserver is the observer the camera service reports to: pass it as camera.Config.Observer to camera.New, before Start binds the service (as Hooks goes into the controller's configuration before the controller exists). Its callbacks queue frames and never block (service.go:69-70); none takes the server's lock.

func (*Server) Capabilities

func (s *Server) Capabilities() []string

Capabilities are the commands this server answers, sorted — the capabilities list of server_info (concept v8 C.1, our extension).

func (*Server) Credentials added in v0.4.0

func (s *Server) Credentials() []Credential

Credentials lists the stored credentials, Wi-Fi first, each kind by id — the entries get_all_credentials lists, without its placeholder default entries (an id-less set_wifi_credentials or set_thread_dataset stores the id "default", which is listed once stored).

func (*Server) FabricLabel

func (s *Server) FabricLabel() string

FabricLabel is the effective fabric label: the pinned one, else the stored one.

func (*Server) Health

func (s *Server) Health() (healthy bool, nodes int)

Health is the controller half's state for GET /health: healthy once started and until shut down.

func (*Server) Hooks

func (s *Server) Hooks(id string) client.Hooks

Hooks are the client node hooks the server needs for the node with the registry's local id: wire them as client.RegistryConfig.HooksFor. An empty id is hooks that cannot tell the nodes apart — what controller.Config.Node.Hooks takes today (report S1, Questions Q2): a change then refreshes every node, and node events, which only the hook's node could name, are not forwarded.

func (*Server) NodeCount

func (s *Server) NodeCount() int

NodeCount is the number of commissioned nodes the server knows.

func (*Server) PairOptions added in v0.4.0

func (s *Server) PairOptions() controller.PairOptions

PairOptions is the template of a commissioning outside /ws: the server's attestation policy and subscription mode, and its BLE central. A request's network is set on a copy.

func (*Server) RemoveCredential added in v0.4.0

func (s *Server) RemoveCredential(kind, id string) error

RemoveCredential is remove_wifi_credentials or remove_thread_dataset; a kind and id the store does not hold is ErrUnknownCredential, where the commands succeed without effect.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves one WebSocket connection of the controller half.

func (*Server) SetFabricLabel added in v0.4.0

func (s *Server) SetFabricLabel(ctx context.Context, label string) error

SetFabricLabel is set_default_fabric_label for a host surface: the label is normalized as the command's (trimmed, empty is "HomeAssistant", at most 32 characters), stored for the next start, set on the fabric at once and pushed to the nodes in the background. It does not claim the label for a connection; a pinned --default-fabric-label refuses it with ErrLabelPinned.

func (*Server) SetThreadDataset added in v0.4.0

func (s *Server) SetThreadDataset(id string, dataset []byte) error

SetThreadDataset is set_thread_dataset with the dataset's bytes: it must read as MeshCoP TLVs (thread.DecodeDataset); it is stored as the hex string the command stores.

func (*Server) SetWiFiCredential added in v0.4.0

func (s *Server) SetWiFiCredential(id, ssid, passphrase string) error

SetWiFiCredential is set_wifi_credentials: an empty id is the default entry, a blank passphrase keeps the stored one of an unchanged SSID.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown sends server_shutdown to every connection, waits until it is written (or ctx ends) and closes them; then the server stops following the controller. The controller itself is the caller's to close.

func (*Server) Start

func (s *Server) Start(ctx context.Context, b Backend, svc Services) error

Start binds the server to its controller and to its services (see Services): the node cache is built from the registry's nodes (no events for them), and changes are followed from then on. The server adds the imported test nodes to the topology as a source and sends its changes as network_topology_updated until Shutdown. The services stay the caller's to close, after Shutdown: the camera first (its Close ends the sessions the closing sockets did not release), then the topology.

func (*Server) ThreadDataset added in v0.4.0

func (s *Server) ThreadDataset(id string) (dataset []byte, ok bool)

ThreadDataset is the stored Thread dataset of id ("" the default one).

func (*Server) WiFiCredential added in v0.4.0

func (s *Server) WiFiCredential(id string) (ssid, passphrase string, ok bool)

WiFiCredential is the stored Wi-Fi entry of id ("" the default one), as a commissioning that names it provisions it.

type Services added in v0.7.0

type Services struct {
	// Topology is the network graph of the controller's nodes (go-fabric
	// controller/topology, built with topology.New, its Changes installed
	// on the controller's configuration): get_network_topology answers
	// from it, and network_topology_updated follows it. Required.
	Topology *topology.Service
	// Camera is the controller side of cameras (go-fabric
	// controller/camera, built with camera.New over a controller with
	// controller.Config.Camera and TCP.Outgoing, its Reports installed and
	// its Observer the server's [Server.CameraObserver]): the camera_*
	// commands and send_webrtc_provider_command map onto it (brief S8). A
	// backend without one does not offer those commands: they are left out
	// of capabilities and answered InvalidCommand naming the service.
	Camera *camera.Service
}

Services are the controller's services the server answers from, each built over the same controller as the backend; the next one (OTA) joins the struct.

type VendorSource added in v0.2.0

type VendorSource func(ctx context.Context) (map[uint16]string, error)

VendorSource lists the vendor names by vendor id — the DCL's vendor records (dcl.Client.Vendors) unless Options.Vendors sets another.

Jump to

Keyboard shortcuts

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