discovery

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

File: pkg/discovery/http_discovery.go

File: pkg/discovery/multicast.go

File: pkg/discovery/service.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverDevices added in v0.4.0

func DiscoverDevices(ctx context.Context, serviceCfg *ServiceConfig, appCfg *config.Config, httpsEnabled bool) ([]*model.Device, error)

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 (hd *HTTPDiscovery) FetchDeviceInfo(ctx context.Context, ip net.IP, port int) (*model.Device, error)

func (*HTTPDiscovery) RegisterWithDevice

func (hd *HTTPDiscovery) RegisterWithDevice(ctx context.Context, ip net.IP, port int, scheme string) (*model.Device, error)

func (*HTTPDiscovery) ScanLocalNetwork

func (hd *HTTPDiscovery) ScanLocalNetwork(ctx context.Context, port int) ([]*model.Device, error)

func (*HTTPDiscovery) ScanNetwork

func (hd *HTTPDiscovery) ScanNetwork(ctx context.Context, ips []net.IP, port int) ([]*model.Device, error)

type HTTPDiscoveryConfig

type HTTPDiscoveryConfig struct {
	RequestTimeout time.Duration
}

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.

func (*PeerCache) GetPeers added in v0.5.0

func (pc *PeerCache) GetPeers() []*model.Device

GetPeers returns a snapshot of all cached peers.

func (*PeerCache) Save added in v0.5.0

func (pc *PeerCache) Save(device *model.Device)

Save adds or updates a peer and persists atomically.

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

func (s *Service) AddDeviceHandler(handler func(*model.Device))

AddDeviceHandler adds a handler for device discovery events

func (*Service) Discover

func (s *Service) Discover(ctx context.Context, dto model.MulticastDto) ([]*model.Device, error)

Discover performs a discovery scan and returns found devices.

func (*Service) GetDevice

func (s *Service) GetDevice(id string) *model.Device

GetDevice returns a specific device by ID

func (*Service) GetDevices

func (s *Service) GetDevices() []*model.Device

GetDevices returns all currently known devices

func (*Service) SetPeerCache added in v0.5.0

func (s *Service) SetPeerCache(cache *PeerCache)

SetPeerCache sets the persistent peer cache for both service and multicast.

func (*Service) Start

func (s *Service) Start(ctx context.Context, dto model.MulticastDto) error

Start initializes and starts the discovery service for listening and periodic announcements

func (*Service) Stop

func (s *Service) Stop()

Stop stops the discovery service

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL