discovery

package
v0.0.0-...-119448c Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package discovery implements UDP multicast discovery functionality.

Most users will want to use a Registry, which keeps track of observed remote devices and instantiates Remote instances for each such device.

Transmitter and Listener are low-level discovery primitives that can broadcast discovery packets and receive discovery packets respectively.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultListenerConn

func DefaultListenerConn() *network.ResolvedConn

DefaultListenerConn returns a resolved connection configuration bound to the default device discovery port and multicast listener address.

func DefaultTransmitterConn

func DefaultTransmitterConn() *network.ResolvedConn

DefaultTransmitterConn returns a resolved connection configuration bound to the default device discovery port and all-hosts multicast broadcast address.

func ListenAndRegister

func ListenAndRegister(c context.Context, l *Listener, reg *Registry, fn func(d device.D) error) error

ListenAndRegister is a convenience function to listen for device discovery packets on l and register all of these devices with reg.

ListenAndRegister will run until c is cancelled, or the fn callback returns an error.

If a new device is observed, fn will be called with that device.

Types

type Listener

type Listener struct {
	// Logger, if not nil, is the Logger to log Listener status to.
	Logger logging.L

	// FilterFunc, if not nil, is called with a prospective set of DeviceHeaders.
	// If the function returns false, the device's discovery is ignored.
	FilterFunc func(dh *protocol.DiscoveryHeaders) bool
	// contains filtered or unexported fields
}

Listener listens for PixelPusher broadcasts.

When a user is finished with Listener, they should call Close to release its resources.

Listener is not safe for concurrent use.

func (*Listener) Accept

Accept blocks until a device broadcast is received.

Listener must successfully Connect prior to using Accept.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the Listener, interrupting any current operations and releasing its resources.

func (*Listener) Start

func (l *Listener) Start(conn *net.UDPConn) error

Start starts the Listener listening on the supplied connection, conn.

Start will transfer ownership of conn to Listener regardless of success.

Consider using network.ListenMulticastUDP4Helper to generate conn.

type Registry

type Registry struct {
	// Expiration is the amount of time after which a device is considered
	// to no longer exist.
	//
	// If <= 0, a device will never expire once observed.
	Expiration time.Duration

	// DeviceRegistry, if not nil, is a device.Registry that will be updated when
	// new devices are registered.
	DeviceRegistry *device.Registry
	// contains filtered or unexported fields
}

Registry tracks a list of discovered headers, instantiating a device.D instance for each unique device. It uses device.Remote instances.

If successive headers are observed for the same device, Registry will update the device's header values.

Registry automatically expires devices if they haven't been observed within its Expiration threshold. When a device is expired, it will have its DoneC channel closed, marking it done.

Registry is safe for concurrent use.

func (*Registry) Devices

func (reg *Registry) Devices() []device.D

Devices returns the list of current devices, in no particular order.

func (*Registry) Observe

func (reg *Registry) Observe(dh *protocol.DiscoveryHeaders) (d device.D, isNew bool)

Observe observes the supplied discovery headers. This will add the device if it has not been observed before, or refresh its timeout and metadata if it has.

func (*Registry) Shutdown

func (reg *Registry) Shutdown()

Shutdown shuts down Registry monitoring and all managed devices. It blocks until everything is terminated.

func (*Registry) Unregister

func (reg *Registry) Unregister(d device.D)

Unregister unregisters and shuts down the specified device.

If the device is not currently registered, Unregister will do nothing.

type Transmitter

type Transmitter struct {
	// Logger, if not nil, is the Logger to log Listener status to.
	Logger logging.L
	// contains filtered or unexported fields
}

Transmitter broadcasts discovery data for a set of devices.

It can be run periodically to broadcast the existence of several devices.

Transmitter is not safe for concurrent use.

func (*Transmitter) Broadcast

Broadcast broadcasts discovery headers.

Jump to

Keyboard shortcuts

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