mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-08-27 00:11:10 +00:00
The node binary is most often run as a transport-only service/fleet node, so `logosdeliverynode` no longer mounts the messaging client and reliable channel manager unless asked. Protocol flags are unchanged in the default case: the individual CLI defaults already match what `applyMode(Core)` was setting. Only the CLI default moves. `LogosDelivery.new(entryLayer = ...)` and `parseLogosDeliveryConf` keep defaulting to `channels`, so the Nim and C library entry points are unaffected. `MessagingClientConf.toWakuNodeConf` pins `entryLayer = channels` for the same reason it already pins `mode`: a conf derived from a messaging config is by construction not kernel-only. `LogosDeliveryConf.init` now honours `entryLayer == kernel` instead of always mounting the messaging layer, so the layer it records and the layers it mounts agree. Doc comments follow the code: `mode`/`preset` shape the kernel conf for every layer, `kernel` included, and `init(kernelConf)` stays the raw entry. Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
100 lines
3.1 KiB
Nim
100 lines
3.1 KiB
Nim
{.push raises: [].}
|
|
|
|
import
|
|
std/[options, strutils, sequtils, net],
|
|
chronicles,
|
|
chronos,
|
|
metrics,
|
|
system/ansi_c,
|
|
libp2p/crypto/crypto
|
|
import
|
|
../../tools/confutils/cli_args,
|
|
logos_delivery/logos_delivery,
|
|
logos_delivery/waku/common/logging
|
|
|
|
logScope:
|
|
topics = "logosdeliverynode main"
|
|
|
|
const git_version* {.strdefine.} = "n/a"
|
|
|
|
{.pop.}
|
|
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
|
|
when isMainModule:
|
|
## Node setup happens in 6 phases:
|
|
## 1. Set up storage
|
|
## 2. Initialize node
|
|
## 3. Mount and initialize configured protocols
|
|
## 4. Start node and mounted protocols
|
|
## 5. Start monitoring tools and external interfaces
|
|
## 6. Setup graceful shutdown hooks
|
|
|
|
const versionString = "version / git commit hash: " & git_version
|
|
|
|
var wakuNodeConf = WakuNodeConf.load(version = versionString).valueOr:
|
|
error "failure while loading the configuration", error = error
|
|
quit(QuitFailure)
|
|
|
|
## Also called within LogosDelivery.new. The call to startRestServerEssentials
|
|
## needs the following line
|
|
logging.setupLog(wakuNodeConf.logLevel, wakuNodeConf.logFormat)
|
|
|
|
case wakuNodeConf.cmd
|
|
of generateRlnKeystore:
|
|
error "generateRlnKeystore not supported by logos_delivery_node; use wakunode2"
|
|
quit(QuitFailure)
|
|
of noCommand:
|
|
# `LogosDelivery` derives the per-layer config from `WakuNodeConf` itself
|
|
# (it runs `toWakuConf` internally), then builds the layers bottom-up:
|
|
# Waku <- MessagingClient <- ReliableChannelManager
|
|
# How far up it goes is set by `--entry-layer` (default `kernel`: Waku only).
|
|
var node = (waitFor LogosDelivery.new(wakuNodeConf)).valueOr:
|
|
error "LogosDelivery initialization failed", error = error
|
|
quit(QuitFailure)
|
|
|
|
(waitFor node.start()).isOkOr:
|
|
error "Starting LogosDelivery failed", error = error
|
|
quit(QuitFailure)
|
|
|
|
info "Setting up shutdown hooks"
|
|
proc asyncStopper(node: LogosDelivery) {.async: (raises: [Exception]).} =
|
|
(await node.stop()).isOkOr:
|
|
error "LogosDelivery shutdown failed", error = error
|
|
quit(QuitSuccess)
|
|
|
|
# Handle Ctrl-C SIGINT
|
|
proc handleCtrlC() {.noconv.} =
|
|
when defined(windows):
|
|
# workaround for https://github.com/nim-lang/Nim/issues/4057
|
|
setupForeignThreadGc()
|
|
notice "Shutting down after receiving SIGINT"
|
|
asyncSpawn asyncStopper(node)
|
|
|
|
setControlCHook(handleCtrlC)
|
|
|
|
# Handle SIGTERM
|
|
when defined(posix):
|
|
proc handleSigterm(signal: cint) {.noconv.} =
|
|
notice "Shutting down after receiving SIGTERM"
|
|
asyncSpawn asyncStopper(node)
|
|
|
|
c_signal(ansi_c.SIGTERM, handleSigterm)
|
|
|
|
# Handle SIGSEGV
|
|
when defined(posix):
|
|
proc handleSigsegv(signal: cint) {.noconv.} =
|
|
# Require --debugger:native
|
|
fatal "Shutting down after receiving SIGSEGV"
|
|
|
|
# Not available in -d:release mode
|
|
writeStackTrace()
|
|
|
|
(waitFor node.stop()).isOkOr:
|
|
error "LogosDelivery shutdown failed", error = error
|
|
quit(QuitFailure)
|
|
|
|
c_signal(ansi_c.SIGSEGV, handleSigsegv)
|
|
|
|
info "Node setup complete"
|
|
|
|
runForever()
|