mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-27 12:59:30 +00:00
Use compilation flag to exclude nat simulation on release
This commit is contained in:
parent
a46d7b18b3
commit
9a7554dbe9
@ -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] " &
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user