Documentation
¶
Overview ¶
Package discovery implements DNS-SD (mDNS) discovery for Matter nodes.
This package provides:
- Service advertising for commissionable, operational, and commissioner nodes
- Service resolution to discover other Matter nodes on the network
- TXT record encoding/decoding for Matter-specific attributes
Spec References:
- Section 4.3: Discovery
- Section 4.3.1: Commissionable Node Discovery (_matterc._udp)
- Section 4.3.2: Operational Discovery (_matter._tcp)
- Section 4.3.3: Commissioner Discovery (_matterd._udp)
Index ¶
- Constants
- Variables
- func DeviceTypeSubtype(deviceType uint32) string
- func FilterIPv4(ips []net.IP) []net.IP
- func FilterIPv6(ips []net.IP) []net.IP
- func GenerateCommissionableInstanceName() string
- func GetLocalAddresses() ([]net.IP, error)
- func GetLocalIPv6Addresses() ([]net.IP, error)
- func LongDiscriminatorSubtype(discriminator uint16) string
- func OperationalInstanceName(compressedFabricID [8]byte, nodeID fabric.NodeID) string
- func OperationalInstanceNameFromBytes(compressedFabricID []byte, nodeID uint64) string
- func ParseOperationalInstanceName(instanceName string) ([8]byte, fabric.NodeID, error)
- func ParseTXT(records []string) map[string]string
- func ShortDiscriminatorSubtype(shortDiscriminator uint8) string
- func SortIPsByPreference(ips []net.IP) []net.IP
- func VendorIDSubtype(vendorID fabric.VendorID) string
- type Advertiser
- func (a *Advertiser) Close() error
- func (a *Advertiser) GetInstanceName(serviceType ServiceType) string
- func (a *Advertiser) IsAdvertising(serviceType ServiceType) bool
- func (a *Advertiser) StartCommissionable(txt CommissionableTXT) error
- func (a *Advertiser) StartCommissioner(txt CommissionerTXT) error
- func (a *Advertiser) StartOperational(compressedFabricID [8]byte, nodeID fabric.NodeID, txt OperationalTXT) error
- func (a *Advertiser) Stop(serviceType ServiceType) error
- func (a *Advertiser) StopAll()
- type AdvertiserConfig
- type AdvertiserWithContext
- type CommissionableTXT
- type CommissionerTXT
- type CommissioningMode
- type ICDMode
- type MDNSResolver
- type MDNSServer
- type MDNSServerFactory
- type Manager
- func (m *Manager) Advertiser() *Advertiser
- func (m *Manager) BrowseCommissionable(ctx context.Context) (<-chan ResolvedService, error)
- func (m *Manager) BrowseCommissionableByDiscriminator(ctx context.Context, discriminator uint16) (<-chan ResolvedService, error)
- func (m *Manager) BrowseCommissionableByVendor(ctx context.Context, vendorID fabric.VendorID) (<-chan ResolvedService, error)
- func (m *Manager) BrowseCommissioner(ctx context.Context) (<-chan ResolvedService, error)
- func (m *Manager) BrowseOperational(ctx context.Context) (<-chan ResolvedService, error)
- func (m *Manager) Close() error
- func (m *Manager) DiscoverCommissionableNode(ctx context.Context, discriminator uint16) (*ResolvedService, error)
- func (m *Manager) IsAdvertising(serviceType ServiceType) bool
- func (m *Manager) LookupOperational(ctx context.Context, compressedFabricID [8]byte, nodeID fabric.NodeID) (*ResolvedService, error)
- func (m *Manager) Resolver() *Resolver
- func (m *Manager) StartCommissionable(txt CommissionableTXT) error
- func (m *Manager) StartCommissioner(txt CommissionerTXT) error
- func (m *Manager) StartOperational(compressedFabricID [8]byte, nodeID fabric.NodeID, txt OperationalTXT) error
- func (m *Manager) StopAdvertising(serviceType ServiceType) error
- func (m *Manager) StopAllAdvertising()
- type ManagerConfig
- type MockMDNSResolver
- func (m *MockMDNSResolver) Browse(ctx context.Context, service, domain string, entries chan<- *ServiceEntry) error
- func (m *MockMDNSResolver) ClearServices()
- func (m *MockMDNSResolver) Lookup(ctx context.Context, instance, service, domain string, ...) error
- func (m *MockMDNSResolver) RegisterService(service string, entry *ServiceEntry)
- type OperationalTXT
- type ResolvedService
- type Resolver
- func (r *Resolver) BrowseCommissionable(ctx context.Context) (<-chan ResolvedService, error)
- func (r *Resolver) BrowseCommissionableWithFilter(ctx context.Context, filter string) (<-chan ResolvedService, error)
- func (r *Resolver) BrowseCommissioner(ctx context.Context) (<-chan ResolvedService, error)
- func (r *Resolver) BrowseOperational(ctx context.Context) (<-chan ResolvedService, error)
- func (r *Resolver) DiscoverCommissionableNode(ctx context.Context, discriminator uint16) (*ResolvedService, error)
- func (r *Resolver) Lookup(ctx context.Context, serviceType ServiceType, instanceName string) (*ResolvedService, error)
- func (r *Resolver) LookupOperational(ctx context.Context, compressedFabricID [8]byte, nodeID fabric.NodeID) (*ResolvedService, error)
- type ResolverConfig
- type ServiceEntry
- type ServiceRegistration
- type ServiceType
Constants ¶
const ( // ServiceCommissionable is the DNS-SD service type for commissionable nodes. ServiceCommissionable = "_matterc._udp" // ServiceOperational is the DNS-SD service type for operational nodes. ServiceOperational = "_matter._tcp" // ServiceCommissioner is the DNS-SD service type for commissioners. ServiceCommissioner = "_matterd._udp" // DefaultDomain is the default mDNS domain. DefaultDomain = "local." )
DNS-SD service type strings.
const ( // TXTKeyDiscriminator is the discriminator key (12-bit value). TXTKeyDiscriminator = "D" // TXTKeyCommissioningMode is the commissioning mode key. TXTKeyCommissioningMode = "CM" // TXTKeyVendorProduct is the vendor/product ID key (format: "VID+PID"). TXTKeyVendorProduct = "VP" // TXTKeyDeviceType is the device type key. TXTKeyDeviceType = "DT" // TXTKeyDeviceName is the device name key (max 32 chars). TXTKeyDeviceName = "DN" // TXTKeyIdleInterval is the sleepy idle interval key (milliseconds). TXTKeyIdleInterval = "SII" // TXTKeyActiveInterval is the sleepy active interval key (milliseconds). TXTKeyActiveInterval = "SAI" // TXTKeyTCPSupported indicates TCP support. TXTKeyTCPSupported = "T" // TXTKeyICDMode is the ICD operating mode key. TXTKeyICDMode = "ICD" // TXTKeyPairingHint is the pairing hint bitmap. TXTKeyPairingHint = "PH" // TXTKeyPairingInstructions is the pairing instructions key. TXTKeyPairingInstructions = "PI" // TXTKeyCommissionerPasscode indicates commissioner passcode support. TXTKeyCommissionerPasscode = "CP" // TXTKeyJointFabric indicates Joint Fabric capabilities. TXTKeyJointFabric = "JF" )
TXT record key constants from Spec Section 4.3.1.4 and 4.3.2.5.
const CommissioningModeSubtype = "_CM"
CommissioningModeSubtype returns the subtype filter for nodes in commissioning mode.
const DefaultBrowseTimeout = 10 * time.Second
DefaultBrowseTimeout is the default timeout for browse operations.
const DefaultLookupTimeout = 5 * time.Second
DefaultLookupTimeout is the default timeout for lookup operations.
const DefaultPort = 5540
DefaultPort is the default Matter port.
const MaxDeviceNameLength = 32
MaxDeviceNameLength is the maximum length of the device name. Spec Section 4.3.1.9
const MaxDiscriminator = 0xFFF
MaxDiscriminator is the maximum valid discriminator value (12 bits).
Variables ¶
var ( // ErrClosed is returned when an operation is attempted on a closed component. ErrClosed = errors.New("discovery: closed") // ErrAlreadyStarted is returned when starting an already-started service. ErrAlreadyStarted = errors.New("discovery: already started") // ErrNotStarted is returned when stopping a service that was not started. ErrNotStarted = errors.New("discovery: not started") // ErrInvalidServiceType is returned for invalid or unknown service types. ErrInvalidServiceType = errors.New("discovery: invalid service type") // ErrInvalidDiscriminator is returned when the discriminator is out of range. // Valid range: 0-4095 (12 bits). ErrInvalidDiscriminator = errors.New("discovery: invalid discriminator (must be 0-4095)") // ErrInvalidDeviceName is returned when the device name exceeds the maximum length. // Maximum length: 32 characters. ErrInvalidDeviceName = errors.New("discovery: invalid device name (max 32 characters)") // ErrInvalidHostName is returned when the host name is empty or invalid. ErrInvalidHostName = errors.New("discovery: invalid host name") // ErrInvalidPort is returned when the port number is out of range. ErrInvalidPort = errors.New("discovery: invalid port (must be 1-65535)") // ErrNoAddresses is returned when no IP addresses are provided for advertising. ErrNoAddresses = errors.New("discovery: no IP addresses provided") // ErrServiceNotFound is returned when a requested service is not found. ErrServiceNotFound = errors.New("discovery: service not found") // ErrTimeout is returned when an operation times out. ErrTimeout = errors.New("discovery: operation timed out") // ErrInvalidInstanceName is returned when the instance name format is invalid. ErrInvalidInstanceName = errors.New("discovery: invalid instance name format") // ErrInvalidTXTRecord is returned when a TXT record has invalid format. ErrInvalidTXTRecord = errors.New("discovery: invalid TXT record format") )
Package-level sentinel errors for discovery operations.
Functions ¶
func DeviceTypeSubtype ¶
DeviceTypeSubtype returns the subtype filter for device type. Format: "_T<value>"
func FilterIPv4 ¶
FilterIPv4 returns only IPv4 addresses from the slice.
func FilterIPv6 ¶
FilterIPv6 returns only IPv6 addresses from the slice.
func GenerateCommissionableInstanceName ¶
func GenerateCommissionableInstanceName() string
GenerateCommissionableInstanceName generates a random 64-bit instance name for commissionable node discovery. Format: 16 uppercase hex characters. Spec Section 4.3.1
func GetLocalAddresses ¶
GetLocalAddresses returns all non-loopback IP addresses on the host.
func GetLocalIPv6Addresses ¶
GetLocalIPv6Addresses returns all non-loopback IPv6 addresses on the host.
func LongDiscriminatorSubtype ¶
LongDiscriminatorSubtype returns the subtype filter for long discriminator. Format: "_L<value>"
func OperationalInstanceName ¶
OperationalInstanceName constructs the DNS-SD instance name for operational discovery. Format: "<CompressedFabricID>-<NodeID>" where each is 16 uppercase hex characters. Spec Section 4.3.2.1
func OperationalInstanceNameFromBytes ¶
OperationalInstanceNameFromBytes creates an operational instance name from raw bytes.
func ParseOperationalInstanceName ¶
ParseOperationalInstanceName parses the instance name into compressed fabric ID and node ID. Returns an error if the format is invalid. Format must be exactly: 16 hex chars + "-" + 16 hex chars (33 chars total).
func ShortDiscriminatorSubtype ¶
ShortDiscriminatorSubtype returns the subtype filter for short discriminator. Format: "_S<value>"
func SortIPsByPreference ¶
SortIPsByPreference sorts IP addresses by preference per Spec 4.3.2.6. Priority order (highest to lowest):
- Global Unicast Addresses (routable on internet)
- Unique Local Addresses (ULA, fc00::/7)
- Link-Local Addresses (fe80::/10)
- Other addresses
This sorting helps ensure better connectivity for cross-network communication.
func VendorIDSubtype ¶
VendorIDSubtype returns the subtype filter for vendor ID. Format: "_V<value>"
Types ¶
type Advertiser ¶
type Advertiser struct {
// contains filtered or unexported fields
}
Advertiser publishes DNS-SD services to the network.
func NewAdvertiser ¶
func NewAdvertiser(config AdvertiserConfig) (*Advertiser, error)
NewAdvertiser creates a new Advertiser with the given configuration.
func (*Advertiser) Close ¶
func (a *Advertiser) Close() error
Close stops all services and closes the advertiser.
func (*Advertiser) GetInstanceName ¶
func (a *Advertiser) GetInstanceName(serviceType ServiceType) string
GetInstanceName returns the instance name for an active service. Returns empty string if the service is not active.
func (*Advertiser) IsAdvertising ¶
func (a *Advertiser) IsAdvertising(serviceType ServiceType) bool
IsAdvertising returns true if the given service type is currently being advertised.
func (*Advertiser) StartCommissionable ¶
func (a *Advertiser) StartCommissionable(txt CommissionableTXT) error
StartCommissionable begins advertising the commissionable node discovery service. Service type: _matterc._udp Spec Section 4.3.1
func (*Advertiser) StartCommissioner ¶
func (a *Advertiser) StartCommissioner(txt CommissionerTXT) error
StartCommissioner begins advertising the commissioner discovery service. Service type: _matterd._udp Spec Section 4.3.3
func (*Advertiser) StartOperational ¶
func (a *Advertiser) StartOperational(compressedFabricID [8]byte, nodeID fabric.NodeID, txt OperationalTXT) error
StartOperational begins advertising the operational discovery service. Service type: _matter._tcp Spec Section 4.3.2
func (*Advertiser) Stop ¶
func (a *Advertiser) Stop(serviceType ServiceType) error
Stop stops advertising a specific service type.
func (*Advertiser) StopAll ¶
func (a *Advertiser) StopAll()
StopAll stops all active service advertisements.
type AdvertiserConfig ¶
type AdvertiserConfig struct {
// HostName is the mDNS host name (e.g., from MAC address).
// If empty, a random name will be generated.
HostName string
// Port is the Matter port to advertise (default: 5540).
Port int
// Interfaces specifies which network interfaces to advertise on.
// If nil, all interfaces are used.
Interfaces []net.Interface
// ServerFactory is the factory for creating mDNS servers.
// If nil, the default pion/mdns factory is used.
ServerFactory MDNSServerFactory
// LoggerFactory for creating loggers.
LoggerFactory logging.LoggerFactory
}
AdvertiserConfig holds configuration for the Advertiser.
type AdvertiserWithContext ¶
type AdvertiserWithContext struct {
*Advertiser
// contains filtered or unexported fields
}
AdvertiserWithContext wraps an Advertiser with context support.
func NewAdvertiserWithContext ¶
func NewAdvertiserWithContext(ctx context.Context, config AdvertiserConfig) (*AdvertiserWithContext, error)
NewAdvertiserWithContext creates an Advertiser that can be cancelled via context.
func (*AdvertiserWithContext) Close ¶
func (a *AdvertiserWithContext) Close() error
Close cancels the context and closes the advertiser.
type CommissionableTXT ¶
type CommissionableTXT struct {
// Discriminator is the 12-bit discriminator (required).
// Spec Section 4.3.1.5
Discriminator uint16
// CommissioningMode indicates the current commissioning mode.
// Spec Section 4.3.1.3
CommissioningMode CommissioningMode
// VendorID is the vendor identifier (optional, from VP key).
// Spec Section 4.3.1.6
VendorID fabric.VendorID
// ProductID is the product identifier (optional, from VP key).
// Spec Section 4.3.1.6
ProductID uint16
// DeviceType is the primary device type identifier (optional).
// Spec Section 4.3.1.8
DeviceType uint32
// DeviceName is the human-readable device name (optional, max 32 chars).
// Spec Section 4.3.1.9
DeviceName string
// IdleInterval is the SESSION_IDLE_INTERVAL in milliseconds (optional).
// Spec Section 4.3.1.10
IdleInterval time.Duration
// ActiveInterval is the SESSION_ACTIVE_INTERVAL in milliseconds (optional).
// Spec Section 4.3.1.11
ActiveInterval time.Duration
// TCPSupported indicates whether the node supports TCP (optional).
// Spec Section 4.3.4
TCPSupported bool
// ICDMode is the ICD operating mode (optional).
// Spec Section 4.3.4
ICDMode ICDMode
ICDSet bool // Whether ICD was explicitly set
// PairingHint is the bitmap of pairing methods (optional).
// Spec Section 4.3.1.12
PairingHint uint16
// PairingInstructions provides additional pairing info (optional).
// Spec Section 4.3.1.14
PairingInstructions string
}
CommissionableTXT holds TXT records for _matterc._udp (Spec 4.3.1.4).
func ParseCommissionableTXT ¶
func ParseCommissionableTXT(records []string) (*CommissionableTXT, error)
ParseCommissionableTXT parses raw TXT records into CommissionableTXT.
func (*CommissionableTXT) Encode ¶
func (c *CommissionableTXT) Encode() []string
Encode converts the TXT record to DNS-SD format strings.
func (*CommissionableTXT) ShortDiscriminator ¶
func (c *CommissionableTXT) ShortDiscriminator() uint8
ShortDiscriminator returns the 4-bit short discriminator. Spec Section 4.3.1.5: short = (long >> 8) & 0xF
func (*CommissionableTXT) Validate ¶
func (c *CommissionableTXT) Validate() error
Validate checks that the TXT record values are within spec limits.
type CommissionerTXT ¶
type CommissionerTXT struct {
// VendorID is the vendor identifier (optional).
VendorID fabric.VendorID
// ProductID is the product identifier (optional).
ProductID uint16
// DeviceType is the primary device type identifier (optional).
DeviceType uint32
// DeviceName is the human-readable device name (optional, max 32 chars).
DeviceName string
// CommissionerPasscode indicates whether commissioner passcode is supported.
// Spec Section 4.3.3
CommissionerPasscode bool
}
CommissionerTXT holds TXT records for _matterd._udp (Spec 4.3.3).
func ParseCommissionerTXT ¶
func ParseCommissionerTXT(records []string) (*CommissionerTXT, error)
ParseCommissionerTXT parses raw TXT records into CommissionerTXT.
func (*CommissionerTXT) Encode ¶
func (c *CommissionerTXT) Encode() []string
Encode converts the TXT record to DNS-SD format strings.
func (*CommissionerTXT) Validate ¶
func (c *CommissionerTXT) Validate() error
Validate checks that the TXT record values are within spec limits.
type CommissioningMode ¶
type CommissioningMode int
CommissioningMode indicates the commissioning state of a node. Spec Section 4.3.1.3
const ( // CommissioningModeDisabled indicates the node is not currently in commissioning mode. // CM=0: Extended Discovery only, not accepting commissioning. CommissioningModeDisabled CommissioningMode = 0 // CommissioningModeBasic indicates basic commissioning mode. // CM=1: Node is in commissioning mode (e.g., factory reset, first boot). CommissioningModeBasic CommissioningMode = 1 // CommissioningModeEnhanced indicates enhanced commissioning mode. // CM=2: Administrator-opened commissioning window (OpenCommissioningWindow command). CommissioningModeEnhanced CommissioningMode = 2 )
CommissioningMode constants.
func (CommissioningMode) IsValid ¶
func (c CommissioningMode) IsValid() bool
IsValid returns true if the commissioning mode is valid.
func (CommissioningMode) String ¶
func (c CommissioningMode) String() string
String returns a human-readable string for the commissioning mode.
type ICDMode ¶
type ICDMode int
ICDMode indicates the operating mode of an Intermittently Connected Device. Spec Section 4.3.4
const ( // ICDModeSIT indicates Short Idle Time operating mode. // ICD=0: Device operates in Short Idle Time mode. ICDModeSIT ICDMode = 0 // ICDModeLIT indicates Long Idle Time operating mode. // ICD=1: Device operates in Long Idle Time mode. ICDModeLIT ICDMode = 1 )
ICDMode constants.
type MDNSResolver ¶
type MDNSResolver interface {
// Browse browses for services of the given type. The service may be a
// subtype browse name of the form "<subtype>._sub.<service>".
Browse(ctx context.Context, service, domain string, entries chan<- *ServiceEntry) error
// Lookup looks up a specific service instance.
Lookup(ctx context.Context, instance, service, domain string, entries chan<- *ServiceEntry) error
}
MDNSResolver is the interface for mDNS service resolution. This allows for dependency injection in tests.
Implementations send entries until ctx is done and then return; the caller owns and closes the entries channel.
type MDNSServer ¶
type MDNSServer interface {
// Shutdown stops the server.
Shutdown()
}
MDNSServer is the interface for mDNS service registration. This allows for dependency injection in tests.
type MDNSServerFactory ¶
type MDNSServerFactory interface {
// Register creates a new mDNS server for the given service.
Register(reg ServiceRegistration) (MDNSServer, error)
}
MDNSServerFactory creates MDNSServer instances.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates DNS-SD advertising and resolution for Matter.
func NewManager ¶
func NewManager(config ManagerConfig) (*Manager, error)
NewManager creates a new discovery Manager with the given configuration.
func (*Manager) Advertiser ¶
func (m *Manager) Advertiser() *Advertiser
Advertiser returns the underlying Advertiser for advanced usage.
func (*Manager) BrowseCommissionable ¶
func (m *Manager) BrowseCommissionable(ctx context.Context) (<-chan ResolvedService, error)
BrowseCommissionable discovers commissionable nodes on the network. Spec Section 4.3.1
func (*Manager) BrowseCommissionableByDiscriminator ¶
func (m *Manager) BrowseCommissionableByDiscriminator(ctx context.Context, discriminator uint16) (<-chan ResolvedService, error)
BrowseCommissionableByDiscriminator discovers commissionable nodes matching the discriminator.
func (*Manager) BrowseCommissionableByVendor ¶
func (m *Manager) BrowseCommissionableByVendor(ctx context.Context, vendorID fabric.VendorID) (<-chan ResolvedService, error)
BrowseCommissionableByVendor discovers commissionable nodes from a specific vendor.
func (*Manager) BrowseCommissioner ¶
func (m *Manager) BrowseCommissioner(ctx context.Context) (<-chan ResolvedService, error)
BrowseCommissioner discovers commissioners on the network. Spec Section 4.3.3
func (*Manager) BrowseOperational ¶
func (m *Manager) BrowseOperational(ctx context.Context) (<-chan ResolvedService, error)
BrowseOperational discovers operational nodes on the network. Spec Section 4.3.2
func (*Manager) DiscoverCommissionableNode ¶
func (m *Manager) DiscoverCommissionableNode(ctx context.Context, discriminator uint16) (*ResolvedService, error)
DiscoverCommissionableNode finds a commissionable node by discriminator. This is a convenience method that browses and returns the first match.
func (*Manager) IsAdvertising ¶
func (m *Manager) IsAdvertising(serviceType ServiceType) bool
IsAdvertising returns true if the given service type is currently being advertised.
func (*Manager) LookupOperational ¶
func (m *Manager) LookupOperational(ctx context.Context, compressedFabricID [8]byte, nodeID fabric.NodeID) (*ResolvedService, error)
LookupOperational looks up a specific operational node. This is the primary method for finding a known commissioned node before establishing a CASE session. Spec Section 4.3.2
func (*Manager) StartCommissionable ¶
func (m *Manager) StartCommissionable(txt CommissionableTXT) error
StartCommissionable begins advertising as a commissionable node. This should be called when the device enters commissioning mode. Spec Section 4.3.1
func (*Manager) StartCommissioner ¶
func (m *Manager) StartCommissioner(txt CommissionerTXT) error
StartCommissioner begins advertising as a commissioner. This should be called when the device acts as a commissioner. Spec Section 4.3.3
func (*Manager) StartOperational ¶
func (m *Manager) StartOperational(compressedFabricID [8]byte, nodeID fabric.NodeID, txt OperationalTXT) error
StartOperational begins advertising as an operational (commissioned) node. This should be called after the device is commissioned onto a fabric. Spec Section 4.3.2
func (*Manager) StopAdvertising ¶
func (m *Manager) StopAdvertising(serviceType ServiceType) error
StopAdvertising stops advertising a specific service type.
func (*Manager) StopAllAdvertising ¶
func (m *Manager) StopAllAdvertising()
StopAllAdvertising stops all active service advertisements.
type ManagerConfig ¶
type ManagerConfig struct {
// HostName is the mDNS host name (e.g., derived from MAC address).
// If empty, a default will be generated.
HostName string
// Port is the Matter port to advertise (default: 5540).
Port int
// Interfaces specifies which network interfaces to use.
// If nil, all interfaces are used.
Interfaces []net.Interface
// BrowseTimeout is the default timeout for browse operations.
// If zero, DefaultBrowseTimeout is used.
BrowseTimeout time.Duration
// LookupTimeout is the default timeout for lookup operations.
// If zero, DefaultLookupTimeout is used.
LookupTimeout time.Duration
// ServerFactory is the factory for creating mDNS servers (for testing).
ServerFactory MDNSServerFactory
// MDNSResolver is the mDNS resolver implementation (for testing).
MDNSResolver MDNSResolver
// LoggerFactory is the factory for creating loggers.
// If nil, logging is disabled.
LoggerFactory logging.LoggerFactory
}
ManagerConfig holds configuration for the discovery Manager.
type MockMDNSResolver ¶
type MockMDNSResolver struct {
// contains filtered or unexported fields
}
MockMDNSResolver provides a mock mDNS resolver for testing without real network I/O. It allows registering services and simulating discovery responses.
func NewMockMDNSResolver ¶
func NewMockMDNSResolver() *MockMDNSResolver
NewMockMDNSResolver creates a new mock resolver.
func (*MockMDNSResolver) Browse ¶
func (m *MockMDNSResolver) Browse(ctx context.Context, service, domain string, entries chan<- *ServiceEntry) error
Browse implements MDNSResolver.
func (*MockMDNSResolver) ClearServices ¶
func (m *MockMDNSResolver) ClearServices()
ClearServices removes all registered services.
func (*MockMDNSResolver) Lookup ¶
func (m *MockMDNSResolver) Lookup(ctx context.Context, instance, service, domain string, entries chan<- *ServiceEntry) error
Lookup implements MDNSResolver.
func (*MockMDNSResolver) RegisterService ¶
func (m *MockMDNSResolver) RegisterService(service string, entry *ServiceEntry)
RegisterService registers a service that will be returned by Browse/Lookup.
type OperationalTXT ¶
type OperationalTXT struct {
// IdleInterval is the SESSION_IDLE_INTERVAL in milliseconds (optional).
IdleInterval time.Duration
// ActiveInterval is the SESSION_ACTIVE_INTERVAL in milliseconds (optional).
ActiveInterval time.Duration
// TCPSupported indicates whether the node supports TCP (optional).
TCPSupported bool
// ICDMode is the ICD operating mode (optional).
ICDMode ICDMode
ICDSet bool // Whether ICD was explicitly set
}
OperationalTXT holds TXT records for _matter._tcp (Spec 4.3.2.5).
func ParseOperationalTXT ¶
func ParseOperationalTXT(records []string) (*OperationalTXT, error)
ParseOperationalTXT parses raw TXT records into OperationalTXT.
func (*OperationalTXT) Encode ¶
func (o *OperationalTXT) Encode() []string
Encode converts the TXT record to DNS-SD format strings.
type ResolvedService ¶
type ResolvedService struct {
// ServiceType is the type of the discovered service.
ServiceType ServiceType
// InstanceName is the DNS-SD instance name.
InstanceName string
// HostName is the target host name.
HostName string
// Port is the service port.
Port int
// IPs contains the resolved IP addresses, sorted by preference.
IPs []net.IP
// Text contains the raw TXT record key-value pairs.
Text map[string]string
}
ResolvedService contains information about a discovered DNS-SD service.
func (*ResolvedService) IPv4Addresses ¶
func (r *ResolvedService) IPv4Addresses() []net.IP
IPv4Addresses returns only IPv4 addresses from the service.
func (*ResolvedService) IPv6Addresses ¶
func (r *ResolvedService) IPv6Addresses() []net.IP
IPv6Addresses returns only IPv6 addresses from the service.
func (*ResolvedService) PreferredIP ¶
func (r *ResolvedService) PreferredIP() net.IP
PreferredIP returns the most preferred IP address (first in the sorted list). Returns nil if no addresses are available.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver discovers Matter services via DNS-SD.
func NewResolver ¶
func NewResolver(config ResolverConfig) (*Resolver, error)
NewResolver creates a new Resolver with the given configuration.
func (*Resolver) BrowseCommissionable ¶
func (r *Resolver) BrowseCommissionable(ctx context.Context) (<-chan ResolvedService, error)
BrowseCommissionable discovers commissionable nodes on the network. Returns a channel that receives discovered services until the context is cancelled or the browse timeout expires. Spec Section 4.3.1
func (*Resolver) BrowseCommissionableWithFilter ¶
func (r *Resolver) BrowseCommissionableWithFilter(ctx context.Context, filter string) (<-chan ResolvedService, error)
BrowseCommissionableWithFilter discovers commissionable nodes matching the filter. The filter can be:
- Short discriminator: "_S<value>" (e.g., "_S3")
- Long discriminator: "_L<value>" (e.g., "_L840")
- Vendor ID: "_V<value>" (e.g., "_V123")
- Device Type: "_T<value>" (e.g., "_T81")
- Commissioning Mode: "_CM"
func (*Resolver) BrowseCommissioner ¶
func (r *Resolver) BrowseCommissioner(ctx context.Context) (<-chan ResolvedService, error)
BrowseCommissioner discovers commissioners on the network. Returns a channel that receives discovered services until the context is cancelled or the browse timeout expires. Spec Section 4.3.3
func (*Resolver) BrowseOperational ¶
func (r *Resolver) BrowseOperational(ctx context.Context) (<-chan ResolvedService, error)
BrowseOperational discovers operational nodes on the network. Returns a channel that receives discovered services until the context is cancelled or the browse timeout expires. Spec Section 4.3.2
func (*Resolver) DiscoverCommissionableNode ¶
func (r *Resolver) DiscoverCommissionableNode(ctx context.Context, discriminator uint16) (*ResolvedService, error)
DiscoverCommissionableNode is a convenience function to find a commissionable node by discriminator. It browses and filters by the long discriminator.
func (*Resolver) Lookup ¶
func (r *Resolver) Lookup(ctx context.Context, serviceType ServiceType, instanceName string) (*ResolvedService, error)
Lookup looks up a specific service instance by name.
func (*Resolver) LookupOperational ¶
func (r *Resolver) LookupOperational(ctx context.Context, compressedFabricID [8]byte, nodeID fabric.NodeID) (*ResolvedService, error)
LookupOperational looks up a specific operational node by compressed fabric ID and node ID. This is the primary method for finding a known commissioned node. Spec Section 4.3.2
type ResolverConfig ¶
type ResolverConfig struct {
// MDNSResolver is the underlying mDNS resolver implementation.
// If nil, the default pion/mdns resolver is used.
MDNSResolver MDNSResolver
// BrowseTimeout is the timeout for browse operations.
// If zero, DefaultBrowseTimeout is used.
BrowseTimeout time.Duration
// LookupTimeout is the timeout for lookup operations.
// If zero, DefaultLookupTimeout is used.
LookupTimeout time.Duration
}
ResolverConfig holds configuration for the Resolver.
type ServiceEntry ¶
type ServiceEntry struct {
// Instance is the service instance name.
Instance string
// Service is the service type (e.g., "_matterc._udp"), never a subtype.
Service string
// Domain is the DNS-SD domain.
Domain string
// HostName is the SRV target host name.
HostName string
// Port is the SRV port.
Port int
// Text contains the TXT record "key=value" strings.
Text []string
// AddrIPv4 and AddrIPv6 contain the resolved host addresses.
AddrIPv4 []net.IP
AddrIPv6 []net.IP
}
ServiceEntry is a DNS-SD service instance reported by an MDNSResolver.
func MockCommissionableService ¶
func MockCommissionableService(instanceName string, port int, ip net.IP, discriminator uint16) *ServiceEntry
MockCommissionableService creates a mock commissionable service entry for testing.
func MockOperationalService ¶
func MockOperationalService(compressedFabricID [8]byte, nodeID uint64, port int, ip net.IP) *ServiceEntry
MockOperationalService creates a mock operational service entry for testing.
type ServiceRegistration ¶
type ServiceRegistration struct {
// Instance is the service instance name (e.g., "DD200C20D25AE5F7").
Instance string
// Service is the service type (e.g., "_matterc._udp").
Service string
// Subtypes are the DNS-SD subtypes the instance is also advertised under
// (e.g., "_L840"). Spec Section 4.3.1.
Subtypes []string
// Domain is the DNS-SD domain (e.g., "local.").
Domain string
// HostName is the target host name for the SRV record.
// If empty, the factory picks one.
HostName string
// Port is the service port.
Port int
// Text contains the TXT record "key=value" strings.
Text []string
// Interfaces restricts advertising to these interfaces.
// If nil, all interfaces are used.
Interfaces []net.Interface
}
ServiceRegistration describes a DNS-SD service instance to advertise.
type ServiceType ¶
type ServiceType int
ServiceType identifies the type of DNS-SD service. Spec Section 4.3
const ( // ServiceTypeUnknown represents an unknown or invalid service type. ServiceTypeUnknown ServiceType = iota // ServiceTypeCommissionable is for nodes ready to be commissioned. // Service type: _matterc._udp // Spec Section 4.3.1 ServiceTypeCommissionable // ServiceTypeOperational is for commissioned nodes in normal operation. // Service type: _matter._tcp // Spec Section 4.3.2 ServiceTypeOperational // ServiceTypeCommissioner is for commissioners advertising their presence. // Service type: _matterd._udp // Spec Section 4.3.3 ServiceTypeCommissioner )
ServiceType constants.
func (ServiceType) IsValid ¶
func (s ServiceType) IsValid() bool
IsValid returns true if the service type is valid.
func (ServiceType) ServiceString ¶
func (s ServiceType) ServiceString() string
ServiceString returns the DNS-SD service type string.
func (ServiceType) String ¶
func (s ServiceType) String() string
String returns a human-readable string for the service type.