one upnp is enough (#324)

we shouldn't have to recreate the upnp interface every time
This commit is contained in:
Jacek Sieka 2021-01-26 14:12:04 +01:00 committed by GitHub
parent ab969f72c1
commit 51a8795e56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -42,7 +42,9 @@ proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress]
var externalIP: IPAddress var externalIP: IPAddress
if natStrategy == NatAny or natStrategy == NatUpnp: if natStrategy == NatAny or natStrategy == NatUpnp:
upnp = newMiniupnp() if upnp == nil:
upnp = newMiniupnp()
upnp.discoverDelay = UPNP_TIMEOUT upnp.discoverDelay = UPNP_TIMEOUT
let dres = upnp.discover() let dres = upnp.discover()
if dres.isErr: if dres.isErr:
@ -78,7 +80,8 @@ proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress]
return return
if natStrategy == NatAny or natStrategy == NatPmp: if natStrategy == NatAny or natStrategy == NatPmp:
npmp = newNatPmp() if npmp == nil:
npmp = newNatPmp()
let nres = npmp.init() let nres = npmp.init()
if nres.isErr: if nres.isErr:
debug "NAT-PMP", msg = nres.error debug "NAT-PMP", msg = nres.error