discovery

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 17 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, cfg *ServiceConfig, alias string, port int, fingerprint string, deviceModel *string, httpsEnabled bool) ([]*model.Device, error)

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
	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) 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, isDownloadServer bool) ([]*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) 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