Przeglądaj źródła

lib/upnp: Don’t log unknown device types (fixes #5038) (#5087)

Oyebanji Jacob Mayowa 7 lat temu
rodzic
commit
adc5bf6604
1 zmienionych plików z 16 dodań i 2 usunięć
  1. 16 2
      lib/upnp/upnp.go

+ 16 - 2
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")