mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Refinements to UPnP documentation
This commit is contained in:
parent
c4d15b3b95
commit
75d5e74059
@ -16,7 +16,7 @@
|
|||||||
// Adapted from https://github.com/jackpal/Taipei-Torrent/blob/dd88a8bfac6431c01d959ce3c745e74b8a911793/IGD.go
|
// Adapted from https://github.com/jackpal/Taipei-Torrent/blob/dd88a8bfac6431c01d959ce3c745e74b8a911793/IGD.go
|
||||||
// Copyright (c) 2010 Jack Palevich (https://github.com/jackpal/Taipei-Torrent/blob/dd88a8bfac6431c01d959ce3c745e74b8a911793/LICENSE)
|
// Copyright (c) 2010 Jack Palevich (https://github.com/jackpal/Taipei-Torrent/blob/dd88a8bfac6431c01d959ce3c745e74b8a911793/LICENSE)
|
||||||
|
|
||||||
// Package upnp implements UPnP Internet Gateway upnpDevice port mappings
|
// Package upnp implements UPnP InternetGatewayDevice discovery, querying, and port mapping.
|
||||||
package upnp
|
package upnp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -35,6 +35,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A container for relevant properties of a UPnP InternetGatewayDevice.
|
||||||
type IGD struct {
|
type IGD struct {
|
||||||
uuid string
|
uuid string
|
||||||
friendlyName string
|
friendlyName string
|
||||||
@ -43,6 +44,7 @@ type IGD struct {
|
|||||||
localIPAddress string
|
localIPAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A container for relevant properties of a UPnP service of an IGD.
|
||||||
type IGDServiceDescription struct {
|
type IGDServiceDescription struct {
|
||||||
serviceURL string
|
serviceURL string
|
||||||
serviceURN string
|
serviceURN string
|
||||||
@ -71,8 +73,8 @@ type upnpRoot struct {
|
|||||||
Device upnpDevice `xml:"device"`
|
Device upnpDevice `xml:"device"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover UPnP InternetGatewayDevices
|
// Discover discovers UPnP InternetGatewayDevices.
|
||||||
// The order in which the devices appear in the result list is not deterministic
|
// The order in which the devices appear in the result list is not deterministic.
|
||||||
func Discover() []*IGD {
|
func Discover() []*IGD {
|
||||||
result := make([]*IGD, 0)
|
result := make([]*IGD, 0)
|
||||||
l.Infoln("Starting UPnP discovery...")
|
l.Infoln("Starting UPnP discovery...")
|
||||||
@ -107,8 +109,7 @@ func Discover() []*IGD {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for UPnP InternetGatewayDevices for <timeout> seconds
|
// Search for UPnP InternetGatewayDevices for <timeout> seconds, ignoring responses from any devices listed in knownDevices.
|
||||||
// Ignore responses from any devices listed in <knownDevices>
|
|
||||||
// The order in which the devices appear in the result list is not deterministic
|
// The order in which the devices appear in the result list is not deterministic
|
||||||
func discover(deviceType string, timeout int, knownDevices []*IGD) []*IGD {
|
func discover(deviceType string, timeout int, knownDevices []*IGD) []*IGD {
|
||||||
ssdp := &net.UDPAddr{IP: []byte{239, 255, 255, 250}, Port: 1900}
|
ssdp := &net.UDPAddr{IP: []byte{239, 255, 255, 250}, Port: 1900}
|
||||||
@ -467,6 +468,7 @@ func soapRequest(url, device, function, message string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a port mapping to the specified InternetGatewayDevice.
|
||||||
func (n *IGD) AddPortMapping(protocol Protocol, externalPort, internalPort int, description string, timeout int) error {
|
func (n *IGD) AddPortMapping(protocol Protocol, externalPort, internalPort int, description string, timeout int) error {
|
||||||
for _, service := range n.services {
|
for _, service := range n.services {
|
||||||
tpl := `<u:AddPortMapping xmlns:u="%s">
|
tpl := `<u:AddPortMapping xmlns:u="%s">
|
||||||
@ -489,6 +491,7 @@ func (n *IGD) AddPortMapping(protocol Protocol, externalPort, internalPort int,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a port mapping from the specified InternetGatewayDevice.
|
||||||
func (n *IGD) DeletePortMapping(protocol Protocol, externalPort int) (err error) {
|
func (n *IGD) DeletePortMapping(protocol Protocol, externalPort int) (err error) {
|
||||||
for _, service := range n.services {
|
for _, service := range n.services {
|
||||||
tpl := `<u:DeletePortMapping xmlns:u="%s">
|
tpl := `<u:DeletePortMapping xmlns:u="%s">
|
||||||
@ -506,18 +509,22 @@ func (n *IGD) DeletePortMapping(protocol Protocol, externalPort int) (err error)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The InternetGatewayDevice's UUID.
|
||||||
func (n *IGD) UUID() string {
|
func (n *IGD) UUID() string {
|
||||||
return n.uuid
|
return n.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The InternetGatewayDevice's friendly name.
|
||||||
func (n *IGD) FriendlyName() string {
|
func (n *IGD) FriendlyName() string {
|
||||||
return n.friendlyName
|
return n.friendlyName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The InternetGatewayDevice's friendly identifier (friendly name + IP address).
|
||||||
func (n *IGD) FriendlyIdentifier() string {
|
func (n *IGD) FriendlyIdentifier() string {
|
||||||
return "'" + n.FriendlyName() + "' (" + strings.Split(n.URL().Host, ":")[0] + ")"
|
return "'" + n.FriendlyName() + "' (" + strings.Split(n.URL().Host, ":")[0] + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The URL of the InternetGatewayDevice's root device description.
|
||||||
func (n *IGD) URL() *url.URL {
|
func (n *IGD) URL() *url.URL {
|
||||||
return n.url
|
return n.url
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user