Documentation
¶
Overview ¶
File: pkg/discovery/http_discovery.go
File: pkg/discovery/multicast.go
File: pkg/discovery/service.go
Index ¶
- func DiscoverDevices(ctx context.Context, serviceCfg *ServiceConfig, appCfg *config.Config, ...) ([]*model.Device, error)
- func ProbeCached(ctx context.Context, cache *PeerCache, onFound func(*model.Device), ...)
- 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) SetPeerCache(cache *PeerCache)
- func (md *MulticastDiscovery) StartListening(ctx context.Context) error
- func (md *MulticastDiscovery) Stop()
- type PeerCache
- type Service
- func (s *Service) AddDeviceHandler(handler func(*model.Device))
- func (s *Service) Discover(ctx context.Context, dto model.MulticastDto) ([]*model.Device, error)
- func (s *Service) GetDevice(id string) *model.Device
- func (s *Service) GetDevices() []*model.Device
- func (s *Service) SetPeerCache(cache *PeerCache)
- func (s *Service) Start(ctx context.Context, dto model.MulticastDto) error
- func (s *Service) Stop()
- type ServiceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiscoverDevices ¶ added in v0.4.0
func ProbeCached ¶ added in v0.5.0
func ProbeCached(ctx context.Context, cache *PeerCache, onFound func(*model.Device), logger *zap.SugaredLogger)
ProbeCached pings each cached peer with GET /api/localsend/v2/info and calls onFound for every peer that responds.
Types ¶
type HTTPDiscovery ¶
type HTTPDiscovery struct {
// contains filtered or unexported fields
}
func NewHTTPDiscovery ¶
func NewHTTPDiscovery(config *HTTPDiscoveryConfig, dto model.RegisterDto, handler func(*model.Device), logger *zap.SugaredLogger) *HTTPDiscovery
func (*HTTPDiscovery) FetchDeviceInfo ¶
func (*HTTPDiscovery) RegisterWithDevice ¶
func (*HTTPDiscovery) ScanLocalNetwork ¶
type HTTPDiscoveryConfig ¶
func DefaultHTTPDiscoveryConfig ¶
func DefaultHTTPDiscoveryConfig() *HTTPDiscoveryConfig
type MulticastConfig ¶
type MulticastConfig struct {
MulticastAddr string
Port int
InterfaceName string
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
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)
func (*MulticastDiscovery) SetHTTPDiscoverer ¶ added in v0.1.1
func (md *MulticastDiscovery) SetHTTPDiscoverer(hd *HTTPDiscovery)
func (*MulticastDiscovery) SetPeerCache ¶ added in v0.5.0
func (md *MulticastDiscovery) SetPeerCache(cache *PeerCache)
func (*MulticastDiscovery) StartListening ¶
func (md *MulticastDiscovery) StartListening(ctx context.Context) error
StartListening starts listening for multicast announcements on all suitable interfaces. If InterfaceName is set in config, only that interface is used.
func (*MulticastDiscovery) Stop ¶
func (md *MulticastDiscovery) Stop()
Stop stops the multicast discovery and closes all listeners.
type PeerCache ¶ added in v0.5.0
type PeerCache struct {
// contains filtered or unexported fields
}
PeerCache persists discovered peers to disk and provides thread-safe access.
func NewPeerCache ¶ added in v0.5.0
func NewPeerCache(logger *zap.SugaredLogger) *PeerCache
NewPeerCache creates or loads a peer cache from the XDG cache directory.
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) GetDevices ¶
GetDevices returns all currently known devices
func (*Service) SetPeerCache ¶ added in v0.5.0
SetPeerCache sets the persistent peer cache for both service and multicast.
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