Merge pull request #2014 from frennkie/re-create-port-mappings

Re-create forwardings after externalIP change
This commit is contained in:
Wilmer Paulino 2019-04-18 17:38:02 -07:00 committed by GitHub
commit 5173ef6f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -65,10 +65,6 @@ func (p *PMP) AddPortMapping(port uint16) error {
p.forwardedPortsMtx.Lock()
defer p.forwardedPortsMtx.Unlock()
if _, exists := p.forwardedPorts[port]; exists {
return nil
}
_, err := p.client.AddPortMapping("tcp", int(port), int(port), 0)
if err != nil {
return err

View File

@ -62,10 +62,6 @@ func (u *UPnP) AddPortMapping(port uint16) error {
u.forwardedPortsMtx.Lock()
defer u.forwardedPortsMtx.Unlock()
if _, exists := u.forwardedPorts[port]; exists {
return nil
}
if err := u.device.Forward(port, ""); err != nil {
return err
}

View File

@ -1371,6 +1371,21 @@ out:
continue
}
// Periodically renew the NAT port forwarding.
for _, port := range forwardedPorts {
err := s.natTraversal.AddPortMapping(port)
if err != nil {
srvrLog.Warnf("Unable to automatically "+
"re-create port forwarding using %s: %v",
s.natTraversal.Name(), err)
} else {
srvrLog.Debugf("Automatically re-created "+
"forwarding for port %d using %s to "+
"advertise external IP",
port, s.natTraversal.Name())
}
}
if ip.Equal(s.lastDetectedIP) {
continue
}