mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-27 21:09:28 +00:00
Add more config checks
This commit is contained in:
parent
540d8440dc
commit
5f96fed3e3
@ -396,12 +396,21 @@ func validateAutonatConfig*(config: StorageConf): ?!void =
|
||||
if config.isRelayServer and not config.nat.hasExtIp:
|
||||
return failure "--relay-server requires --nat=extip:<IP>"
|
||||
|
||||
if config.noBootstrapNode and not config.nat.hasExtIp:
|
||||
return failure(
|
||||
"--no-bootstrap-node requires --nat=extip:<IP>: without bootstrap peers " &
|
||||
"AutoNAT has no one to probe and the node can never become reachable"
|
||||
)
|
||||
|
||||
if config.natMaxQueueSize < 1:
|
||||
return failure "--nat-max-queue-size must be at least 1"
|
||||
|
||||
if config.natNumPeersToAsk < 1:
|
||||
return failure "--nat-num-peers-to-ask must be at least 1"
|
||||
|
||||
if config.natObservedAddrMinCount < 1:
|
||||
return failure "--nat-observed-addr-min-count must be at least 1"
|
||||
|
||||
if config.natMinConfidence < 0.0 or config.natMinConfidence > 1.0:
|
||||
return failure "--nat-min-confidence must be between 0 and 1"
|
||||
|
||||
|
||||
@ -302,12 +302,8 @@ proc new*(
|
||||
enableDialableCandidates = true,
|
||||
)
|
||||
)
|
||||
# At the first AutoNAT probe, the only identify observations available come
|
||||
# from the bootstrap nodes, so requiring more observations than there are
|
||||
# bootstrap nodes would make the threshold unreachable. The floor of 1
|
||||
# covers the case where the bootstrap list is empty.
|
||||
let observedAddrMinCount =
|
||||
max(1, min(config.natObservedAddrMinCount, bootstrapNodes.len))
|
||||
|
||||
let observedAddrMinCount = min(config.natObservedAddrMinCount, bootstrapNodes.len)
|
||||
switchBuilder = switchBuilder.withObservedAddrManager(
|
||||
ObservedAddrManager.new(minCount = observedAddrMinCount)
|
||||
)
|
||||
|
||||
@ -10,6 +10,7 @@ proc validConfig(): StorageConf =
|
||||
natMaxQueueSize: 3,
|
||||
natNumPeersToAsk: 5,
|
||||
natMinConfidence: 0.7,
|
||||
natObservedAddrMinCount: 1,
|
||||
)
|
||||
|
||||
suite "Conf - validateAutonatConfig":
|
||||
@ -42,6 +43,19 @@ suite "Conf - validateAutonatConfig":
|
||||
|
||||
check config.validateAutonatConfig().isOk
|
||||
|
||||
test "rejects no-bootstrap-node without extip":
|
||||
var config = validConfig()
|
||||
config.noBootstrapNode = true
|
||||
|
||||
check config.validateAutonatConfig().isErr
|
||||
|
||||
test "accepts no-bootstrap-node with extip":
|
||||
var config = validConfig()
|
||||
config.noBootstrapNode = true
|
||||
config.nat = nat.NatConfig(hasExtIp: true, extIp: parseIpAddress("1.2.3.4"))
|
||||
|
||||
check config.validateAutonatConfig().isOk
|
||||
|
||||
test "rejects nat-max-queue-size below 1":
|
||||
var config = validConfig()
|
||||
config.natMaxQueueSize = 0
|
||||
@ -66,6 +80,18 @@ suite "Conf - validateAutonatConfig":
|
||||
|
||||
check config.validateAutonatConfig().isOk
|
||||
|
||||
test "rejects nat-observed-addr-min-count below 1":
|
||||
var config = validConfig()
|
||||
config.natObservedAddrMinCount = 0
|
||||
|
||||
check config.validateAutonatConfig().isErr
|
||||
|
||||
test "accepts nat-observed-addr-min-count of 1":
|
||||
var config = validConfig()
|
||||
config.natObservedAddrMinCount = 1
|
||||
|
||||
check config.validateAutonatConfig().isOk
|
||||
|
||||
test "rejects negative nat-min-confidence":
|
||||
var config = validConfig()
|
||||
config.natMinConfidence = -0.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user