浏览代码

Check if we had successfully acquired a UPnP mapping before (fixes #627)

Audrius Butkevicius 11 年之前
父节点
当前提交
b445a7c4d3
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. 8 5
      cmd/syncthing/main.go

+ 8 - 5
cmd/syncthing/main.go

@@ -663,13 +663,16 @@ func renewUPnP(port int) {
 		}
 		}
 
 
 		// Just renew the same port that we already have
 		// Just renew the same port that we already have
-		err = igd.AddPortMapping(upnp.TCP, externalPort, port, "syncthing", cfg.Options.UPnPLease*60)
-		if err == nil {
-			l.Infoln("Renewed UPnP port mapping - external port", externalPort)
-			continue
+		if externalPort != 0 {
+			err = igd.AddPortMapping(upnp.TCP, externalPort, port, "syncthing", cfg.Options.UPnPLease*60)
+			if err == nil {
+				l.Infoln("Renewed UPnP port mapping - external port", externalPort)
+				continue
+			}
 		}
 		}
 
 
-		// Something strange has happened. Perhaps the gateway has changed?
+		// Something strange has happened. We didn't have an external port before?
+		// Or perhaps the gateway has changed?
 		// Retry the same port sequence from the beginning.
 		// Retry the same port sequence from the beginning.
 		r := setupExternalPort(igd, port)
 		r := setupExternalPort(igd, port)
 		if r != 0 {
 		if r != 0 {