diff --git a/tests/integration/1_minute/testnat.nim b/tests/integration/1_minute/testnat.nim index b21d8c64..f7981030 100644 --- a/tests/integration/1_minute/testnat.nim +++ b/tests/integration/1_minute/testnat.nim @@ -19,7 +19,7 @@ multinodesuite "AutoNAT detection": .withRelay(0) .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) test "node is reachable when using bootstrap node on same network", natConfig: @@ -33,7 +33,7 @@ multinodesuite "AutoNAT detection": .withNatSimulation(idx = 1, "endpoint-independent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) # EIF = Endpoint Independent Filtering @@ -48,7 +48,7 @@ multinodesuite "AutoNAT detection": .withNatSimulation(idx = 1, "address-and-port-dependent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) # APDF = Address and Port-Dependent Filtering @@ -64,7 +64,7 @@ multinodesuite "AutoNAT detection": .withNatSimulation(idx = 1, "address-and-port-dependent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(5.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) # APDF = Address and Port-Dependent Filtering @@ -74,9 +74,7 @@ multinodesuite "AutoNAT detection": let node2 = clients()[1] await node2.client.checkNotReachable() - check (await node2.client.setNatFiltering("endpoint-independent")).isOk - await node2.client.checkReachable() let natToSimConfig = NodeConfigs( @@ -86,7 +84,7 @@ multinodesuite "AutoNAT detection": .withNatSimulation(idx = 1, "endpoint-independent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(5.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) # APDF = Address and Port-Dependent Filtering @@ -95,9 +93,7 @@ multinodesuite "AutoNAT detection": let node2 = clients()[1] await node2.client.checkReachable() - check (await node2.client.setNatFiltering("address-and-port-dependent")).isOk - await node2.client.checkNotReachable() let doubleNatConfig = NodeConfigs( @@ -107,7 +103,7 @@ multinodesuite "AutoNAT detection": .withNatSimulation(idx = 1, "double-nat") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(5.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) test "node behind double NAT is detected as not reachable and starts relay", @@ -123,7 +119,7 @@ multinodesuite "AutoNAT detection": .withNatSimulation(idx = 2, "address-and-port-dependent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(5.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) # APDF = Address and Port-Dependent Filtering diff --git a/tests/integration/5_minutes/testnatdownload.nim b/tests/integration/5_minutes/testnatdownload.nim index 0216c000..95554326 100644 --- a/tests/integration/5_minutes/testnatdownload.nim +++ b/tests/integration/5_minutes/testnatdownload.nim @@ -1,10 +1,11 @@ -import std/json +import std/[json, sequtils] import pkg/chronos import pkg/questionable/results import ../multinodes import ../storageclient import ../storageconfig +import ../nathelper const RelayTimeout = 30_000 @@ -18,7 +19,7 @@ multinodesuite "NAT download": .withNatSimulation(idx = 2, "address-and-port-dependent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(5.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) # APDF = Address and Port-Dependent Filtering @@ -50,6 +51,13 @@ multinodesuite "NAT download": pollInterval = PollInterval, ) + # Verify natNode advertises a relay circuit address. seed has never dialed + # natNode, so APDF blocks any direct inbound connection from seed — the + # only reachable address is the p2p-circuit one. + let info = (await natNode.client.info()).get + let addrs = info["addrs"].getElems.mapIt(it.getStr) + check addrs.anyIt("p2p-circuit" in it) + let content = "content seeded from nat node" let cid = (await natNode.client.upload(content)).get diff --git a/tests/integration/nathelper.nim b/tests/integration/nathelper.nim index 82caadd4..95b3da17 100644 --- a/tests/integration/nathelper.nim +++ b/tests/integration/nathelper.nim @@ -10,6 +10,7 @@ import ./storageconfig const RelayTimeout* = 30_000 PollInterval* = 1_000 + NatScheduleInterval* = 5.seconds proc checkNatStatus*( client: StorageClient, reachability: string, relayRunning: bool, clientMode: bool @@ -43,6 +44,8 @@ proc checkNatStatus*( proc checkReachable*(client: StorageClient) {.async.} = await client.checkNatStatus("Reachable", relayRunning = false, clientMode = false) +# Relay might be false when the mapping has been created for UPnP / TCP but +# Autonat didn't detect yet Reachable proc checkNotReachable*(client: StorageClient, relayRunning = true) {.async.} = await client.checkNatStatus( "NotReachable", relayRunning = relayRunning, clientMode = true diff --git a/tests/nat/testnatpcp.nim b/tests/nat/testnatpcp.nim index 02deecd2..25f5902b 100644 --- a/tests/nat/testnatpcp.nim +++ b/tests/nat/testnatpcp.nim @@ -16,7 +16,7 @@ multinodesuite "AutoNAT PCP port mapping": .withNatSimulation(idx = 1, "address-and-port-dependent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) @@ -44,7 +44,7 @@ multinodesuite "AutoNAT PCP port mapping": .withNatSimulation(idx = 1, "double-nat") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) # Increase the max queue to trigger the AutoNat 2 times .withNatMaxQueueSize(2).some ) @@ -63,6 +63,9 @@ multinodesuite "AutoNAT PCP port mapping": pollInterval = PollInterval, ) + # Wait for next Autonat iteration + await sleepAsync(6.seconds) + await node2.client.checkNotReachable() test "reachable node downloads content uploaded by node behind NAT after PCP mapping", diff --git a/tests/nat/testnatupnp.nim b/tests/nat/testnatupnp.nim index e36def22..9f7c29bf 100644 --- a/tests/nat/testnatupnp.nim +++ b/tests/nat/testnatupnp.nim @@ -16,7 +16,7 @@ multinodesuite "AutoNAT UPnP port mapping": .withNatSimulation(idx = 1, "address-and-port-dependent") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) .withNatMaxQueueSize(1).some ) @@ -45,7 +45,7 @@ multinodesuite "AutoNAT UPnP port mapping": .withNatSimulation(idx = 1, "double-nat") .withNatNumPeersToAsk(1) .withNatMinConfidence(0.5) - .withNatScheduleInterval(10.seconds) + .withNatScheduleInterval(NatScheduleInterval) # Increase the max queue to trigger the AutoNat 2 times .withNatMaxQueueSize(2).some ) @@ -64,6 +64,9 @@ multinodesuite "AutoNAT UPnP port mapping": pollInterval = PollInterval, ) + # Wait for next Autonat iteration + await sleepAsync(6.seconds) + await node2.client.checkNotReachable() test "reachable node downloads content uploaded by node behind NAT after UPnP mapping",