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
if natStrategy == NatAny or natStrategy == NatUpnp:
if upnp == nil:
upnp = newMiniupnp()
upnp.discoverDelay = UPNP_TIMEOUT
let dres = upnp.discover()
if dres.isErr:
@ -78,6 +80,7 @@ proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress]
return
if natStrategy == NatAny or natStrategy == NatPmp:
if npmp == nil:
npmp = newNatPmp()
let nres = npmp.init()
if nres.isErr: