mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
p2p: delete port mappings abandoned by geth
This commit is contained in:
parent
ca78b84407
commit
19f33ebeac
3 changed files with 11 additions and 4 deletions
|
|
@ -49,6 +49,9 @@ func (n *pmp) AddMapping(protocol string, extport, intport int, name string, lif
|
||||||
if lifetime <= 0 {
|
if lifetime <= 0 {
|
||||||
return 0, errors.New("lifetime must not be <= 0")
|
return 0, errors.New("lifetime must not be <= 0")
|
||||||
}
|
}
|
||||||
|
if extport == 0 {
|
||||||
|
extport = intport
|
||||||
|
}
|
||||||
// Note order of port arguments is switched between our
|
// Note order of port arguments is switched between our
|
||||||
// AddMapping and the client's AddPortMapping.
|
// AddMapping and the client's AddPortMapping.
|
||||||
res, err := n.c.AddPortMapping(strings.ToLower(protocol), intport, extport, int(lifetime/time.Second))
|
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)
|
protocol = strings.ToUpper(protocol)
|
||||||
lifetimeS := uint32(lifetime / time.Second)
|
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 {
|
err = n.withRateLimit(func() error {
|
||||||
return n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
|
return n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -150,10 +150,7 @@ func (srv *Server) portMappingLoop() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
external := m.port
|
external := m.extPort
|
||||||
if m.extPort != 0 {
|
|
||||||
external = m.extPort
|
|
||||||
}
|
|
||||||
log := newLogger(m.protocol, external, m.port)
|
log := newLogger(m.protocol, external, m.port)
|
||||||
|
|
||||||
log.Trace("Attempting port mapping")
|
log.Trace("Attempting port mapping")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue