Documentation
¶
Index ¶
- Variables
- type AvahiProvider
- func (a *AvahiProvider) AnnounceService(serviceType, serviceName string, port int, txt []string) (string, error)
- func (a *AvahiProvider) Shutdown()
- func (a *AvahiProvider) Start(pairingMode api.PairingMode, autoReconnect bool, cb api.MdnsResolveCB) bool
- func (a *AvahiProvider) UnannounceService(instanceID string) error
- func (a *AvahiProvider) UpdateInterfaces(_ []net.Interface, ifaceIndexes []int32)
- type DefaultZeroconfFactory
- type MdnsManager
- func (m *MdnsManager) AnnounceMdnsEntry() error
- func (m *MdnsManager) AnnouncePairingService(txtRecord *api.ShipPairingTXT) (string, error)
- func (m *MdnsManager) DeviceBrand() string
- func (m *MdnsManager) DeviceCategories() []api.DeviceCategoryType
- func (m *MdnsManager) DeviceModel() string
- func (m *MdnsManager) DeviceSerial() string
- func (m *MdnsManager) DeviceType() string
- func (m *MdnsManager) IsPairingServiceAnnounced() bool
- func (m *MdnsManager) RegisterPairingCallback(callback func(*api.ShipPairingTXT) bool)
- func (m *MdnsManager) RequestMdnsEntries()
- func (m *MdnsManager) RequestPairingEntries() (map[string]*api.ShipPairingTXT, error)
- func (m *MdnsManager) SearchPairingServices(callback func(*api.ShipPairingTXT) bool) error
- func (m *MdnsManager) SetAutoAccept(accept bool)
- func (m *MdnsManager) SetMdnsProvider(provider api.MdnsProviderInterface)
- func (m *MdnsManager) SetProviderFactory(factory *ProviderFactory)
- func (m *MdnsManager) Shutdown()
- func (m *MdnsManager) SimulatePairingDiscovery(txtRecord *api.ShipPairingTXT)
- func (m *MdnsManager) Start(pairingMode api.PairingMode, cb api.MdnsReportInterface) error
- func (m *MdnsManager) UnannounceMdnsEntry()
- func (m *MdnsManager) UnannouncePairingService(logicalID string) error
- func (m *MdnsManager) UnregisterPairingCallback()
- type MdnsProviderSelection
- type ProviderFactory
- type ServiceType
- type ZeroconfFactoryInterface
- type ZeroconfProvider
- func (z *ZeroconfProvider) AnnounceService(serviceType, serviceName string, port int, txt []string) (string, error)
- func (z *ZeroconfProvider) Shutdown()
- func (z *ZeroconfProvider) Start(pairingMode api.PairingMode, autoReconnect bool, cb api.MdnsResolveCB) bool
- func (z *ZeroconfProvider) UnannounceService(instanceID string) error
- func (z *ZeroconfProvider) UpdateInterfaces(ifaces []net.Interface, _ []int32)
- type ZeroconfServerInterface
Constants ¶
This section is empty.
Variables ¶
var ErrNoInterfacesAvailable = errors.New("none of the configured interfaces are available")
Functions ¶
This section is empty.
Types ¶
type AvahiProvider ¶
type AvahiProvider struct {
// contains filtered or unexported fields
}
func NewAvahiProvider ¶
func NewAvahiProvider(ifaceIndexes []int32) *AvahiProvider
func (*AvahiProvider) AnnounceService ¶ added in v0.7.0
func (a *AvahiProvider) AnnounceService(serviceType, serviceName string, port int, txt []string) (string, error)
AnnounceService announces a specific service type and returns an instance ID
func (*AvahiProvider) Shutdown ¶
func (a *AvahiProvider) Shutdown()
func (*AvahiProvider) Start ¶ added in v0.6.0
func (a *AvahiProvider) Start(pairingMode api.PairingMode, autoReconnect bool, cb api.MdnsResolveCB) bool
func (*AvahiProvider) UnannounceService ¶ added in v0.7.0
func (a *AvahiProvider) UnannounceService(instanceID string) error
UnannounceService removes a service instance by its instance ID
func (*AvahiProvider) UpdateInterfaces ¶ added in v0.7.0
func (a *AvahiProvider) UpdateInterfaces(_ []net.Interface, ifaceIndexes []int32)
UpdateInterfaces updates the interface indexes in a thread-safe manner. AvahiProvider uses ifaceIndexes; ifaces is ignored.
type DefaultZeroconfFactory ¶ added in v0.7.0
type DefaultZeroconfFactory struct{}
DefaultZeroconfFactory implements ZeroconfFactoryInterface using real zeroconf
func (*DefaultZeroconfFactory) Browse ¶ added in v0.7.0
func (f *DefaultZeroconfFactory) Browse(ctx context.Context, service, domain string, entries, removed chan<- *zeroconf.ServiceEntry, opts ...zeroconf.ClientOption) error
func (*DefaultZeroconfFactory) Register ¶ added in v0.7.0
func (f *DefaultZeroconfFactory) Register(serviceName, serviceType, domain string, port int, txt []string, ifaces []net.Interface) (ZeroconfServerInterface, error)
type MdnsManager ¶
type MdnsManager struct {
// contains filtered or unexported fields
}
func NewMDNS ¶
func NewMDNS( ski, deviceBrand, deviceModel, deviceType, deviceSerial string, deviceCategories []api.DeviceCategoryType, shipIdentifier, serviceName string, port int, ifaces []string, providerSelection MdnsProviderSelection) *MdnsManager
Create a new mDNS manager
Parameters:
- ski: the SKI of certificate
- deviceBrand: the brand of the device (max 32 byte of UTF8)
- deviceModel: the model of the device (max 32 byte of UTF8)
- deviceType: the type of the device (max 32 byte of UTF8)
- deviceSerial: the serial number of the device (max 32 byte of UTF8)
- deviceCategories: the categories of the device
- shipIdentifier: the identifier to be used for SHIP ID
- serviceName: the name to be used as the mDNS service name
- port: the port address of the websocket server
- ifaces: the network interfaces to use for the service or empty if a all to be used
- providerSelection: the mDNS provider selection
func (*MdnsManager) AnnounceMdnsEntry ¶
func (m *MdnsManager) AnnounceMdnsEntry() error
Announces the service to the network via mDNS A CEM service should always invoke this on startup Any other service should only invoke this whenever it is not connected to a CEM service
func (*MdnsManager) AnnouncePairingService ¶ added in v0.7.0
func (m *MdnsManager) AnnouncePairingService(txtRecord *api.ShipPairingTXT) (string, error)
AnnouncePairingService announces _shippairing._tcp service (implements MdnsPairingInterface).
Returns a stable logical ID. The caller must hold this ID and pass it to UnannouncePairingService to stop the announcement. The logical ID remains valid across interface-change re-announcements — the manager transparently replaces the underlying provider instance without invalidating caller-held IDs.
func (*MdnsManager) DeviceBrand ¶ added in v0.7.0
func (m *MdnsManager) DeviceBrand() string
Device metadata getters for QR code generation
func (*MdnsManager) DeviceCategories ¶ added in v0.7.0
func (m *MdnsManager) DeviceCategories() []api.DeviceCategoryType
func (*MdnsManager) DeviceModel ¶ added in v0.7.0
func (m *MdnsManager) DeviceModel() string
func (*MdnsManager) DeviceSerial ¶ added in v0.7.0
func (m *MdnsManager) DeviceSerial() string
func (*MdnsManager) DeviceType ¶ added in v0.7.0
func (m *MdnsManager) DeviceType() string
func (*MdnsManager) IsPairingServiceAnnounced ¶ added in v0.7.0
func (m *MdnsManager) IsPairingServiceAnnounced() bool
IsPairingServiceAnnounced returns true if at least one pairing service has been announced and not yet unannounced. Returns true even during interface-loss events when the provider-side announcement is temporarily down, because the logical entry still exists and will be re-announced when interfaces reappear.
func (*MdnsManager) RegisterPairingCallback ¶ added in v0.7.0
func (m *MdnsManager) RegisterPairingCallback(callback func(*api.ShipPairingTXT) bool)
RegisterPairingCallback registers a callback for pairing service discoveries
func (*MdnsManager) RequestMdnsEntries ¶
func (m *MdnsManager) RequestMdnsEntries()
func (*MdnsManager) RequestPairingEntries ¶ added in v0.7.0
func (m *MdnsManager) RequestPairingEntries() (map[string]*api.ShipPairingTXT, error)
RequestPairingEntries returns a snapshot of the currently-live _shippairing._tcp records from the local browse cache; it performs no network operation (implements MdnsPairingInterface)
func (*MdnsManager) SearchPairingServices ¶ added in v0.7.0
func (m *MdnsManager) SearchPairingServices(callback func(*api.ShipPairingTXT) bool) error
SearchPairingServices searches for _shippairing._tcp services (implements MdnsPairingInterface)
func (*MdnsManager) SetAutoAccept ¶
func (m *MdnsManager) SetAutoAccept(accept bool)
func (*MdnsManager) SetMdnsProvider ¶ added in v0.7.0
func (m *MdnsManager) SetMdnsProvider(provider api.MdnsProviderInterface)
SetMdnsProvider sets the mDNS provider for the manager mainly used for testing
func (*MdnsManager) SetProviderFactory ¶ added in v0.7.0
func (m *MdnsManager) SetProviderFactory(factory *ProviderFactory)
SetProviderFactory injects a custom provider factory for testing purposes
func (*MdnsManager) Shutdown ¶
func (m *MdnsManager) Shutdown()
Shutdown all of mDNS. Safe to call multiple times; only the first call after each Start() performs cleanup.
func (*MdnsManager) SimulatePairingDiscovery ¶ added in v0.7.0
func (m *MdnsManager) SimulatePairingDiscovery(txtRecord *api.ShipPairingTXT)
SimulatePairingDiscovery simulates the discovery of a pairing service for testing. Routes the TXT record through the same wire-encode → parseTxt pipeline that production providers use, so the simulator delivers identically normalized input to processShipPairingMdnsEntry.
func (*MdnsManager) Start ¶
func (m *MdnsManager) Start(pairingMode api.PairingMode, cb api.MdnsReportInterface) error
func (*MdnsManager) UnannounceMdnsEntry ¶
func (m *MdnsManager) UnannounceMdnsEntry()
Stop the mDNS announcement on the network
func (*MdnsManager) UnannouncePairingService ¶ added in v0.7.0
func (m *MdnsManager) UnannouncePairingService(logicalID string) error
UnannouncePairingService removes a _shippairing._tcp announcement (implements MdnsPairingInterface). logicalID is the value returned by AnnouncePairingService; it remains valid even after interface-change re-announcements.
func (*MdnsManager) UnregisterPairingCallback ¶ added in v0.7.0
func (m *MdnsManager) UnregisterPairingCallback()
UnregisterPairingCallback removes the registered pairing callback
type MdnsProviderSelection ¶
type MdnsProviderSelection uint
const ( MdnsProviderSelectionAll MdnsProviderSelection = iota // Automatically use avahi if available, otherwise use Go native Zeroconf, default MdnsProviderSelectionAvahiOnly // Only use avahi MdnsProviderSelectionGoZeroConfOnly // Only us Go native zeroconf MdnsProviderSelectionTestSetup // Skip provider creation, use pre-set provider via SetMdnsProvider )
type ProviderFactory ¶ added in v0.7.0
type ProviderFactory struct {
NewAvahi func([]int32) api.MdnsProviderInterface
NewZeroconf func([]net.Interface) api.MdnsProviderInterface
}
ProviderFactory defines functions for creating mDNS providers
func DefaultProviderFactory ¶ added in v0.7.0
func DefaultProviderFactory() *ProviderFactory
DefaultProviderFactory returns the standard provider factory
type ServiceType ¶ added in v0.7.0
type ServiceType uint
ServiceType represents the type of mDNS service being processed
const ( ServiceTypeUnknown ServiceType = iota ServiceTypeShip ServiceTypeShipPairing )
type ZeroconfFactoryInterface ¶ added in v0.7.0
type ZeroconfFactoryInterface interface {
Register(serviceName, serviceType, domain string, port int, txt []string, ifaces []net.Interface) (ZeroconfServerInterface, error)
Browse(ctx context.Context, service, domain string, entries, removed chan<- *zeroconf.ServiceEntry, opts ...zeroconf.ClientOption) error
}
ZeroconfFactoryInterface abstracts zeroconf.Register for testing
type ZeroconfProvider ¶
type ZeroconfProvider struct {
// contains filtered or unexported fields
}
func NewZeroconfProvider ¶
func NewZeroconfProvider(ifaces []net.Interface) *ZeroconfProvider
func (*ZeroconfProvider) AnnounceService ¶ added in v0.7.0
func (z *ZeroconfProvider) AnnounceService(serviceType, serviceName string, port int, txt []string) (string, error)
Enhanced Provider Interface Implementation - TDD Stubs
AnnounceService announces a specific service type and returns an instance ID
func (*ZeroconfProvider) Shutdown ¶
func (z *ZeroconfProvider) Shutdown()
func (*ZeroconfProvider) Start ¶ added in v0.6.0
func (z *ZeroconfProvider) Start(pairingMode api.PairingMode, autoReconnect bool, cb api.MdnsResolveCB) bool
func (*ZeroconfProvider) UnannounceService ¶ added in v0.7.0
func (z *ZeroconfProvider) UnannounceService(instanceID string) error
UnannounceService removes a service instance by its instance ID
func (*ZeroconfProvider) UpdateInterfaces ¶ added in v0.7.0
func (z *ZeroconfProvider) UpdateInterfaces(ifaces []net.Interface, _ []int32)
UpdateInterfaces updates the interface list in a thread-safe manner. ZeroconfProvider uses ifaces; ifaceIndexes is ignored.
type ZeroconfServerInterface ¶ added in v0.7.0
type ZeroconfServerInterface interface {
Shutdown()
}
ZeroconfServerInterface abstracts zeroconf.Server for testing