Commit 523cb01f authored by Steven Allen's avatar Steven Allen

Revert "Try to map external port the same as internal port"

This reverts commit 3fa58ced.

Its safer to just pick a random port. Unfortunately, some NATs (e.g., mine) suck
and will happily map a port that's already been mapped elsewhere (e.g., in the
port forwarding config).

While this patch does the _nice_ thing, it was mostly cosmetic.
parent 4a84cb45
......@@ -111,13 +111,6 @@ func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, descriptio
}
}
// try to map external port the same as internal port
_, err = n.c.AddPortMapping(protocol, internalPort, internalPort, timeoutInSeconds)
if err == nil {
n.ports[internalPort] = internalPort
return internalPort, nil
}
for i := 0; i < 3; i++ {
externalPort := randomPort()
_, err = n.c.AddPortMapping(protocol, internalPort, externalPort, timeoutInSeconds)
......
......@@ -264,12 +264,6 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description
}
}
// try to map external port the same as internal port
err = u.c.AddPortMapping("", uint16(internalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds)
if err == nil {
return internalPort, nil
}
for i := 0; i < 3; i++ {
externalPort := randomPort()
err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment