mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
p2p/nat: do not reset external port on UPnP refresh failure
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
77dc1acafa
commit
fe9056f29f
1 changed files with 28 additions and 16 deletions
|
|
@ -154,15 +154,24 @@ func (srv *Server) portMappingLoop() {
|
||||||
log.Trace("Attempting port mapping")
|
log.Trace("Attempting port mapping")
|
||||||
p, err := srv.NAT.AddMapping(m.protocol, m.extPort, m.port, m.name, portMapDuration)
|
p, err := srv.NAT.AddMapping(m.protocol, m.extPort, m.port, m.name, portMapDuration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Failed to add or refresh port mapping.
|
||||||
|
if m.extPort == 0 {
|
||||||
log.Debug("Couldn't add port mapping", "err", err)
|
log.Debug("Couldn't add port mapping", "err", err)
|
||||||
m.extPort = 0
|
} else {
|
||||||
|
// Since UPnP implementation are often buggy,
|
||||||
|
// and lifetime is larger than the retry interval, this does not mean we lost our
|
||||||
|
// existing mapping. We do not reset the external port, as it is still our best chance,
|
||||||
|
// but we do retry soon.
|
||||||
|
// TODO: we could check the error code, but again, UPnP implementations are buggy.
|
||||||
|
log.Debug("Couldn't refresh port mapping", "err", err)
|
||||||
|
}
|
||||||
m.nextTime = srv.clock.Now().Add(portMapRetryInterval)
|
m.nextTime = srv.clock.Now().Add(portMapRetryInterval)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// It was mapped!
|
// It was mapped!
|
||||||
|
log = newLogger(m.protocol, int(p), m.port)
|
||||||
|
if int(p) != m.extPort {
|
||||||
m.extPort = int(p)
|
m.extPort = int(p)
|
||||||
m.nextTime = srv.clock.Now().Add(portMapRefreshInterval)
|
|
||||||
log = newLogger(m.protocol, m.extPort, m.port)
|
|
||||||
if m.port != m.extPort {
|
if m.port != m.extPort {
|
||||||
log.Info("NAT mapped alternative port")
|
log.Info("NAT mapped alternative port")
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -177,6 +186,9 @@ func (srv *Server) portMappingLoop() {
|
||||||
srv.localnode.SetFallbackUDP(m.extPort)
|
srv.localnode.SetFallbackUDP(m.extPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.nextTime = srv.clock.Now().Add(portMapRefreshInterval)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue