This commit is contained in:
Tanguy 2022-09-15 13:54:08 +02:00
parent 8509891857
commit 7fc1645e93
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
1 changed files with 8 additions and 2 deletions

View File

@ -186,7 +186,7 @@ proc getAllMappings*(tupnp: TUpnpSession): Future[seq[TUpnpPortMapping]] {.async
externalPort: parseInt(res.response.getOrDefault("newexternalport")),
internalPort: parseInt(res.response.getOrDefault("newinternalport")),
internalClient: parseIpAddress(res.response.getOrDefault("newinternalclient")),
protocol: if res.response.getOrDefault("newinternalclient") == "TCP": Tcp else: Udp,
protocol: if res.response.getOrDefault("newprotocol").toUpper() == "TCP": Tcp else: Udp,
description: res.response.getOrDefault("newportmappingdescription"),
leaseDuration: parseInt(res.response.getOrDefault("newleaseduration")).seconds
)
@ -337,7 +337,7 @@ proc check*(sess: TUpnpSession): Future[bool] {.async.} =
when isMainModule:
let sess = TUpnpSession.new()
waitFor(sess.setup())
let newMapping = TUpnpPortMapping(
var newMapping = TUpnpPortMapping(
externalPort: 5445, internalPort: 5445, internalClient: sess.gateway.localIp,
protocol: Tcp, description: "test binding tinyupnp", leaseDuration: 5.minutes)
@ -345,3 +345,9 @@ when isMainModule:
doAssert (waitFor sess.getAllMappings()).anyIt(it.same(newMapping))
waitFor sess.deletePortMapping(newMapping)
doAssert (waitFor sess.getAllMappings()).countIt(it.same(newMapping)) == 0
newMapping.protocol = Udp
waitFor sess.addPortMapping(newMapping)
doAssert (waitFor sess.getAllMappings()).anyIt(it.same(newMapping))
waitFor sess.deletePortMapping(newMapping)
doAssert (waitFor sess.getAllMappings()).countIt(it.same(newMapping)) == 0