Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
4.3 KiB
Nim
Raw Normal View History

2026-04-10 18:28:37 +04:00
import std/options
import pkg/chronos
import pkg/questionable/results
import ../multinodes
import ../storageclient
import ../storageconfig
2026-05-19 14:59:23 +04:00
import ../nathelper
2026-04-10 18:28:37 +04:00
2026-05-19 14:59:23 +04:00
export nathelper
2026-05-12 10:06:23 +04:00
2026-05-19 14:59:23 +04:00
const DetectionTimeout = 15_000
2026-05-14 10:56:56 +04:00
2026-05-12 10:06:23 +04:00
# Reminder: multinodesuite setup the first node as bootstrap node
multinodesuite "AutoNAT detection":
2026-04-10 18:28:37 +04:00
let natConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 2)
2026-05-12 20:44:49 +04:00
.withRelay(0)
2026-04-10 18:28:37 +04:00
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
2026-05-12 20:44:49 +04:00
.withNatMaxQueueSize(1).some
2026-04-10 18:28:37 +04:00
)
test "node is reachable when using bootstrap node on same network", natConfig:
let node2 = clients()[1]
await node2.client.checkReachable()
2026-05-12 10:06:23 +04:00
2026-05-12 20:44:49 +04:00
let endpointIndependentConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 2)
.withRelay(0)
.withNatSimulation(idx = 1, "endpoint-independent")
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
2026-05-12 20:44:49 +04:00
.withNatMaxQueueSize(1).some
)
# EIF = Endpoint Independent Filtering
test "node with simulated EIF nat is detected as reachable", endpointIndependentConfig:
let node2 = clients()[1]
await node2.client.checkReachable()
2026-05-12 20:44:49 +04:00
2026-05-12 10:06:23 +04:00
let autonatConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 2)
2026-05-12 20:44:49 +04:00
.withRelay(0)
.withNatSimulation(idx = 1, "address-and-port-dependent")
2026-05-12 10:06:23 +04:00
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
2026-05-12 20:44:49 +04:00
.withNatMaxQueueSize(1).some
2026-05-12 10:06:23 +04:00
)
2026-05-12 20:44:49 +04:00
# APDF = Address and Port-Dependent Filtering
test "node with simulated APDF nat is detected as not reachable and starts relay",
autonatConfig:
2026-05-12 10:06:23 +04:00
let node2 = clients()[1]
await node2.client.checkNotReachable()
2026-05-12 10:06:23 +04:00
let transitionConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 2)
2026-05-12 20:44:49 +04:00
.withRelay(0)
.withNatSimulation(idx = 1, "address-and-port-dependent")
2026-05-12 10:06:23 +04:00
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
2026-05-12 10:06:23 +04:00
.withNatMaxQueueSize(1).some
)
2026-05-12 20:44:49 +04:00
# APDF = Address and Port-Dependent Filtering
# EIF = Endpoint Independent Filtering
test "node with simulated APDF nat recovers to reachable and stops relay when nat switches to EIF nat",
transitionConfig:
2026-05-12 10:06:23 +04:00
let node2 = clients()[1]
await node2.client.checkNotReachable()
2026-05-12 10:06:23 +04:00
check (await node2.client.setNatFiltering("endpoint-independent")).isOk
await node2.client.checkReachable()
2026-05-12 10:06:23 +04:00
let natToSimConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 2)
2026-05-12 20:44:49 +04:00
.withRelay(0)
2026-05-12 10:06:23 +04:00
.withNatSimulation(idx = 1, "endpoint-independent")
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
2026-05-12 10:06:23 +04:00
.withNatMaxQueueSize(1).some
)
2026-05-12 20:44:49 +04:00
# APDF = Address and Port-Dependent Filtering
test "reachable node becomes not reachable and starts relay when nat switches to APDF nat",
natToSimConfig:
2026-05-12 10:06:23 +04:00
let node2 = clients()[1]
await node2.client.checkReachable()
2026-05-12 10:06:23 +04:00
check (await node2.client.setNatFiltering("address-and-port-dependent")).isOk
await node2.client.checkNotReachable()
let doubleNatConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 2)
.withRelay(0)
.withNatSimulation(idx = 1, "double-nat")
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
.withNatMaxQueueSize(1).some
)
test "node behind double NAT is detected as not reachable and starts relay",
doubleNatConfig:
let node2 = clients()[1]
await node2.client.checkNotReachable()
2026-05-12 20:44:49 +04:00
let multiNatConfig = NodeConfigs(
clients: StorageConfigs
.init(nodes = 3)
.withRelay(0)
.withNatSimulation(idx = 1, "address-and-port-dependent")
.withNatSimulation(idx = 2, "address-and-port-dependent")
.withNatNumPeersToAsk(1)
.withNatMinConfidence(0.5)
2026-05-25 17:01:33 +04:00
.withNatScheduleInterval(NatScheduleInterval)
2026-05-12 20:44:49 +04:00
.withNatMaxQueueSize(1).some
)
# APDF = Address and Port-Dependent Filtering
test "two nodes with simulated APDF nat starts relay through the same relay node",
multiNatConfig:
let node2 = clients()[1]
let node3 = clients()[2]
await node2.client.checkNotReachable()
await node3.client.checkNotReachable()