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 a7922e85): 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
- Variables
- type Backend
- type Credential
- type Options
- type Server
- func (s *Server) Capabilities() []string
- func (s *Server) Credentials() []Credential
- func (s *Server) FabricLabel() string
- func (s *Server) Health() (healthy bool, nodes int)
- func (s *Server) Hooks(id string) client.Hooks
- func (s *Server) NodeCount() int
- func (s *Server) PairOptions() controller.PairOptions
- func (s *Server) RemoveCredential(kind, id string) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetFabricLabel(ctx context.Context, label string) error
- func (s *Server) SetThreadDataset(id string, dataset []byte) error
- func (s *Server) SetWiFiCredential(id, ssid, passphrase string) error
- func (s *Server) Shutdown(ctx context.Context)
- func (s *Server) Start(ctx context.Context, b Backend) error
- func (s *Server) ThreadDataset(id string) (dataset []byte, ok bool)
- func (s *Server) WiFiCredential(id string) (ssid, passphrase string, ok bool)
- type VendorSource
Constants ¶
const ( CredentialWiFi = "wifi" CredentialThread = "thread" )
Credential kinds, as Credential.Kind names them.
Variables ¶
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
}
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).
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 rejects it (attestation.Reject), as
// matterjs-server without its test-net DCL option.
Attestation attestation.Policy
// BLE is the Bluetooth LE central commission_with_code finds a device
// on BLE through (--ble-adapter); 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 (*Server) Capabilities ¶
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 ¶
FabricLabel is the effective fabric label: the pinned one, else the stored one.
func (*Server) Health ¶
Health is the controller half's state for GET /health: healthy once started and until shut down.
func (*Server) 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) 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
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
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
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
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 ¶
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 ¶
Start binds the server to its controller: the node cache is built from the registry's nodes (no events for them), and changes are followed from then on.
func (*Server) ThreadDataset ¶ added in v0.4.0
ThreadDataset is the stored Thread dataset of id ("" the default one).
type VendorSource ¶ added in v0.2.0
VendorSource lists the vendor names by vendor id — the DCL's vendor records (dcl.Client.Vendors) unless Options.Vendors sets another.