Run vet and lint. Make us lint clean.
This commit is contained in:
@@ -27,7 +27,7 @@ import (
|
||||
"github.com/syncthing/syncthing/internal/sync"
|
||||
)
|
||||
|
||||
// A container for relevant properties of a UPnP InternetGatewayDevice.
|
||||
// An IGD is a UPnP InternetGatewayDevice.
|
||||
type IGD struct {
|
||||
uuid string
|
||||
friendlyName string
|
||||
@@ -36,27 +36,25 @@ type IGD struct {
|
||||
localIPAddress string
|
||||
}
|
||||
|
||||
// The InternetGatewayDevice's UUID.
|
||||
func (n *IGD) UUID() string {
|
||||
return n.uuid
|
||||
}
|
||||
|
||||
// The InternetGatewayDevice's friendly name.
|
||||
func (n *IGD) FriendlyName() string {
|
||||
return n.friendlyName
|
||||
}
|
||||
|
||||
// The InternetGatewayDevice's friendly identifier (friendly name + IP address).
|
||||
// FriendlyIdentifier returns a friendly identifier (friendly name + IP
|
||||
// address) for the IGD.
|
||||
func (n *IGD) FriendlyIdentifier() string {
|
||||
return "'" + n.FriendlyName() + "' (" + strings.Split(n.URL().Host, ":")[0] + ")"
|
||||
}
|
||||
|
||||
// The URL of the InternetGatewayDevice's root device description.
|
||||
func (n *IGD) URL() *url.URL {
|
||||
return n.url
|
||||
}
|
||||
|
||||
// A container for relevant properties of a UPnP service of an IGD.
|
||||
// An IGDService is a specific service provided by an IGD.
|
||||
type IGDService struct {
|
||||
serviceID string
|
||||
serviceURL string
|
||||
@@ -244,7 +242,7 @@ func parseResponse(deviceType string, resp []byte) (IGD, error) {
|
||||
|
||||
deviceDescriptionLocation := response.Header.Get("Location")
|
||||
if deviceDescriptionLocation == "" {
|
||||
return IGD{}, errors.New("invalid IGD response: no location specified.")
|
||||
return IGD{}, errors.New("invalid IGD response: no location specified")
|
||||
}
|
||||
|
||||
deviceDescriptionURL, err := url.Parse(deviceDescriptionLocation)
|
||||
@@ -255,7 +253,7 @@ func parseResponse(deviceType string, resp []byte) (IGD, error) {
|
||||
|
||||
deviceUSN := response.Header.Get("USN")
|
||||
if deviceUSN == "" {
|
||||
return IGD{}, errors.New("invalid IGD response: USN not specified.")
|
||||
return IGD{}, errors.New("invalid IGD response: USN not specified")
|
||||
}
|
||||
|
||||
deviceUUID := strings.TrimLeft(strings.Split(deviceUSN, "::")[0], "uuid:")
|
||||
@@ -361,9 +359,8 @@ func getServiceDescriptions(rootURL string, device upnpDevice) ([]IGDService, er
|
||||
|
||||
if len(result) < 1 {
|
||||
return result, errors.New("[" + rootURL + "] Malformed device description: no compatible service descriptions found.")
|
||||
} else {
|
||||
return result, nil
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getIGDServices(rootURL string, device upnpDevice, wanDeviceURN string, wanConnectionURN string, serviceURNs []string) []IGDService {
|
||||
@@ -488,9 +485,11 @@ func soapRequest(url, service, function, message string) ([]byte, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Add a port mapping to all relevant services on the specified InternetGatewayDevice.
|
||||
// Port mapping will fail and return an error if action is fails for _any_ of the relevant services.
|
||||
// For this reason, it is generally better to configure port mapping for each individual service instead.
|
||||
// AddPortMapping adds a port mapping to all relevant services on the
|
||||
// specified InternetGatewayDevice. Port mapping will fail and return an error
|
||||
// if action is fails for _any_ of the relevant services. For this reason, it
|
||||
// is generally better to configure port mapping for each individual service
|
||||
// instead.
|
||||
func (n *IGD) AddPortMapping(protocol Protocol, externalPort, internalPort int, description string, timeout int) error {
|
||||
for _, service := range n.services {
|
||||
err := service.AddPortMapping(n.localIPAddress, protocol, externalPort, internalPort, description, timeout)
|
||||
@@ -501,9 +500,11 @@ func (n *IGD) AddPortMapping(protocol Protocol, externalPort, internalPort int,
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete a port mapping from all relevant services on the specified InternetGatewayDevice.
|
||||
// Port mapping will fail and return an error if action is fails for _any_ of the relevant services.
|
||||
// For this reason, it is generally better to configure port mapping for each individual service instead.
|
||||
// DeletePortMapping deletes a port mapping from all relevant services on the
|
||||
// specified InternetGatewayDevice. Port mapping will fail and return an error
|
||||
// if action is fails for _any_ of the relevant services. For this reason, it
|
||||
// is generally better to configure port mapping for each individual service
|
||||
// instead.
|
||||
func (n *IGD) DeletePortMapping(protocol Protocol, externalPort int) error {
|
||||
for _, service := range n.services {
|
||||
err := service.DeletePortMapping(protocol, externalPort)
|
||||
@@ -528,7 +529,7 @@ type getExternalIPAddressResponse struct {
|
||||
NewExternalIPAddress string `xml:"NewExternalIPAddress"`
|
||||
}
|
||||
|
||||
// Add a port mapping to the specified IGD service.
|
||||
// AddPortMapping adds a port mapping to the specified IGD service.
|
||||
func (s *IGDService) AddPortMapping(localIPAddress string, protocol Protocol, externalPort, internalPort int, description string, timeout int) error {
|
||||
tpl := `<u:AddPortMapping xmlns:u="%s">
|
||||
<NewRemoteHost></NewRemoteHost>
|
||||
@@ -550,7 +551,7 @@ func (s *IGDService) AddPortMapping(localIPAddress string, protocol Protocol, ex
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete a port mapping from the specified IGD service.
|
||||
// DeletePortMapping deletes a port mapping from the specified IGD service.
|
||||
func (s *IGDService) DeletePortMapping(protocol Protocol, externalPort int) error {
|
||||
tpl := `<u:DeletePortMapping xmlns:u="%s">
|
||||
<NewRemoteHost></NewRemoteHost>
|
||||
@@ -568,8 +569,9 @@ func (s *IGDService) DeletePortMapping(protocol Protocol, externalPort int) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query the IGD service for its external IP address.
|
||||
// Returns nil if the external IP address is invalid or undefined, along with any relevant errors
|
||||
// GetExternalIPAddress queries the IGD service for its external IP address.
|
||||
// Returns nil if the external IP address is invalid or undefined, along with
|
||||
// any relevant errors
|
||||
func (s *IGDService) GetExternalIPAddress() (net.IP, error) {
|
||||
tpl := `<u:GetExternalIPAddress xmlns:u="%s" />`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user