p2p: delete port mappings abandoned by geth
This commit is contained in:
parent
59a2943dee
commit
8bc9d82942
|
@ -49,6 +49,9 @@ func (n *pmp) AddMapping(protocol string, extport, intport int, name string, lif
|
|||
if lifetime <= 0 {
|
||||
return 0, errors.New("lifetime must not be <= 0")
|
||||
}
|
||||
if extport == 0 {
|
||||
extport = intport
|
||||
}
|
||||
// Note order of port arguments is switched between our
|
||||
// AddMapping and the client's AddPortMapping.
|
||||
res, err := n.c.AddPortMapping(strings.ToLower(protocol), intport, extport, int(lifetime/time.Second))
|
||||
|
|
|
@ -87,6 +87,13 @@ func (n *upnp) AddMapping(protocol string, extport, intport int, desc string, li
|
|||
protocol = strings.ToUpper(protocol)
|
||||
lifetimeS := uint32(lifetime / time.Second)
|
||||
|
||||
if extport == 0 {
|
||||
extport = intport
|
||||
} else {
|
||||
// Only delete port mapping if the external port was already used by geth.
|
||||
n.DeleteMapping(protocol, extport, intport)
|
||||
}
|
||||
|
||||
err = n.withRateLimit(func() error {
|
||||
return n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
|
||||
})
|
||||
|
|
|
@ -150,10 +150,7 @@ func (srv *Server) portMappingLoop() {
|
|||
continue
|
||||
}
|
||||
|
||||
external := m.port
|
||||
if m.extPort != 0 {
|
||||
external = m.extPort
|
||||
}
|
||||
external := m.extPort
|
||||
log := newLogger(m.protocol, external, m.port)
|
||||
|
||||
log.Trace("Attempting port mapping")
|
||||
|
|
Loading…
Reference in New Issue