mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
p2p/nat: remove forceful port mapping in upnp
This commit is contained in:
parent
ee30681a8d
commit
ca78b84407
1 changed files with 8 additions and 6 deletions
|
|
@ -86,7 +86,6 @@ 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)
|
||||||
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)
|
||||||
|
|
@ -111,12 +110,15 @@ func (n *upnp) addAnyPortMapping(protocol string, extport, intport int, ip net.I
|
||||||
}
|
}
|
||||||
// It will retry with a random port number if the client does
|
// It will retry with a random port number if the client does
|
||||||
// not support AddAnyPortMapping.
|
// not support AddAnyPortMapping.
|
||||||
|
var err error
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
extport = n.randomPort()
|
extport = n.randomPort()
|
||||||
err := n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
|
err := n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return uint16(extport), nil
|
return uint16(extport), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *upnp) randomPort() int {
|
func (n *upnp) randomPort() int {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue