Documentation
¶
Overview ¶
Package groups is the node's operational view of group communication: for every fabric, the group key sets in derived form (operational group keys, privacy keys, group session ids), the GroupKeyMap that binds a group to a key set, the group table that names the local endpoints of each group, the Groupcast cluster's per-group properties (multicast address policy, auxiliary-ACL flag), and the replay-protection state of received group messages. From these it derives what matter.js's GroupcastServer derives: the Groupcast Membership list, the multicast address of each group (the shared FF05::FA for the IanaAddr policy) and the auxiliary access control entries.
It is the Go counterpart of matter.js packages/protocol/src/groups (FabricGroups, Groups, KeySets, MessagingState) together with the receive half of packages/protocol/src/session/GroupSession.ts. The GroupKeyManagement and Groups cluster servers write the state, the bridge's receive path reads it to authenticate a group message and route it to the member endpoints, and the bridge joins the multicast address of every group that has a member endpoint.
Group membership is stack state, as in matter.js: a host neither supplies nor observes it.
The send half mirrors SessionManager.groupSessionForAddress and GroupSession.create / encode: Manager.Sender resolves a group's current operational key into an outbound group session, and Sender.Send — with Sender.Invoke and Sender.Write on top — frames, seals and privacy-obfuscates a message and sends it to the group's multicast address. Every message is numbered by the node-global, persisted group data message counter (counter.go).
Index ¶
- Constants
- Variables
- func MulticastAddress(fabricID uint64, groupID uint16) net.IP
- func OperationalKey(epochKey []byte, compressedFabricID [8]byte) ([]byte, error)
- func PrivacyKey(operationalKey []byte) ([]byte, error)
- func SessionID(operationalKey []byte) (uint16, error)
- type CounterStore
- type DecodeError
- type GroupMessageEvent
- type GroupProperties
- type GroupcastMembership
- type Manager
- func (m *Manager) AddEndpointForGroup(ctx context.Context, fabricIndex uint8, groupID, endpoint uint16, name string) error
- func (m *Manager) AuxiliaryACL(ctx context.Context, fabricIndex uint8) ([]store.ACLEntry, error)
- func (m *Manager) CurrentIPK(ctx context.Context, fabricIndex uint8) ([]byte, error)
- func (m *Manager) Decode(ctx context.Context, datagram []byte) (*Message, error)
- func (m *Manager) Fabrics(ctx context.Context) ([]uint8, error)
- func (m *Manager) ForgetFabric(fabricIndex uint8)
- func (m *Manager) GroupTable(ctx context.Context, fabricIndex uint8) ([]TableEntry, error)
- func (m *Manager) GroupcastMemberships(ctx context.Context) ([]GroupcastMembership, error)
- func (m *Manager) HasKeyMapping(ctx context.Context, fabricIndex uint8, groupID uint16) (bool, error)
- func (m *Manager) HasUsableKey(ctx context.Context, fabricIndex uint8, groupID uint16) (bool, error)
- func (m *Manager) IPKKeys(ctx context.Context, fabricIndex uint8) ([][]byte, error)
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) MaxGroupsPerFabric() int
- func (m *Manager) Memberships(ctx context.Context) ([]Membership, error)
- func (m *Manager) MulticastAddressFor(ctx context.Context, fabricIndex uint8, groupID uint16) (net.IP, error)
- func (m *Manager) OnGroupMessage(fn func(GroupMessageEvent)) (unsubscribe func())
- func (m *Manager) OnGroupTableChanged(fn func(fabricIndex uint8))
- func (m *Manager) OnGroupcastChanged(fn func(ctx context.Context, fabricIndex uint8))
- func (m *Manager) OnMembershipChanged(fn func())
- func (m *Manager) Reload(ctx context.Context, fabricIndex uint8) error
- func (m *Manager) RemoveEndpoint(ctx context.Context, fabricIndex uint8, endpoint, groupID uint16, all bool) (bool, error)
- func (m *Manager) RemoveEndpointRetainingSender(ctx context.Context, fabricIndex uint8, endpoint, groupID uint16) (bool, error)
- func (m *Manager) RemoveGroupProperties(ctx context.Context, fabricIndex uint8, groupID uint16) error
- func (m *Manager) ReportGroupMessage(ev GroupMessageEvent)
- func (m *Manager) Sender(ctx context.Context, fabricIndex uint8, groupID uint16) (*Sender, error)
- func (m *Manager) SetClock(c clock.Clock)
- func (m *Manager) SetGroupProperties(ctx context.Context, fabricIndex uint8, groupID uint16, policy *uint8, ...) error
- func (m *Manager) SetMaxGroupsPerFabric(n int)
- func (m *Manager) SetTransport(t MulticastTransport)
- func (m *Manager) StoredFabrics(ctx context.Context) ([]uint8, error)
- type Membership
- type Message
- type MulticastTransport
- type NoKeyErrordeprecated
- type RequestOptions
- type Sender
- func (s *Sender) Address() net.IP
- func (s *Sender) FabricIndex() uint8
- func (s *Sender) GroupID() uint16
- func (s *Sender) Invoke(ctx context.Context, path im.ConcreteCommandPath, fields spec.Encodable, ...) error
- func (s *Sender) KeySetID() uint16
- func (s *Sender) NodeID() uint64
- func (s *Sender) Send(ctx context.Context, payload []byte, protocol uint16, opcode uint8) error
- func (s *Sender) SessionID() uint16
- func (s *Sender) Write(ctx context.Context, path im.ConcreteAttributePath, value spec.Encodable, ...) error
- type Store
- type TableEntry
Constants ¶
const ( TestResultSuccess uint8 = 0 TestResultGeneralError uint8 = 1 TestResultMessageReplay uint8 = 2 TestResultFailedAuth uint8 = 3 TestResultNoAvailableKey uint8 = 4 TestResultSendFailure uint8 = 5 )
GroupcastTestResultEnum values (groupcast.element.ts), the outcome a received group message is reported with.
const ( // PolicyIanaAddr puts a group on the shared [IANAGroupcastAddress]. PolicyIanaAddr uint8 = 0 // PolicyPerGroup puts a group on its own fabric- and group-derived // address ([MulticastAddress]); conformance PGA. PolicyPerGroup uint8 = 1 )
MulticastAddrPolicyEnum values of the Groupcast cluster (groupcast.element.ts MulticastAddrPolicyEnum).
const DefaultMaxGroupsPerFabric = 22
DefaultMaxGroupsPerFabric mirrors matter.js GroupKeyManagementServer.State.maxGroupsPerFabric (22).
const DefaultMcastAddrPolicy = PolicyPerGroup
DefaultMcastAddrPolicy is the policy of a group without Groupcast properties — a group created through the Groups cluster — on a node whose Groupcast server supports the PerGroup feature, the only kind this module builds. Mirrors matter.js GroupcastServer #defaultMcastAddrPolicy ("PerGroup on PerGroupAddr-capable devices, so legacy groups stay on their ff35 per-group address") and Groups.multicastAddress, which uses the per-group address for a group without a policy.
const GroupDataCounterKey = "groupDataCounter"
GroupDataCounterKey is the matter_metadata key of the node-global Group Encrypted Data Message Counter. Mirrors matter.js packages/protocol/src/session/SessionManager.ts:226 at db021da0 (GROUP_DATA_COUNTER_KEY).
const UnmappedKeySetID uint16 = 0xFFFF
UnmappedKeySetID is the Membership KeySetId of a group GroupKeyMap does not bind to a key set. Mirrors matter.js GroupcastServer UNMAPPED_KEYSET_ID.
Variables ¶
var ( // ErrNotGroupMessage is returned for a datagram whose Security Flags // do not name a group session. ErrNotGroupMessage = errors.New("groups: not a group message") // ErrNoKey is what a [DecodeError] without a candidate key is: no // key set mapped to a group in GroupKeyMap has an epoch key with the // message's group session id. Mirrors the first message of matter.js // GroupSessionDecodeError (packages/protocol/src/session/ // GroupSession.ts:94-98 at db021da0). ErrNoKey = errors.New("groups: no key candidate for group message") // ErrDecrypt is what a [DecodeError] with candidate keys is: no // candidate authenticated the message for its destination group. // Mirrors the second message of matter.js GroupSessionDecodeError // (GroupSession.ts:94-98 at db021da0). ErrDecrypt = errors.New("groups: group message failed to authenticate") // ErrMalformed is returned for a group message that authenticated but // carries no source node id or no group id. ErrMalformed = errors.New("groups: malformed group message") )
Errors returned by Manager.Decode. Every one of them means the datagram is dropped without an answer.
var ( // ErrResourceExhausted is returned by [Manager.AddEndpointForGroup] // when the fabric already holds MaxGroupsPerFabric groups. Callers // answer it as IM ResourceExhausted. ErrResourceExhausted = errors.New("groups: too many groups for fabric") // ErrNoFabric is returned for a fabric index the store does not know. ErrNoFabric = errors.New("groups: fabric not found") )
Errors.
var ( // ErrKeyNotStarted is returned when every epoch key of the group's // key set starts in the future, so there is no current key to send // with. Mirrors matter.js GroupKeyNotStartedError // (packages/protocol/src/groups/errors.ts:21-26), thrown by // KeySets.currentKeyForId (KeySets.ts:108-114). Like [ErrNoKey] — its // sibling GroupKeySetMissingError (groups/errors.ts:18-19) for a group // GroupKeyMap does not map, or maps to a key set the fabric does not // hold — it is a NoUsableGroupKeyError: provisioning that is // incomplete or not yet in effect. ErrKeyNotStarted = errors.New("groups: no epoch key of the group's key set has started") // ErrNoInterface is returned when no transport can reach the group's // multicast address. Mirrors GroupSession.create's "IPv6 interface not // initialized" (GroupSession.ts:144-148). ErrNoInterface = errors.New("groups: no interface for the group's multicast address") // ErrInvalidGroupID is returned for group id 0. Mirrors // GroupId.assertGroupId (packages/types/src/datatype/GroupId.ts:54-58) // as SessionManager.groupSessionForAddress applies it (:714-715). ErrInvalidGroupID = errors.New("groups: a group id must be specified and can not be 0") // ErrInvalidGroupOperation is returned for a request a group cannot // carry: a timed request, a path naming an endpoint, an incomplete // write path. Mirrors matter.js InvalidGroupOperationError as // ClientGroupInteraction raises it // (packages/node/src/node/client/ClientGroupInteraction.ts:34-81). ErrInvalidGroupOperation = errors.New("groups: operation not supported on a group") )
Errors of Manager.Sender and Sender.Send.
var ErrEpochKeyLength = errors.New("groups: epoch key must be 16 bytes")
ErrEpochKeyLength is returned for an epoch key that is not 16 bytes.
var ErrNoCounterStore = errors.New("groups: the store cannot persist the group data counter")
ErrNoCounterStore is returned by Manager.Sender when the manager's store keeps no counter (CounterStore): matter.js persists the group data counter unconditionally (§4.6.1.3, "Persistence: Mandatory", MessageCounter.ts:22-26), so sending without one is refused.
var IANAGroupcastAddress = net.ParseIP("ff05::fa")
IANAGroupcastAddress is the IANA-assigned multicast address the Groupcast cluster's IanaAddr policy shares across groups and fabrics: FF05::FA. Mirrors matter.js packages/protocol/src/groups/Groups.ts IANA_GROUPCAST_MULTICAST_ADDRESS.
Functions ¶
func MulticastAddress ¶
MulticastAddress returns the IPv6 multicast address a fabric's group is reached on under the PerGroupID policy: FF35:0040:FD<FabricID>00:<GroupID> — a unicast-prefix-based, site-scoped address carrying the 64-bit fabric id and the 16-bit group id (Matter §2.5.6.2). Mirrors matter.js packages/protocol/src/groups/Groups.ts:multicastAddress.
func OperationalKey ¶
OperationalKey derives the operational group key of an epoch key: HKDF-SHA256 with the fabric's compressed fabric id (8 bytes, big-endian, as the commissioner computed it) as salt and "GroupKey v1.0" as info. Mirrors matter.js FabricGroups.setFromGroupKeySet (`createHkdfKey(epochKey, globalId, GROUP_SECURITY_INFO)`).
func PrivacyKey ¶
PrivacyKey derives the privacy key of an operational group key, the same derivation a unicast session uses (Matter §4.9.1). Mirrors matter.js MessagePrivacy.deriveKey as FabricGroups.setFromGroupKeySet calls it.
Types ¶
type CounterStore ¶ added in v0.4.0
type CounterStore interface {
GetMetadataCounter(ctx context.Context, key string) (value uint64, ok bool, err error)
SetMetadataCounter(ctx context.Context, key string, value uint64) error
}
CounterStore persists the group data counter. Every store.Port satisfies it (GetMetadataCounter / SetMetadataCounter on matter_metadata); a Store that does not implement it cannot send group messages (ErrNoCounterStore).
type DecodeError ¶
type DecodeError struct {
// CandidateFabrics are the fabrics with at least one candidate key —
// a key with the message's session id whose key set GroupKeyMap maps
// to a group — ascending and each once; empty when there was none.
CandidateFabrics []uint8
// GroupID is the group id the message names (HasGroupID), to derive
// the address it arrived on — never to be reported as the group:
// the destination of the first candidate that authenticated the
// message, else the id of a plain header; unset behind privacy when
// no candidate authenticated it.
GroupID uint16
HasGroupID bool
// GroupFabricIndex is the fabric whose candidate key authenticated
// GroupID, so it owns the id; 0 for an id from a plain header. It is
// not the fabric to report on.
GroupFabricIndex uint8
}
DecodeError is the outcome of a group message for which no candidate key passed: none authenticated it for its destination group, or there was no candidate at all. Any sender can cause it. It holds what is known about the message for the Groupcast testing report and nothing that lets it be processed. errors.Is matches ErrNoKey without candidates and ErrDecrypt with them. Mirrors matter.js GroupSessionDecodeError and GroupMessageRejection (packages/protocol/src/session/ GroupSession.ts:37-102 at db021da0).
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
func (*DecodeError) Event ¶
func (e *DecodeError) Event(sourceIP net.IP) GroupMessageEvent
Event is the report of the rejected message from sourceIP: it names no fabric, since no key passed, and carries the candidate fabrics and the group id with its owner for the listener — which reports it on its own fabric with GroupMessageEvent.ResultFor. Mirrors matter.js SessionManager.groupSessionFromPacket emitting `{ kind: "unauthenticated", candidateFabrics, group, sourceIp }` (packages/protocol/src/session/SessionManager.ts:809-820 at db021da0).
func (*DecodeError) Is ¶
func (e *DecodeError) Is(target error) bool
Is makes errors.Is(err, ErrNoKey) hold without a candidate and errors.Is(err, ErrDecrypt) with one.
type GroupMessageEvent ¶
type GroupMessageEvent struct {
// Result is a GroupcastTestResultEnum value.
Result uint8
// FabricIndex names the fabric whose key set authenticated the
// message, 0 when none did: then the event is the rejection of a
// message no candidate key passed ([DecodeError.Event]), and its
// listener reports it on its own fabric with [GroupMessageEvent
// .ResultFor].
FabricIndex uint8
// GroupID is the authenticated destination group (HasGroupID).
GroupID uint16
HasGroupID bool
// HeaderGroupID is the group id a rejected message names
// (HasHeaderGroupID) — fit to derive the arrival address, never to
// report as the group: the destination a candidate key authenticated,
// else the id of an unobfuscated wire header.
HeaderGroupID uint16
HasHeaderGroupID bool
// HeaderGroupFabricIndex is the fabric whose candidate key
// authenticated HeaderGroupID, so it owns the id; 0 for an id from a
// plain header. Mirrors matter.js GroupMessageRejection.Group
// .fabricIndex (packages/protocol/src/session/GroupSession.ts:58-65 at
// db021da0).
HeaderGroupFabricIndex uint8
// CandidateFabrics are, for a rejected message, the fabrics with at
// least one candidate key — a key with the message's session id whose
// key set GroupKeyMap maps to a group. Mirrors matter.js
// GroupMessageRejection.candidateFabrics (GroupSession.ts:43-47 at
// db021da0).
CandidateFabrics []uint8
// SourceIP is the sender's address, when known.
SourceIP net.IP
// HasPath reports that EndpointID, ClusterID and ElementID name the
// command the message dispatched; HasEndpoint whether EndpointID is
// set (a wildcard command path carries none).
HasPath bool
HasEndpoint bool
EndpointID uint16
ClusterID uint32
ElementID uint32
// AccessAllowed is the access-control outcome of a Success, nil when
// no access evaluation took place.
AccessAllowed *bool
}
GroupMessageEvent is the outcome of one received group message. Mirrors matter.js GroupMessageEventInfo (packages/protocol/src/session/ SessionManager.ts), which SessionManager.onGroupMessage carries to the Groupcast server's GroupcastTesting.
func (GroupMessageEvent) ResultFor ¶
func (ev GroupMessageEvent) ResultFor(fabricIndex uint8) uint8
ResultFor is the GroupcastTestResultEnum value the event is reported with on fabricIndex. For a rejected message (FabricIndex 0) it is FailedAuth when a key of fabricIndex was a candidate, NoAvailableKey otherwise; for any other event it is Result. Mirrors matter.js GroupMessageRejection.resultFor (packages/protocol/src/session/ GroupSession.ts:74-81 at db021da0).
type GroupProperties ¶
GroupProperties is the Groupcast cluster's state of one group of a fabric: matter.js GroupcastServer GroupPropertiesStruct without GroupId and FabricIndex. A group with properties is a Groupcast member even while the group table holds none of its endpoints.
type GroupcastMembership ¶
type GroupcastMembership struct {
FabricIndex uint8
GroupID uint16
// Endpoints are the group's local member endpoints, in the order they
// joined; empty for a group without one.
Endpoints []uint16
// KeySetID is the key set GroupKeyMap binds the group to, or
// [UnmappedKeySetID].
KeySetID uint16
HasAuxiliaryACL bool
McastAddrPolicy uint8
}
GroupcastMembership is one entry of the Groupcast Membership attribute (groupcast.element.ts MembershipStruct), derived from its sources: the Groupcast properties, the group table and the GroupKeyMap.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds the group state of every fabric of this node: what the GroupKeyManagement and Groups clusters configure, in the form the receive path needs to authenticate a group message and route it. Group membership is stack state, as in matter.js — the host supplies no part of it.
The persisted state lives in Store; the manager keeps the derived keys and the group table in memory, loading a fabric from the store the first time it is needed, and is told about every change by the cluster servers that make it. Safe for concurrent use.
func NewManager ¶
NewManager returns a manager over st. logger may be nil.
func (*Manager) AddEndpointForGroup ¶
func (m *Manager) AddEndpointForGroup(ctx context.Context, fabricIndex uint8, groupID, endpoint uint16, name string) error
AddEndpointForGroup makes endpoint a member of groupID on the fabric and sets the group's name. A new group beyond MaxGroupsPerFabric is refused with ErrResourceExhausted. Mirrors matter.js GroupKeyManagementServer.addEndpointForGroup: an existing group gains the endpoint (once) and always takes the new name.
func (*Manager) AuxiliaryACL ¶
AuxiliaryACL returns the auxiliary access control entries the Groupcast state grants — of one fabric, or of every fabric for fabricIndex 0: for each Membership entry with HasAuxiliaryACL and at least one listener endpoint, an Operate entry for the Group auth mode whose only subject is the group id and whose targets are the group's endpoints. Mirrors matter.js GroupcastServer #emitAuxAcl (core§11.27.10: sender-only memberships get none); the entries carry AuxiliaryType Groupcast on the wire.
func (*Manager) CurrentIPK ¶ added in v0.8.7
CurrentIPK returns the operational key of key set 0 an initiator uses for the CASE destination identifier: the second-newest of three, else the only one (matter.js Fabric.currentDestinationIdFor, Fabric.ts:391-393, KeySets.ts:113-121). ErrNoKey when the fabric has no key set 0, ErrNoFabric for an unknown fabric.
func (*Manager) Decode ¶
Decode authenticates a group message and returns it with the subject it is evaluated under.
Mirrors matter.js GroupSession.decodeWithCandidateKeys and SessionManager.groupSessionFromPacket at db021da0 (packages/protocol/src/session/GroupSession.ts:330-462, SessionManager.ts:806-820): the candidates are the epoch keys, across every fabric, whose group session id equals the message's session id; only key sets that GroupKeyMap maps a group to participate ("As in the CHIP SDK, a key set that no group maps to is never tried", GroupSession.ts:371-374); each candidate is tried in turn — privacy-deobfuscating the header with its privacy key when the P flag is set, then opening the AEAD with the nonce built from the Security Flags, the message counter and the source node id. A candidate that opens the message still fails when GroupKeyMap does not map the message's group to a key set holding its key (:425-433), or when its payload's protocol header does not parse (:435-442), and the next one is tried; the first that passes wins. Only then does the message counter pass the per-key, per-sender reception window (matter.js MessagingState.receptionStateFor, an encrypted-with-rollover window). When none passes, the error is a *DecodeError with the candidate fabrics and the group the message names (:454-461).
The input is not modified.
func (*Manager) Fabrics ¶
Fabrics returns the index of every fabric the store knows, ascending, loading each one's group state first.
func (*Manager) ForgetFabric ¶
ForgetFabric drops a removed fabric's group state, its reception state and its multicast memberships. The store's cascade has already removed the rows. Mirrors the FabricManager `deleting` handling of matter.js ServerGroupNetworking and the fabric's own disposal.
The fabric's Groupcast properties go with it, as matter.js GroupcastServer #handleFabricDeleted drops the departed fabric's groupProperties.
The replay windows the fabric's keys held are parked, not discarded: a fail-closed path forgets a fabric and loads it again from the store, and an unprimed window takes the first counter it sees, so a recorded datagram would be admitted once after the reload. The next load of the fabric index gives a key it brings back under the same key set id its windows again and drops the rest (restoreParked).
The fabric's reload from the store is owed (reloadOwed): the next Manager.Load loads it again on its own at once, a receive once the retry interval has passed (the first receive after the forget, then 1 s after a failure, doubling to 60 s). For a removed fabric that finds no row, and its parked windows go; a fabric the store still holds comes back — its keys on either path, its multicast memberships only through Load. While its load fails it stays absent and the other fabrics serve from memory. ForgetFabric waits for a store read in progress (storeMu), as every mutation does.
func (*Manager) GroupTable ¶
GroupTable returns the fabric's group table ordered by group id.
func (*Manager) GroupcastMemberships ¶
func (m *Manager) GroupcastMemberships(ctx context.Context) ([]GroupcastMembership, error)
GroupcastMemberships derives the Groupcast Membership list of every fabric: a group is a member while it has Groupcast properties or a group table entry (GroupKeyMap alone makes no member); Endpoints come from the group table, KeySetID from GroupKeyMap, the flags from the properties or their defaults. Ordered by fabric index, then group id. Mirrors matter.js GroupcastServer #deriveMembership, which rebuilds the attribute from the same three sources on every change of one of them.
func (*Manager) HasKeyMapping ¶
func (m *Manager) HasKeyMapping(ctx context.Context, fabricIndex uint8, groupID uint16) (bool, error)
HasKeyMapping reports whether the fabric's GroupKeyMap maps groupID to a key set. matter.js GroupsServer.addGroup answers UnsupportedAccess for a group without one (`fabric.groups.groupKeyIdMap.has(groupId)`).
func (*Manager) HasUsableKey ¶ added in v0.4.0
func (m *Manager) HasUsableKey(ctx context.Context, fabricIndex uint8, groupID uint16) (bool, error)
HasUsableKey reports whether the fabric maps the group to a key set it holds — matter.js BindingManager #holdsGroupKey (BindingManager.ts:466-474 at b25ed960): the GroupKeyMap entry alone is not a key.
func (*Manager) IPKKeys ¶ added in v0.8.7
IPKKeys returns the operational keys of the fabric's key set 0, the Identity Protection Key set, in slot order — matter.js Fabric.destinationIdsFor's candidates (Fabric.ts:399-403, `keySets.allKeysForId(0)`), each a 16-byte key derived from its epoch key with the compressed fabric id. Empty when the store holds no key set 0 for the fabric. ErrNoFabric for an unknown fabric.
func (*Manager) Load ¶
Load restores every fabric's group state from the store. Optional: the manager loads on demand; a host calls Load at start-up so the multicast memberships of persisted groups are joined before the first group message is due.
A fabric Manager.ForgetFabric dropped while the store still holds it is loaded again here, at once — or by a receive once the retry interval has passed (1 s after a failure, doubling to 60 s). Load returns the error of one that fails, which stays absent while the others serve. Only Load announces the multicast memberships again; a receive-path reload restores the keys, not the memberships.
func (*Manager) MaxGroupsPerFabric ¶
MaxGroupsPerFabric returns the cap AddEndpointForGroup enforces.
func (*Manager) Memberships ¶
func (m *Manager) Memberships(ctx context.Context) ([]Membership, error)
Memberships returns, for every loaded fabric, each group that has a member endpoint, with its multicast address — the addresses the node's socket must have joined. Membership follows group existence, not key availability, as in matter.js ServerGroupNetworking. The address follows the group's multicast policy (Manager.MulticastAddressFor): every group a Groupcast JoinGroup put on IanaAddr shares IANAGroupcastAddress, so callers deduplicate by address. Loads every fabric first.
func (*Manager) MulticastAddressFor ¶
func (m *Manager) MulticastAddressFor(ctx context.Context, fabricIndex uint8, groupID uint16) (net.IP, error)
MulticastAddressFor returns the multicast address groupID of the fabric is received on, following its policy. Mirrors matter.js FabricGroups.multicastAddressFor. Group id 0 is ErrInvalidGroupID.
func (*Manager) OnGroupMessage ¶
func (m *Manager) OnGroupMessage(fn func(GroupMessageEvent)) (unsubscribe func())
OnGroupMessage registers fn for the outcome of every received group message and returns the function that removes it again. fn runs synchronously on the receive path, outside the manager's locks, and must not block. Mirrors matter.js SessionManager.onGroupMessage, which the Groupcast server listens on only while a fabric is under test.
func (*Manager) OnGroupTableChanged ¶
OnGroupTableChanged registers fn to run after a fabric's group table changed — a group added or removed, an endpoint joining or leaving, a name changing. It is the change signal of GroupKeyManagement.GroupTable (matter.js reports the attribute from its reactive state). fn runs synchronously, outside the manager's locks.
func (*Manager) OnGroupcastChanged ¶
OnGroupcastChanged registers fn to run after a change of any source of the Groupcast Membership attribute on a fabric — the group table, the GroupKeyMap, the Groupcast properties — or the fabric's removal. ctx is the context of the change: the request that caused it when there was one, so a listener can name the administering node. fn runs synchronously, outside the manager's locks. Mirrors the reactors matter.js GroupcastServer registers on groupTable$Changed, groupKeyMap$Changed and the FabricManager events, each of which re-derives Membership and re-emits the auxiliary ACL.
func (*Manager) OnMembershipChanged ¶
func (m *Manager) OnMembershipChanged(fn func())
OnMembershipChanged registers fn to run after the set of groups with member endpoints changed on any fabric — the trigger for re-joining the multicast addresses. fn runs synchronously, outside the manager's locks. Mirrors the endpointMap observers matter.js ServerGroupNetworking registers (packages/node/src/behavior/system/network/ ServerGroupNetworking.ts:#registerFabricGroupObserver).
func (*Manager) Reload ¶
Reload re-reads one fabric's key sets and GroupKeyMap from the store after GroupKeyManagement changed them (KeySetWrite, KeySetRemove, a GroupKeyMap write). The reception state of an operational key that no key set derives any more is forgotten, so a later key set reusing that epoch key re-synchronises on its first message instead of being taken for a replay. Mirrors matter.js FabricGroups.setFromGroupKeySet / removeGroupKeySet with #forgetUnreferencedReceptionState, and Groups.idMap's setter.
func (*Manager) RemoveEndpoint ¶
func (m *Manager) RemoveEndpoint(ctx context.Context, fabricIndex uint8, endpoint, groupID uint16, all bool) (bool, error)
RemoveEndpoint removes endpoint from groupID — or, with all set, from every group of the fabric — and reports whether it was a member of any. A group whose last endpoint leaves is removed. Mirrors matter.js GroupKeyManagementServer.removeEndpoint.
func (*Manager) RemoveEndpointRetainingSender ¶ added in v0.4.0
func (m *Manager) RemoveEndpointRetainingSender(ctx context.Context, fabricIndex uint8, endpoint, groupID uint16) (bool, error)
RemoveEndpointRetainingSender removes endpoint from groupID as Manager.RemoveEndpoint does, except that a group losing its last endpoint keeps its Groupcast properties and so stays a sender-only member of the Groupcast Membership list — the Sender feature's kKeepGroupIfEmpty. The Groupcast server uses it where matter.js GroupcastServer marks a group retainedSenderOnly (JoinGroup emptying a group's endpoints, GroupcastServer.ts:262-292; LeaveGroup removing the last endpoint, :346-357), a mark the groupTable$Changed prune consumes instead of deleting the group (:631-646). Here the prune runs inside the removal, so the mark is this call.
func (*Manager) RemoveGroupProperties ¶
func (m *Manager) RemoveGroupProperties(ctx context.Context, fabricIndex uint8, groupID uint16) error
RemoveGroupProperties deletes the Groupcast properties of a group. Mirrors matter.js GroupcastServer #removeGroupProperties.
func (*Manager) ReportGroupMessage ¶
func (m *Manager) ReportGroupMessage(ev GroupMessageEvent)
ReportGroupMessage hands a group message's outcome to every listener registered with OnGroupMessage; without one it costs nothing. The receive path calls it. Mirrors matter.js SessionManager.emitGroupMessage.
func (*Manager) Sender ¶ added in v0.4.0
Sender returns the outbound group session for groupID on the fabric. Mirrors matter.js SessionManager.groupSessionForAddress (SessionManager.ts:712-744) with GroupSession.create (GroupSession.ts:129-167):
- :714-715 group id 0 is refused (ErrInvalidGroupID);
- :717 the fabric must exist (ErrNoFabric);
- :718-723 the group's current key (ErrNoKey, ErrKeyNotStarted);
- :725-732 a cached session for the same group, fabric, session id and operational key is reused — never one matched by session id alone;
- GroupSession.ts:141-142 the multicast address follows the group's policy (Manager.MulticastAddressFor), fixed at creation as the session's is;
- :144-148 without a transport there is no interface for it (ErrNoInterface);
- :163 the privacy key is derived from the operational key;
- :742 the node-global group data counter numbers every message — a store that cannot persist it refuses (ErrNoCounterStore).
func (*Manager) SetClock ¶ added in v0.7.2
SetClock sets the clock that selects the current epoch key of a group send and paces the retry of a fabric reload Manager.ForgetFabric left owed; nil is clock.System. Call it before the first send and before the first forget.
func (*Manager) SetGroupProperties ¶
func (m *Manager) SetGroupProperties(ctx context.Context, fabricIndex uint8, groupID uint16, policy *uint8, hasAuxiliaryACL *bool) error
SetGroupProperties creates or updates the Groupcast properties of a group, applying only the fields given: a new entry takes DefaultMcastAddrPolicy and no auxiliary ACL for a field left nil. Mirrors matter.js GroupcastServer #upsertGroupProperties. A policy change of a group with member endpoints moves its multicast membership, as ServerGroupNetworking rebinds on a policy change.
func (*Manager) SetMaxGroupsPerFabric ¶
SetMaxGroupsPerFabric sets the cap AddEndpointForGroup enforces. The GroupKeyManagement cluster owns the value (its MaxGroupsPerFabric attribute) and pushes it here. Values below 1 are ignored.
func (*Manager) SetTransport ¶ added in v0.4.0
func (m *Manager) SetTransport(t MulticastTransport)
SetTransport sets the socket group messages leave through; nil detaches it, after which Manager.Sender answers ErrNoInterface.
type Membership ¶
Membership is one joined group of a fabric: the multicast address the node must listen on for it.
type Message ¶
type Message struct {
// Header is the message header with the privacy obfuscation removed.
Header message.Header
// Payload is the decrypted message: protocol header and application
// payload.
Payload []byte
// FabricIndex is the fabric whose key set authenticated the message.
FabricIndex uint8
// GroupID is the destination group — authoritative only now, since
// privacy obfuscates it on the wire.
GroupID uint16
// SourceNodeID is the sender.
SourceNodeID uint64
// LocalNodeID is this node's operational node id on FabricIndex — the
// id a path of the message that names a node is compared with
// (matter.js DataResponse.nodeId, the node's id on the session's
// fabric, packages/protocol/src/action/server/DataResponse.ts:57-62 at
// b25ed960).
LocalNodeID uint64
// KeySetID is the key set that authenticated the message.
KeySetID uint16
// HasValidMapping reports whether the key that authenticated the
// message belongs to the key set GroupKeyMap maps GroupID to. It is
// always true for a message Decode returns: a candidate key the group
// is not mapped to fails there, and the next one is tried (matter.js
// GroupSession.ts:431-433 at db021da0). Two key sets with identical
// key material share a session id, so the one that decrypted may
// differ from the one the group is mapped to; the check compares key
// material. Mirrors matter.js Groups.subjectForGroup.
HasValidMapping bool
// Endpoints are the local endpoints that are members of GroupID on
// the fabric, in the order they joined.
Endpoints []uint16
// Duplicate reports a message counter the reception state has seen
// for this sender and key already. Mirrors matter.js
// ExchangeManager's DuplicateMessageError branch for group sessions.
Duplicate bool
}
Message is a group message that authenticated under one of this node's operational group keys.
type MulticastTransport ¶ added in v0.4.0
MulticastTransport sends one datagram to an IPv6 multicast group — *udp.Listener (SendMulticast). It is the "UDP interface for the multicast address" of matter.js GroupSession.create (GroupSession.ts:144-153).
type NoKeyError
deprecated
type NoKeyError struct {
// Authenticated reports that an unmapped key set opened the message;
// FabricIndex and GroupID are set only then.
Authenticated bool
FabricIndex uint8
GroupID uint16
}
NoKeyError was the ErrNoKey outcome with the fabric and group an unmapped key set recovered.
Deprecated: Manager.Decode no longer returns it — a key set that GroupKeyMap maps no group to is never tried, as in matter.js (GroupSession.ts:366-376 at db021da0). A message no candidate passes is a DecodeError.
func (*NoKeyError) Error ¶
func (e *NoKeyError) Error() string
func (*NoKeyError) Is ¶
func (e *NoKeyError) Is(target error) bool
Is makes errors.Is(err, ErrNoKey) hold.
type RequestOptions ¶ added in v0.4.0
type RequestOptions struct {
// Timed asks for a timed request, which a group refuses
// ([ErrInvalidGroupOperation]; ClientGroupInteraction.ts:48-50,
// :74-76).
Timed bool
// DisableListChunking writes a list value as one AttributeDataIB; by
// default a group write lists a list value REPLACE-ALL with the empty
// list and one append per element, as a unicast write does (matter.js
// Write.ts chunkLists = true, :59, :149-171 at 0ceb202d).
DisableListChunking bool
}
RequestOptions configures Sender.Invoke and Sender.Write.
type Sender ¶ added in v0.4.0
type Sender struct {
// contains filtered or unexported fields
}
Sender is an outbound group session: it sends group messages to one group of one fabric under the group's current operational key. Obtain one from Manager.Sender. Group sessions are long-lived and do not use MRP: nothing is acknowledged, retransmitted or answered (GroupSession.ts:74-75, MessageExchange.ts:660). Safe for concurrent use.
func (*Sender) Address ¶ added in v0.4.0
Address is the IPv6 multicast address the sender sends to (port 5540).
func (*Sender) FabricIndex ¶ added in v0.4.0
FabricIndex is the fabric the sender sends on.
func (*Sender) Invoke ¶ added in v0.4.0
func (s *Sender) Invoke(ctx context.Context, path im.ConcreteCommandPath, fields spec.Encodable, opts RequestOptions) error
Invoke sends one command to the group. The path names the cluster and the command; a path naming an endpoint is refused, as is a timed invoke (ErrInvalidGroupOperation). The InvokeRequest carries SuppressResponse: invoking on a group yields no response by definition. fields is the request payload (a generated request's value), nil for an empty one. Mirrors ClientGroupInteraction.invoke (ClientGroupInteraction.ts:70-81) and the InvokeRequest encoding of im.MarshalInvokeRequestTLV.
func (*Sender) KeySetID ¶ added in v0.4.0
KeySetID is the key set whose current epoch key the sender uses.
func (*Sender) NodeID ¶ added in v0.4.0
NodeID is this node's node id on the fabric: the source node id of the messages.
func (*Sender) Send ¶ added in v0.4.0
Send sends one message — protocol and opcode with their payload — to the group as the initiator of a new exchange. Mirrors matter.js MessageExchange.#send on a group session (MessageExchange.ts:640-776) with GroupSession.encode (GroupSession.ts:251-287) and MessageCodec.encodePacket (MessageCodec.ts:440-445):
- MessageExchange.ts:719 the message counter is the next value of the node-global group data counter;
- :723-732 the packet header: Session ID the group session id, Session Type Group, the counter, the destination group id, the source node id our node id on the fabric, the P flag set (GroupSession.usePrivacy, GroupSession.ts:173-179), no destination node id, no message extensions;
- :660, :737-749 the payload header: a new exchange id, the initiator flag, no acknowledgement requested and none carried — a group session uses no MRP, so nothing is retransmitted (:752);
- GroupSession.ts:251-287 sealed under the operational group key and privacy-obfuscated (channel.EncryptGroup, channel.ObfuscateGroupHeader);
- GroupSession.ts:150-153 sent to the multicast address on port 5540.
func (*Sender) SessionID ¶ added in v0.4.0
SessionID is the group session id of the operational key — the Session ID of every message the sender sends.
func (*Sender) Write ¶ added in v0.4.0
func (s *Sender) Write(ctx context.Context, path im.ConcreteAttributePath, value spec.Encodable, opts RequestOptions) error
Write writes one attribute on the group. The path names the cluster and the attribute and no endpoint, or the write is refused, as is a timed write (ErrInvalidGroupOperation). The WriteRequest carries SuppressResponse: writing to a group yields no response. A list value is list-chunked in the one message — REPLACE-ALL with the empty list, then one append per element — unless the attribute is AccessControl's ACL or Extension or opts.DisableListChunking is set: ClientGroupInteraction.write hands the request to ClientInteraction.write (ClientGroupInteraction.ts:44-68 at db021da0), whose Write() builder chunks a list as a unicast write does (Write.ts:155-177). The encoding is im.WriteRequest.MarshalTLV's.
type Store ¶
type Store interface {
store.Groups
GetFabric(ctx context.Context, fabricIndex uint8) (store.FabricRecord, error)
ListFabrics(ctx context.Context) ([]store.FabricRecord, error)
ListGroupKeySets(ctx context.Context, fabricIndex uint8) ([]store.GroupKeySet, error)
ListGroupKeyMappings(ctx context.Context, fabricIndex uint8) ([]store.GroupKeyMapping, error)
}
Store is the persistence the manager reads its state from and writes group membership to: the store.Groups area of the persistence port and the fabric and key-set reads. Every store.Port satisfies it.
type TableEntry ¶
TableEntry is one group of a fabric with the local endpoints that are members of it — one GroupInfoMapStruct of GroupKeyManagement.GroupTable.