Use compilation flag to exclude nat simulation on release

This commit is contained in:
Arnaud 2026-06-05 18:53:37 +04:00
parent a46d7b18b3
commit 9a7554dbe9
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA
4 changed files with 41 additions and 27 deletions

View File

@ -72,7 +72,9 @@ task testStorage, "Build & run Logos Storage tests":
task testIntegration, "Run integration tests":
buildBinary "storage",
outName = "storage",
params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE"
params =
"-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE " &
"-d:storage_enable_nat_simulation=true"
test "testIntegration"
# use params to enable logging from the integration test executable
# test "testIntegration", params = "-d:chronicles_sinks=textlines[notimestamps,stdout],textlines[dynamic] " &

View File

@ -73,6 +73,7 @@ proc defaultDataDir*(): string =
const
storage_enable_api_debug_peers* {.booldefine.} = false
storage_enable_log_counter* {.booldefine.} = false
storage_enable_nat_simulation* {.booldefine.} = false
DefaultThreadCount* = ThreadCount(0)

View File

@ -629,26 +629,27 @@ proc initDebugApi(
trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers)
router.api(MethodPost, "/api/storage/v1/debug/nat/filtering") do(
filtering: Option[string]
) -> RestApiResponse:
var headers = buildCorsHeaders("POST", allowedOrigin)
when storage_enable_nat_simulation:
router.api(MethodPost, "/api/storage/v1/debug/nat/filtering") do(
filtering: Option[string]
) -> RestApiResponse:
var headers = buildCorsHeaders("POST", allowedOrigin)
without natSimulation =? natRouter:
return RestApiResponse.error(
Http400, "NAT simulation not active on this node", headers = headers
)
without natSimulation =? natRouter:
return RestApiResponse.error(
Http400, "NAT simulation not active on this node", headers = headers
)
without res =? filtering and filtering =? res:
return
RestApiResponse.error(Http400, "Missing filtering value", headers = headers)
without res =? filtering and filtering =? res:
return
RestApiResponse.error(Http400, "Missing filtering value", headers = headers)
let behavior = FilteringBehavior.fromString(filtering).valueOr:
return
RestApiResponse.error(Http400, "Invalid filtering value", headers = headers)
let behavior = FilteringBehavior.fromString(filtering).valueOr:
return
RestApiResponse.error(Http400, "Invalid filtering value", headers = headers)
natSimulation.setFiltering(behavior)
return RestApiResponse.response("", headers = headers)
natSimulation.setFiltering(behavior)
return RestApiResponse.response("", headers = headers)
when storage_enable_api_debug_peers:
router.api(MethodGet, "/api/storage/v1/debug/peer/{peerId}") do(

View File

@ -317,17 +317,27 @@ proc new*(
var natRouter: Option[NatRouter]
let switch =
if config.natSimulation.isSome:
# Provide a NAT simulation useful for testing NAT Traversal
let filtering = FilteringBehavior.fromString(config.natSimulation.get).valueOr(
AddressAndPortDependent
)
let router = NatRouter.new(filtering)
natRouter = some(router)
switchBuilder
.withNatTransport(router, {ServerFlags.ReuseAddr, ServerFlags.TcpNoDelay})
.build()
when storage_enable_nat_simulation:
if config.natSimulation.isSome:
# Provide a NAT simulation useful for testing NAT Traversal
let filtering = FilteringBehavior.fromString(config.natSimulation.get).valueOr(
AddressAndPortDependent
)
let router = NatRouter.new(filtering)
natRouter = some(router)
switchBuilder
.withNatTransport(router, {ServerFlags.ReuseAddr, ServerFlags.TcpNoDelay})
.build()
else:
switchBuilder
.withTcpTransport({ServerFlags.ReuseAddr, ServerFlags.TcpNoDelay})
.build()
else:
if config.natSimulation.isSome:
raise newException(
StorageError,
"--nat-simulation requires a build with -d:storage_enable_nat_simulation=true",
)
switchBuilder
.withTcpTransport({ServerFlags.ReuseAddr, ServerFlags.TcpNoDelay})
.build()