mirror of https://github.com/status-im/nim-eth.git
doPortMapping(): don't set the external IP
because some IGDs can't handle it
This commit is contained in:
parent
e0e49b1711
commit
655fc43751
|
@ -27,7 +27,6 @@ var
|
||||||
upnp {.threadvar.}: Miniupnp
|
upnp {.threadvar.}: Miniupnp
|
||||||
npmp {.threadvar.}: NatPmp
|
npmp {.threadvar.}: NatPmp
|
||||||
strategy = NatNone
|
strategy = NatNone
|
||||||
externalIP {.threadvar.}: IPAddress
|
|
||||||
internalTcpPort: Port
|
internalTcpPort: Port
|
||||||
externalTcpPort: Port
|
externalTcpPort: Port
|
||||||
internalUdpPort: Port
|
internalUdpPort: Port
|
||||||
|
@ -39,6 +38,8 @@ logScope:
|
||||||
## Also does threadvar initialisation.
|
## Also does threadvar initialisation.
|
||||||
## Must be called before redirectPorts() in each thread.
|
## Must be called before redirectPorts() in each thread.
|
||||||
proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress] =
|
proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress] =
|
||||||
|
var externalIP: IPAddress
|
||||||
|
|
||||||
if natStrategy == NatAny or natStrategy == NatUpnp:
|
if natStrategy == NatAny or natStrategy == NatUpnp:
|
||||||
upnp = newMiniupnp()
|
upnp = newMiniupnp()
|
||||||
upnp.discoverDelay = UPNP_TIMEOUT
|
upnp.discoverDelay = UPNP_TIMEOUT
|
||||||
|
@ -107,8 +108,7 @@ proc doPortMapping(tcpPort, udpPort: Port, description: string): Option[(Port, P
|
||||||
internalHost = upnp.lanAddr,
|
internalHost = upnp.lanAddr,
|
||||||
internalPort = $port,
|
internalPort = $port,
|
||||||
desc = description,
|
desc = description,
|
||||||
leaseDuration = 0,
|
leaseDuration = 0)
|
||||||
externalIP = $externalIP)
|
|
||||||
if pmres.isErr:
|
if pmres.isErr:
|
||||||
error "UPnP port mapping", msg = pmres.error
|
error "UPnP port mapping", msg = pmres.error
|
||||||
return
|
return
|
||||||
|
@ -161,14 +161,14 @@ proc repeatPortMapping(args: PortMappingArgs) {.thread.} =
|
||||||
|
|
||||||
# We can't use copies of Miniupnp and NatPmp objects in this thread, because they share
|
# We can't use copies of Miniupnp and NatPmp objects in this thread, because they share
|
||||||
# C pointers with other instances that have already been garbage collected, so
|
# C pointers with other instances that have already been garbage collected, so
|
||||||
# we use threadvars instead and initialise them again with getExternalIP().
|
# we use threadvars instead and initialise them again with getExternalIP(),
|
||||||
|
# even though we don't need the external IP's value.
|
||||||
let ipres = getExternalIP(strategy, quiet = true)
|
let ipres = getExternalIP(strategy, quiet = true)
|
||||||
if ipres.isSome:
|
if ipres.isSome:
|
||||||
externalIP = ipres.get()
|
|
||||||
while true:
|
while true:
|
||||||
# we're being silly here with this channel polling because we can't
|
# we're being silly here with this channel polling because we can't
|
||||||
# select on Nim channels like on Go ones
|
# select on Nim channels like on Go ones
|
||||||
let (dataAvailable, data) = natCloseChan.tryRecv()
|
let (dataAvailable, _) = natCloseChan.tryRecv()
|
||||||
if dataAvailable:
|
if dataAvailable:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue