discovery

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package discovery handles device discovery mechanisms

Package discovery provides network device discovery functionality

Index

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 (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)

ScanLocalNetwork scans the local network for devices

func (*HTTPDiscovery) ScanNetwork

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

ScanNetwork scans a range of IP addresses for LocalGo devices

type HTTPDiscoveryConfig

type HTTPDiscoveryConfig struct {
	RequestTimeout time.Duration
}

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

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, 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) 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) Start

func (s *Service) Start(ctx context.Context, alias string, port int, fingerprint string, deviceType model.DeviceType, deviceModel *string, httpsEnabled bool) 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