ssdp

package
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: BSD-2-Clause Imports: 10 Imported by: 30

Documentation

Index

Constants

View Source
const (
	EventAlive = EventType(iota)
	EventUpdate
	EventByeBye
)
View Source
const (

	// SSDPAll is a value for searchTarget that searches for all devices and services.
	SSDPAll = "ssdp:all"
	// UPNPRootDevice is a value for searchTarget that searches for all root devices.
	UPNPRootDevice = "upnp:rootdevice"
)

Variables

This section is empty.

Functions

func SSDPRawSearch

func SSDPRawSearch(
	httpu HTTPUClient,
	searchTarget string,
	maxWaitSeconds int,
	numSends int,
) ([]*http.Response, error)

SSDPRawSearch performs a fairly raw SSDP search request, and returns the unique response(s) that it receives. Each response has the requested searchTarget, a USN, and a valid location. maxWaitSeconds states how long to wait for responses in seconds, and must be a minimum of 1 (the implementation waits an additional 100ms for responses to arrive), 2 is a reasonable value for this. numSends is the number of requests to send - 3 is a reasonable value for this.

Types

type Entry

type Entry struct {
	// The address that the entry data was actually received from.
	RemoteAddr string
	// Unique Service Name. Identifies a unique instance of a device or service.
	USN string
	// Notfication Type. The type of device or service being announced.
	NT string
	// Server's self-identifying string.
	Server string
	Host   string
	// Location of the UPnP root device description.
	Location url.URL

	BootID   int32
	ConfigID int32

	SearchPort uint16

	// When the last update was received for this entry identified by this USN.
	LastUpdate time.Time
	// When the last update's cached values are advised to expire.
	CacheExpiry time.Time
}

type EventType

type EventType int8

func (EventType) String

func (et EventType) String() string

type HTTPUClient added in v1.0.1

type HTTPUClient interface {
	Do(
		req *http.Request,
		timeout time.Duration,
		numSends int,
	) ([]*http.Response, error)
}

HTTPUClient is the interface required to perform HTTP-over-UDP requests.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maintains knowledge of discovered devices and services.

NOTE: the interface for this is experimental and may change, or go away entirely.

func NewRegistry

func NewRegistry() *Registry

func NewServerAndRegistry

func NewServerAndRegistry() (*httpu.Server, *Registry)

NewServerAndRegistry is a convenience function to create a registry, and an httpu server to pass it messages. Call ListenAndServe on the server for messages to be processed.

func (*Registry) AddListener

func (reg *Registry) AddListener(c chan<- Update)

func (*Registry) GetService

func (reg *Registry) GetService(serviceURN string) []*Entry

GetService returns known service (or device) entries for the given service URN.

func (*Registry) RemoveListener

func (reg *Registry) RemoveListener(c chan<- Update)

func (*Registry) ServeMessage

func (reg *Registry) ServeMessage(r *http.Request)

ServeMessage implements httpu.Handler, and uses SSDP NOTIFY requests to maintain the registry of devices and services.

type Update

type Update struct {
	// The USN of the service.
	USN string
	// What happened.
	EventType EventType
	// The entry, which is nil if the service was not known and
	// EventType==EventByeBye. The contents of this must not be modified as it is
	// shared with the registry and other listeners. Once created, the Registry
	// does not modify the Entry value - any updates are replaced with a new
	// Entry value.
	Entry *Entry
}

Jump to

Keyboard shortcuts

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