Documentation ¶
Index ¶
Constants ¶
const ( EventAlive = EventType(iota) EventUpdate EventByeBye )
const ( MethodSearch = "M-SEARCH" MethodNotify = "NOTIFY" SsdpDiscover = `"ssdp:discover"` NtsAlive = `ssdp:alive` NtsByebye = `ssdp:byebye` NtsUpdate = `ssdp:update` SearchPort = 1900 UDP4Addr = "239.255.255.250:1900" // 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 ¶
var (
LayerTypeSSDP = gopacket.RegisterLayerType(1001, gopacket.LayerTypeMetadata{Name: "SSDP", Decoder: gopacket.DecodeFunc(decodeSSDP)})
)
Functions ¶
func SSDPRawSearchCtx ¶
func SSDPRawSearchCtx(ctx context.Context, client httpu.Client, searchTarget string, numSends int) ([]*http.Response, error)
SSDPRawSearchCtx 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 AliveMessage ¶
type AliveMessage struct { SSDPMessage // USN is a property of "USN" USN string // Location is a property of "LOCATION" Location string // Server is a property of "SERVER" Server string // contains filtered or unexported fields }
AliveMessage represents SSDP's ssdp:alive message.
func (*AliveMessage) MaxAge ¶
func (m *AliveMessage) MaxAge() int
MaxAge extracts "max-age" value from "CACHE-CONTROL" property.
type ByeMessage ¶
type ByeMessage struct { SSDPMessage // USN is a property of "USN" USN string }
ByeMessage represents SSDP's ssdp:byebye message.
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 // Wakeup MAC address. Wakeup string 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 Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) AddListener ¶
func (*Registry) RemoveListener ¶
func (*Registry) ServeMessage ¶
ServeMessage implements httpu.Handler, and uses SSDP NOTIFY requests to maintain the registry of devices and services.
type SSDP ¶ added in v0.2.0
type SSDP struct { layers.BaseLayer Method string URL string Headers map[string]string StatusCode int Status string }
func (*SSDP) DecodeFromBytes ¶ added in v0.2.0
func (s *SSDP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
type SSDPMessage ¶
type SSDPMessage struct { // From is a sender of this message From net.Addr // Type is a property of "NT" Type string // contains filtered or unexported fields }
func (SSDPMessage) Get ¶
func (m SSDPMessage) Get(name string) string
Get returns a property value by name.
func (SSDPMessage) Header ¶
func (m SSDPMessage) Header() http.Header
Header returns all properties in alive message.
type SearchMessage ¶
type SearchMessage struct {
SSDPMessage
}
SearchMessage represents SSDP's ssdp:discover message.
type Update ¶
type Update struct { // The USN of the service.ntsUpdate gv 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 }