bridgeapi

package
v0.9.3 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: 158 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 bridgeapi is the bridge half of go-fabric-server: the /bridge API through which a host that is not written in Go declares devices, sends state deltas and answers what a controller asks of them (concept v8 C.3, brief S2 §1).

The half maps go-fabric's device kit one-to-one: a declaration is device.New with each cluster's generated <cluster>def.Declare, its initial state decoded into the generated Patch (clusters_gen.go, written by internal/gen from the snapshot's cluster list, holds one kit per typed package); the whole document is one Aggregator.Batch. set is the typed Server.Set, host is Device.Update, SetReachable and Rename. A change the host did not make is the changed event; a write or a command reaches the host as a write or command event only when the declaration opted in (OnWrite, Handle<Command>), with a correlation and a deadline.

Lifecycle: New → wire Server.Observers into node.Config.Observers → node.New and Start → Server.Start with the node → serve Server.ServeHTTP at /bridge → Server.Shutdown → stop the node. One bridge client at a time.

Index

Constants

View Source
const (
	ExtensionsFlag = "--bridge-extensions"
	SpecLevelFlag  = "--bridge-spec-level"
)

ExtensionsFlag and SpecLevelFlag are the daemon flags that set the node's surface policies the refusals name: the enabled "Ahead of matter.js" register IDs (surface.Policies.Extensions) and the specification level (surface.Policies.Level).

View Source
const BridgeSchemaVersion = 1

BridgeSchemaVersion is the schema number of the bridge half, apart from the controller half's (concept v8 C.1).

View Source
const StatusBusy websocket.StatusCode = 4409

StatusBusy is the WebSocket close status of a second bridge client: the daemon's node has one author (brief S2 §1.1).

Variables

This section is empty.

Functions

func Capabilities

func Capabilities() []string

Capabilities are the commands of the bridge half, sorted.

Types

type Options

type Options struct {
	// Version is go-fabric-server's version, GoFabricVersion go-fabric's,
	// for server_info's sdk_version.
	Version, GoFabricVersion string
	// ResultTimeout is how long a write or command event waits for its
	// result; 0 is 5 seconds.
	ResultTimeout time.Duration
	// SubscriptionPoll is how often the node's subscription count is
	// read for the subscriptions event; 0 is 5 seconds.
	SubscriptionPoll time.Duration
	// Logger receives the server's logs; nil discards them.
	Logger *slog.Logger
	// Metrics receives the send path's metrics.
	Metrics protocol.Metrics
	// Conn overrides the backpressure defaults of the connection (tests).
	Conn protocol.ConnOptions
	// MaxInFlight bounds the requests the client runs at once; 0 is 64.
	MaxInFlight int
	// Surface are the surface policies of the node the server binds to:
	// the node's node.Config.Surface, the same value. Every declared
	// device is built under them (device.Options.Surface), since the
	// node's Aggregator refuses a device composed under other policies
	// (go-fabric node.ErrPolicyMismatch). The zero value is no policy.
	Surface surface.Policies
	// Node is the key of the device node the server binds to, as the
	// daemon names it (its registry key, "default" for the --bridge-*
	// node); server_info reports it as node, so a client sees
	// which node it feeds. Empty reports "default".
	Node string
}

Options configures a Server.

type Server

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

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

func New

func New(opts Options) *Server

New returns a server.

func (*Server) Health

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

Health is the bridge half's state for GET /health: healthy once started and until shut down; devices is the declared device count.

func (*Server) Observers

func (s *Server) Observers() node.Observers

Observers are the node observers the server needs for its fabric_added, fabric_removed and commissioning_window events: wire them as node.Config.Observers before node.New.

func (*Server) ServeHTTP

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

ServeHTTP serves the bridge client's WebSocket. A second client while one is connected receives an error frame naming the holder and the close status StatusBusy.

func (*Server) Shutdown

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

Shutdown sends server_shutdown to the client, waits until it is written (or ctx ends) and closes it; pending results are answered. The node is the caller's to stop.

func (*Server) Start

func (s *Server) Start(_ context.Context, n *node.Node) error

Start binds the server to its node, which must have an Aggregator (no node.Config.Topology of the host's own); the node may be started before or after.

Jump to

Keyboard shortcuts

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