From 4c9ecd07665f605cd8aeaf16fbcd8d4a3de81eb7 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 21 Apr 2026 15:36:02 +0400 Subject: [PATCH] feat: add a warning when private address only (#1423) Signed-off-by: Arnaud Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- README.md | 6 ++--- .../requests/node_lifecycle_request.nim | 3 ++- storage/storage.nim | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 280a22b9..0e1c9143 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,6 @@ Feel free to dive in, contributions are welcomed! Open an issue or submit PRs. `logos-storage-nim` uses [nph](https://github.com/arnetheduck/nph) for formatting our code and it is required to adhere to its styling. If you are setting up fresh setup, in order to get `nph` run `make build-nph`. -In order to format files run `make nph/`. -If you want you can install Git pre-commit hook using `make install-nph-commit`, which will format modified files prior committing them. -If you are using VSCode and the [NimLang](https://marketplace.visualstudio.com/items?itemName=NimLang.nimlang) extension you can enable "Format On Save" (eq. the `nim.formatOnSave` property) that will format the files using `nph`. \ No newline at end of file +In order to format files run `make nph/`. +If you want you can install Git pre-commit hook using `make install-nph-commit`, which will format modified files prior committing them. +If you are using VSCode and the [NimLang](https://marketplace.visualstudio.com/items?itemName=NimLang.nimlang) extension you can enable "Format On Save" (eq. the `nim.formatOnSave` property) that will format the files using `nph`. diff --git a/library/storage_thread_requests/requests/node_lifecycle_request.nim b/library/storage_thread_requests/requests/node_lifecycle_request.nim index e5e5e524..146d12b9 100644 --- a/library/storage_thread_requests/requests/node_lifecycle_request.nim +++ b/library/storage_thread_requests/requests/node_lifecycle_request.nim @@ -91,6 +91,7 @@ proc createStorage( configJson: cstring ): Future[Result[StorageServer, string]] {.async: (raises: []).} = var conf: StorageConf + try: conf = StorageConf.load( version = storageFullVersion, @@ -185,6 +186,6 @@ proc process*( try: await storage[].close() except Exception as e: - error "Failed to STOP_NODE.", error = e.msg + error "Failed to CLOSE_NODE.", error = e.msg return err(e.msg) return ok("") diff --git a/storage/storage.nim b/storage/storage.nim index 97bbaf53..5c7b933a 100644 --- a/storage/storage.nim +++ b/storage/storage.nim @@ -11,6 +11,7 @@ import std/os import std/tables import std/cpuinfo import std/net +import std/sequtils import pkg/chronos import pkg/taskpools @@ -31,6 +32,7 @@ import ./blockexchange import ./utils/fileutils import ./discovery import ./utils/addrutils +import ./utils/natutils import ./namespaces import ./storagetypes import ./logutils @@ -77,6 +79,16 @@ proc start*(s: StorageServer) {.async.} = s.config.nat, s.storageNode.switch.peerInfo.addrs, s.config.discoveryPort ) + var hasPublicAddr = false + for announceAddr in announceAddrs: + let (maybeIp, _) = getAddressAndPort(announceAddr) + if maybeIp.isSome and maybeIp.get.isGlobalUnicast(): + hasPublicAddr = true + break + + if not hasPublicAddr: + warn "Unable to determine a public IP address. This node will only be reachable on a private network." + s.storageNode.discovery.updateAnnounceRecord(announceAddrs) s.storageNode.discovery.updateDhtRecord(discoveryAddrs) @@ -110,7 +122,10 @@ proc stop*(s: StorageServer) {.async.} = if res.failure.len > 0: error "Failed to stop Storage node", failures = res.failure.len - raiseAssert "Failed to stop Storage node" + raise newException( + StorageError, + "Failed to stop Storage node: " & res.failure.mapIt(it.error.msg).join(", "), + ) proc close*(s: StorageServer) {.async.} = var futures = @@ -123,7 +138,7 @@ proc close*(s: StorageServer) {.async.} = s.taskpool.shutdown() except Exception as exc: error "Failed to stop the taskpool", failures = res.failure.len - raiseAssert("Failure in taskpool shutdown:" & exc.msg) + raise newException(StorageError, "Failure in taskpool shutdown: " & exc.msg) when defaultChroniclesStream.outputs.type.arity >= 3: proc noOutput(logLevel: LogLevel, msg: LogOutputStr) = @@ -137,7 +152,10 @@ proc close*(s: StorageServer) {.async.} = if res.failure.len > 0: error "Failed to close Storage node", failures = res.failure.len - raiseAssert "Failed to close Storage node" + raise newException( + StorageError, + "Failed to close Storage node: " & res.failure.mapIt(it.error.msg).join(", "), + ) proc shutdown*(server: StorageServer) {.async.} = await server.stop()