mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-26 12:29:30 +00:00
Fallback on relay when port mapping is not reachable
This commit is contained in:
parent
488f2b57b3
commit
164f2dac3a
@ -217,17 +217,9 @@ method handleNatStatus*(
|
||||
# If the relay is running, the addresses will be updated on reservation.
|
||||
discovery.announceDirectAddrs(@[], udpPort = discoveryPort)
|
||||
|
||||
if dialBackAddr.isNone:
|
||||
warn "Got empty dialback address in AutoNat when node is NotReachable"
|
||||
|
||||
if m.hasMappingIds():
|
||||
m.close()
|
||||
elif m.hasMappingIds():
|
||||
warn "Not Reachable with active port mapping. The port mapping will be deleted and relay will start."
|
||||
|
||||
# The mapping was created the the node is still not reachable.
|
||||
# In that case, we delete the mapping and relay will start.
|
||||
m.close()
|
||||
if m.hasMappingIds():
|
||||
# The mapping was created but the node is still not reachable.
|
||||
debug "Not Reachable with active port mapping, keeping it and starting relay if not started"
|
||||
else:
|
||||
debug "Node is not reachable trying port mapping now"
|
||||
|
||||
|
||||
@ -104,7 +104,7 @@ asyncchecksuite "NAT reaction - port mapping":
|
||||
check not autoRelay.isRunning
|
||||
check disc.protocol.clientMode
|
||||
|
||||
test "handleNatStatus starts autoRelay when NotReachable and no dialBackAddr but no mapped ports":
|
||||
test "handleNatStatus starts autoRelay when NotReachable with no mapped ports":
|
||||
let mapper = MockNatPortMapper(mappedPorts: none((Port, Port, MappingProtocol)))
|
||||
|
||||
autorelayservice.setup(autoRelay, sw)
|
||||
@ -112,23 +112,11 @@ asyncchecksuite "NAT reaction - port mapping":
|
||||
NotReachable, Opt.none(MultiAddress), discoveryPort, disc, sw, autoRelay
|
||||
)
|
||||
|
||||
check autoRelay.isRunning
|
||||
check disc.protocol.clientMode
|
||||
|
||||
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)))
|
||||
|
||||
autorelayservice.setup(autoRelay, sw)
|
||||
await mapper.handleNatStatus(
|
||||
NotReachable, Opt.some(dialBack), discoveryPort, disc, sw, autoRelay
|
||||
)
|
||||
|
||||
check autoRelay.isRunning
|
||||
check disc.announceAddrs == newSeq[MultiAddress]()
|
||||
check disc.protocol.clientMode
|
||||
|
||||
test "handleNatStatus tears down an active mapping and starts relay when NotReachable with dialBackAddr":
|
||||
test "handleNatStatus starts relay when NotReachable with an active mapping":
|
||||
privateAccess(NatPortMapper)
|
||||
let dialBack = MultiAddress.init("/ip4/1.2.3.4/tcp/8080").expect("valid")
|
||||
let mapper = MockNatPortMapper()
|
||||
@ -143,23 +131,7 @@ asyncchecksuite "NAT reaction - port mapping":
|
||||
check autoRelay.isRunning
|
||||
check disc.announceAddrs == newSeq[MultiAddress]()
|
||||
check disc.protocol.clientMode
|
||||
check not mapper.hasMappingIds() # the active mapping was torn down
|
||||
|
||||
test "handleNatStatus tears down an active mapping and starts relay when NotReachable without dialBackAddr":
|
||||
privateAccess(NatPortMapper)
|
||||
let mapper = MockNatPortMapper()
|
||||
mapper.tcpMappingId = some(cint(1))
|
||||
mapper.udpMappingId = some(cint(2))
|
||||
|
||||
autorelayservice.setup(autoRelay, sw)
|
||||
await mapper.handleNatStatus(
|
||||
NotReachable, Opt.none(MultiAddress), discoveryPort, disc, sw, autoRelay
|
||||
)
|
||||
|
||||
check autoRelay.isRunning
|
||||
check disc.announceAddrs == newSeq[MultiAddress]()
|
||||
check disc.protocol.clientMode
|
||||
check not mapper.hasMappingIds() # the active mapping was torn down
|
||||
check mapper.hasMappingIds() # the active mapping is kept
|
||||
|
||||
test "handleNatStatus stops relay and exits client mode when mapping is created and node is Reachable":
|
||||
let dialBack = MultiAddress.init("/ip4/1.2.3.4/tcp/8080").expect("valid")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user