From adc5bf6604dfc4e9532a78b3dc6e1ebf8a9b4edd Mon Sep 17 00:00:00 2001 From: Oyebanji Jacob Mayowa Date: Mon, 30 Jul 2018 15:34:35 +0100 Subject: [PATCH] =?UTF-8?q?lib/upnp:=20Don=E2=80=99t=20log=20unknown=20dev?= =?UTF-8?q?ice=20types=20(fixes=20#5038)=20(#5087)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/upnp/upnp.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/upnp/upnp.go b/lib/upnp/upnp.go index 144061712..9543e1200 100644 --- a/lib/upnp/upnp.go +++ b/lib/upnp/upnp.go @@ -72,6 +72,15 @@ type upnpRoot struct { Device upnpDevice `xml:"device"` } +// UnsupportedDeviceTypeError for unsupported UPnP device types (i.e upnp:rootdevice) +type UnsupportedDeviceTypeError struct { + deviceType string +} + +func (e UnsupportedDeviceTypeError) Error() string { + return fmt.Sprintf("Unsupported UPnP device of type %s", e.deviceType) +} + // Discover discovers UPnP InternetGatewayDevices. // The order in which the devices appear in the results list is not deterministic. func Discover(renewal, timeout time.Duration) []nat.Device { @@ -180,7 +189,12 @@ USER-AGENT: syncthing/1.0 } igds, err := parseResponse(deviceType, resp[:n]) if err != nil { - l.Infoln("UPnP parse:", err) + switch err.(type) { + case *UnsupportedDeviceTypeError: + l.Debugln(err.Error()) + default: + l.Infoln("UPnP parse:", err) + } continue } for _, igd := range igds { @@ -203,7 +217,7 @@ func parseResponse(deviceType string, resp []byte) ([]IGDService, error) { respondingDeviceType := response.Header.Get("St") if respondingDeviceType != deviceType { - return nil, errors.New("unrecognized UPnP device of type " + respondingDeviceType) + return nil, &UnsupportedDeviceTypeError{deviceType: respondingDeviceType} } deviceDescriptionLocation := response.Header.Get("Location")