Documentation
¶
Overview ¶
Package discovery handles device discovery mechanisms
Package discovery provides network device discovery functionality
Index ¶
- type HTTPDiscovery
- func (hd *HTTPDiscovery) FetchDeviceInfo(ctx context.Context, ip net.IP, port int) (*model.Device, error)
- func (hd *HTTPDiscovery) RegisterWithDevice(ctx context.Context, ip net.IP, port int, scheme string) (*model.Device, error)
- func (hd *HTTPDiscovery) ScanLocalNetwork(ctx context.Context, port int) ([]*model.Device, error)
- func (hd *HTTPDiscovery) ScanNetwork(ctx context.Context, ips []net.IP, port int) ([]*model.Device, error)
- type HTTPDiscoveryConfig
- type MulticastConfig
- type MulticastDiscoverer
- type MulticastDiscovery
- func (md *MulticastDiscovery) AddDeviceHandler(handler func(*model.Device))
- func (md *MulticastDiscovery) GetDevices() []*model.Device
- func (md *MulticastDiscovery) SendDiscoveryAnnouncement() error
- func (md *MulticastDiscovery) SendDiscoveryResponse(targetAddr *net.UDPAddr, targetDevice *model.Device) error
- func (md *MulticastDiscovery) SetDto(dto model.MulticastDto)
- func (md *MulticastDiscovery) SetHTTPDiscoverer(hd *HTTPDiscovery)
- func (md *MulticastDiscovery) StartListening(ctx context.Context) error
- func (md *MulticastDiscovery) Stop()
- type Service
- func (s *Service) AddDeviceHandler(handler func(*model.Device))
- func (s *Service) Discover(ctx context.Context, alias string, port int, fingerprint string, ...) ([]*model.Device, error)
- func (s *Service) GetDevice(id string) *model.Device
- func (s *Service) GetDevices() []*model.Device
- func (s *Service) Start(ctx context.Context, alias string, port int, fingerprint string, ...) error
- func (s *Service) Stop()
- type ServiceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPDiscovery ¶
type HTTPDiscovery struct {
// contains filtered or unexported fields
}
HTTPDiscovery handles HTTP-based device discovery
func NewHTTPDiscovery ¶
func NewHTTPDiscovery(config *HTTPDiscoveryConfig, dto model.RegisterDto, handler func(*model.Device), logger *zap.SugaredLogger) *HTTPDiscovery
NewHTTPDiscovery creates a new HTTP discovery instance
func (*HTTPDiscovery) FetchDeviceInfo ¶
func (hd *HTTPDiscovery) FetchDeviceInfo(ctx context.Context, ip net.IP, port int) (*model.Device, error)
FetchDeviceInfo is a public wrapper that tries HTTPS first, then HTTP.
func (*HTTPDiscovery) RegisterWithDevice ¶
func (*HTTPDiscovery) ScanLocalNetwork ¶
ScanLocalNetwork scans the local network for devices
type HTTPDiscoveryConfig ¶
HTTPDiscoveryConfig contains settings for HTTP discovery
func DefaultHTTPDiscoveryConfig ¶
func DefaultHTTPDiscoveryConfig() *HTTPDiscoveryConfig
DefaultHTTPDiscoveryConfig returns default HTTP discovery configuration
type MulticastConfig ¶
type MulticastConfig struct {
MulticastAddr string
Port int
AnnounceTimeout time.Duration
ListenTimeout time.Duration
}
MulticastConfig contains settings for multicast discovery
func DefaultMulticastConfig ¶
func DefaultMulticastConfig() *MulticastConfig
DefaultMulticastConfig returns a default configuration
type MulticastDiscoverer ¶
type MulticastDiscoverer interface {
AddDeviceHandler(handler func(*model.Device))
StartListening(ctx context.Context) error
SendDiscoveryAnnouncement() error
Stop()
SetDto(dto model.MulticastDto)
}
MulticastDiscoverer is an interface for multicast discovery.
type MulticastDiscovery ¶
type MulticastDiscovery struct {
// contains filtered or unexported fields
}
MulticastDiscovery implements UDP multicast-based device discovery
func NewMulticastDiscovery ¶
func NewMulticastDiscovery(config *MulticastConfig, dto model.MulticastDto, logger *zap.SugaredLogger) *MulticastDiscovery
NewMulticastDiscovery creates a new multicast discovery instance
func (*MulticastDiscovery) AddDeviceHandler ¶
func (md *MulticastDiscovery) AddDeviceHandler(handler func(*model.Device))
AddDeviceHandler adds a handler function that will be called when a device is discovered
func (*MulticastDiscovery) GetDevices ¶
func (md *MulticastDiscovery) GetDevices() []*model.Device
GetDevices returns all discovered devices
func (*MulticastDiscovery) SendDiscoveryAnnouncement ¶
func (md *MulticastDiscovery) SendDiscoveryAnnouncement() error
SendDiscoveryAnnouncement sends a multicast announcement
func (*MulticastDiscovery) SendDiscoveryResponse ¶
func (md *MulticastDiscovery) SendDiscoveryResponse(targetAddr *net.UDPAddr, targetDevice *model.Device) error
SendDiscoveryResponse sends a response to a specific address
func (*MulticastDiscovery) SetDto ¶
func (md *MulticastDiscovery) SetDto(dto model.MulticastDto)
SetDto sets the DTO for the multicast discovery
func (*MulticastDiscovery) SetHTTPDiscoverer ¶ added in v0.1.1
func (md *MulticastDiscovery) SetHTTPDiscoverer(hd *HTTPDiscovery)
SetHTTPDiscoverer sets the HTTP discovery instance for sending responses
func (*MulticastDiscovery) StartListening ¶
func (md *MulticastDiscovery) StartListening(ctx context.Context) error
StartListening starts listening for multicast announcements
func (*MulticastDiscovery) Stop ¶
func (md *MulticastDiscovery) Stop()
Stop stops the multicast discovery
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service coordinates different discovery mechanisms
func NewService ¶
func NewService(config *ServiceConfig, multicast MulticastDiscoverer, logger *zap.SugaredLogger) *Service
NewService creates a new discovery service
func (*Service) AddDeviceHandler ¶
AddDeviceHandler adds a handler for device discovery events
func (*Service) Discover ¶
func (s *Service) Discover(ctx context.Context, alias string, port int, fingerprint string, deviceType model.DeviceType, deviceModel *string, httpsEnabled bool) ([]*model.Device, error)
Discover performs a discovery scan and returns found devices. It sends an announcement and listens for a short duration. It requires the service to be configured but not necessarily fully "Start"ed (for listening).
func (*Service) GetDevices ¶
GetDevices returns all currently known devices
type ServiceConfig ¶
type ServiceConfig struct {
MulticastConfig *MulticastConfig
AnnounceInterval time.Duration
DeviceTimeout time.Duration
EnableAnnouncement bool
}
ServiceConfig contains settings for the discovery service
func DefaultServiceConfig ¶
func DefaultServiceConfig() *ServiceConfig
DefaultServiceConfig returns a default configuration for the discovery service