mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-28 05:19:28 +00:00
Improve handleNatStatus case when dial back is none
This commit is contained in:
parent
7260cd6fe6
commit
1c6ae98948
@ -144,6 +144,8 @@ method handleNatStatus*(
|
||||
of Reachable:
|
||||
if dialBackAddr.isNone:
|
||||
warn "Got empty dialback address in AutoNat when node is Reachable"
|
||||
# Reachable but no address to announce: incomplete information, do nothing
|
||||
# and wait for the next AutoNAT cycle.
|
||||
return
|
||||
|
||||
if autoRelayService.isRunning:
|
||||
@ -152,8 +154,8 @@ method handleNatStatus*(
|
||||
else:
|
||||
debug "AutoRelayService stopped"
|
||||
|
||||
discovery.updateRecordsAndSpr(@[dialBackAddr.get], udpPort = discoveryPort)
|
||||
discovery.protocol.clientMode = false
|
||||
discovery.updateRecordsAndSpr(@[dialBackAddr.get], udpPort = discoveryPort)
|
||||
of NotReachable:
|
||||
var hasPortMapping = false
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ asyncchecksuite "NAT - handleNatStatus":
|
||||
mappedPorts: some((Port(9000), Port(9001), MappingProtocol.UPnP))
|
||||
)
|
||||
|
||||
discard await autorelayservice.setup(autoRelay, sw)
|
||||
await mapper.handleNatStatus(
|
||||
NotReachable, Opt.some(dialBack), discoveryPort, disc, sw, autoRelay
|
||||
)
|
||||
@ -63,7 +64,7 @@ asyncchecksuite "NAT - handleNatStatus":
|
||||
check not autoRelay.isRunning
|
||||
check disc.protocol.clientMode
|
||||
|
||||
test "handleNatStatus starts autoRelay when NotReachable and UPnP failed":
|
||||
test "handleNatStatus starts autoRelay when NotReachable and no dialBackAddr":
|
||||
let mapper = MockNatPortMapper(mappedPorts: none((Port, Port, MappingProtocol)))
|
||||
|
||||
await mapper.handleNatStatus(
|
||||
@ -73,7 +74,7 @@ asyncchecksuite "NAT - handleNatStatus":
|
||||
check autoRelay.isRunning
|
||||
check disc.protocol.clientMode
|
||||
|
||||
test "handleNatStatus starts autoRelay when NotReachable and mapping fails":
|
||||
test "handleNatStatus starts autoRelay when NotReachable and dialBackAddr but no mapped ports":
|
||||
let dialBack = MultiAddress.init("/ip4/1.2.3.4/tcp/8080").expect("valid")
|
||||
let mapper = MockNatPortMapper(mappedPorts: none((Port, Port, MappingProtocol)))
|
||||
|
||||
@ -85,21 +86,24 @@ asyncchecksuite "NAT - handleNatStatus":
|
||||
check disc.announceAddrs == newSeq[MultiAddress]()
|
||||
check disc.protocol.clientMode
|
||||
|
||||
test "handleNatStatus does not announce address when Reachable and no dialBackAddr":
|
||||
test "handleNatStatus does nothing when Reachable and no dialBackAddr":
|
||||
let mapper = MockNatPortMapper(mappedPorts: none((Port, Port, MappingProtocol)))
|
||||
|
||||
discard await autorelayservice.setup(autoRelay, sw)
|
||||
disc.protocol.clientMode = true
|
||||
await mapper.handleNatStatus(
|
||||
Reachable, Opt.none(MultiAddress), discoveryPort, disc, sw, autoRelay
|
||||
)
|
||||
|
||||
check autoRelay.isRunning
|
||||
check disc.announceAddrs == newSeq[MultiAddress]()
|
||||
check not autoRelay.isRunning
|
||||
check not disc.protocol.clientMode
|
||||
check disc.protocol.clientMode
|
||||
|
||||
test "handleNatStatus stops relay and announces dialBackAddr when Reachable":
|
||||
let dialBack = MultiAddress.init("/ip4/1.2.3.4/tcp/8080").expect("valid")
|
||||
let mapper = MockNatPortMapper(mappedPorts: none((Port, Port, MappingProtocol)))
|
||||
|
||||
disc.protocol.clientMode = true
|
||||
discard await autorelayservice.setup(autoRelay, sw)
|
||||
await mapper.handleNatStatus(
|
||||
Reachable, Opt.some(dialBack), discoveryPort, disc, sw, autoRelay
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user