ssdp

package module
v0.0.0-...-1d63d0f Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2018 License: BSD-2-Clause Imports: 16 Imported by: 0

README

Package ssdp implements the Simple Service Discovery Protocol (SSDP) as described in http://www.upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf.

GoDoc Build Status Build status Go Report Card

Documentation

Overview

Package ssdp implements the Simple Service Discovery Protocol (SSDP) as described in http://www.upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf.

Index

Constants

View Source
const (
	DefaultIPv4Group = "239.255.255.250"

	DefaultIPv6LinkLocalGroup = "ff02::c"
	DefaultIPv6SiteLocalGroup = "ff05::c" // for unique local address, global unicast address

	DefaultPort = "1900"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdvertRedirector

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

An AdvertRedirector represents a SSDP advertisement message redirector.

func (*AdvertRedirector) ForwardPath

func (rdr *AdvertRedirector) ForwardPath() *net.UDPAddr

ForwardPath returns the destination address of the SSDP advertisement message.

func (*AdvertRedirector) Header

func (rdr *AdvertRedirector) Header() http.Header

Header returns the HTTP header map that will be sent by WriteTo method.

func (*AdvertRedirector) ReversePath

func (rdr *AdvertRedirector) ReversePath() (*net.UDPAddr, *net.Interface)

ReversePath returns the source address and inbound interface of the SSDP advertisement message.

func (*AdvertRedirector) WriteTo

func (rdr *AdvertRedirector) WriteTo(dst *net.UDPAddr, ifi *net.Interface) (int, error)

WriteTo writes the SSDP advertisement message. The outbound network interface ifi is used for sending multicast message. It uses the system assigned multicast network interface when ifi is nil.

type ControlPoint

type ControlPoint struct {
	// ErrorLog specified an optional logger for errors. If it is
	// nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger
	// contains filtered or unexported fields
}

A ControlPoint represents a SSDP control point.

func (*ControlPoint) Close

func (cp *ControlPoint) Close() error

Close closes the control point.

func (*ControlPoint) GroupAddr

func (cp *ControlPoint) GroupAddr() *net.UDPAddr

GroupAddr returns the joined group network address.

func (*ControlPoint) Interfaces

func (cp *ControlPoint) Interfaces() []net.Interface

Interfaces returns a list of the joined multicast network interfaces.

func (*ControlPoint) MSearch

func (cp *ControlPoint) MSearch(hdr http.Header, mifs []net.Interface, tmo time.Duration) ([]*http.Response, error)

MSearch issues a M-SEARCH SSDP message, takes a timeout and returns a list of responses. Callers should close each http.Response.Body when done reading from it. If mifs is nil, it tries to use all available multicast network interfaces.

func (*ControlPoint) Serve

func (cp *ControlPoint) Serve(hdlr http.Handler) error

Serve starts to handle incoming SSDP messages from SSDP devices. The handler must not be nil.

type Device

type Device struct {
	// ErrorLog specified an optional logger for errors. If it is
	// nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger
	// contains filtered or unexported fields
}

A Device represents a SSDP device.

func (*Device) Close

func (dev *Device) Close() error

Close closes the device.

func (*Device) GroupAddr

func (dev *Device) GroupAddr() *net.UDPAddr

GroupAddr returns the joined group network address.

func (*Device) Interfaces

func (dev *Device) Interfaces() []net.Interface

Interfaces returns a list of the joined multicast network interfaces.

func (*Device) Notify

func (dev *Device) Notify(hdr http.Header, mifs []net.Interface) error

Notify issues a NOTIFY SSDP message. If mifs is nil, it tries to use all available multicast network interfaces.

func (*Device) Serve

func (dev *Device) Serve(hdlr http.Handler) error

Serve starts to handle incoming SSDP messages from SSDP control points. The handler must not be nil.

type Listener

type Listener struct {
	// Group specifies a group IP address of the multicast UDP
	// HTTP message exchange. if it is empty, DefaultIPv4Group
	// will be used.
	Group string

	// Port specifies a service port of the unicast and multicast
	// UDP HTTP message exchanges. If it is empty, DefaultPort
	// will be used.
	Port string

	// Port specifies a local listening port of the unicast and
	// multicast UDP HTTP message exchanges. If it is not empty,
	// the listener prefers LocalPort than Port.
	LocalPort string

	// Loopback sets whether transmitted multicast packets should
	// be copied and send back to the originator.
	MulticastLoopback bool
}

A Listener represents a UDP multicast listener.

func (*Listener) ListenControlPoint

func (ln *Listener) ListenControlPoint(mifs []net.Interface) (*ControlPoint, error)

ListenControlPoint listens on the UDP network Listener.Group and Listener.Port, and returns a control point. If mifs is nil, it tries to listen on all available multicast network interfaces.

func (*Listener) ListenDevice

func (ln *Listener) ListenDevice(mifs []net.Interface) (*Device, error)

ListenDevices listens on the UDP network Listener.Group and Listener.Port, and returns a device. If mifs is nil, it tries to listen on all available multicast network interfaces.

func (*Listener) ListenRedirector

func (ln *Listener) ListenRedirector(mifs []net.Interface) (*Redirector, error)

ListenRedirector listens on the UDP network Listener.Group and Listener.Port, and returns a redirector. If mifs is nil, it tries to listen on all available multicast network interfaces.

type RedirectHandler

type RedirectHandler interface {
	// RediretAdvert handles an inbound SSDP advertisement
	// message.
	RedirectAdvert(*AdvertRedirector)

	// RediretResponse handles an inbound SSDP response message.
	RedirectResponse(*ResponseRedirector)
}

A RedirectHandler represens a generic redirect handler.

type Redirector

type Redirector struct {
	// ErrorLog specified an optional logger for errors. If it is
	// nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger
	// contains filtered or unexported fields
}

A Redirector represents a back-to-back SSDP entity.

func (*Redirector) Close

func (rdr *Redirector) Close() error

Close closes the redirector.

func (*Redirector) GroupAddr

func (rdr *Redirector) GroupAddr() *net.UDPAddr

GroupAddr returns the joined group network address.

func (*Redirector) Interfaces

func (rdr *Redirector) Interfaces() []net.Interface

Interfaces returns a list of the joined multicast network interfaces.

func (*Redirector) Serve

func (rdr *Redirector) Serve(hdlr RedirectHandler) error

Serve starts to handle incoming SSDP messages from either SSDP control points or SSDP devices. The handler must not be nil.

type ResponseRedirector

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

A ResponseRedirector represents a SSDP response message redirector.

func (*ResponseRedirector) ForwardPath

func (rdr *ResponseRedirector) ForwardPath() *net.UDPAddr

ForwardPath returns the destination address of the SSDP response message.

func (*ResponseRedirector) Header

func (rdr *ResponseRedirector) Header() http.Header

Header returns the HTTP header map that will be sent by WriteTo method.

func (*ResponseRedirector) ReversePath

func (rdr *ResponseRedirector) ReversePath() (*net.UDPAddr, *net.Interface)

ReversePath returns the source address and inbound interface of the SSDP response message.

func (*ResponseRedirector) WriteTo

func (rdr *ResponseRedirector) WriteTo(dst *net.UDPAddr, ifi *net.Interface) (int, error)

WriteTo writes the SSDP response message. The outbound network interface ifi is used for sending multicast messages. It uses the system assigned multicast network interface when ifi is nil.

Jump to

Keyboard shortcuts

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