2024-06-28 16:04:57 +05:30
|
|
|
|
{.push raises: [].}
|
2021-07-14 19:58:46 +02:00
|
|
|
|
|
2020-04-29 12:49:27 +08:00
|
|
|
|
import
|
2024-05-17 16:28:54 +02:00
|
|
|
|
std/[options, strutils, sequtils, net],
|
2022-11-23 10:08:00 +01:00
|
|
|
|
chronicles,
|
2022-10-18 12:35:26 -05:00
|
|
|
|
chronos,
|
|
|
|
|
|
metrics,
|
2022-11-30 19:41:19 +01:00
|
|
|
|
libbacktrace,
|
2022-10-18 12:35:26 -05:00
|
|
|
|
system/ansi_c,
|
2023-04-25 15:34:57 +02:00
|
|
|
|
libp2p/crypto/crypto
|
2022-07-25 13:01:37 +02:00
|
|
|
|
import
|
2025-10-01 16:31:34 +10:00
|
|
|
|
../../tools/[rln_keystore_generator/rln_keystore_generator, confutils/cli_args],
|
2024-07-06 03:33:38 +05:30
|
|
|
|
waku/[
|
|
|
|
|
|
common/logging,
|
|
|
|
|
|
factory/waku,
|
|
|
|
|
|
node/health_monitor,
|
2025-11-15 23:31:09 +01:00
|
|
|
|
rest_api/endpoint/builder as rest_server_builder,
|
2025-10-01 16:31:34 +10:00
|
|
|
|
waku_core/message/default_values,
|
2024-07-06 03:33:38 +05:30
|
|
|
|
]
|
2022-10-18 12:35:26 -05:00
|
|
|
|
|
|
|
|
|
|
logScope:
|
2023-04-25 15:34:57 +02:00
|
|
|
|
topics = "wakunode main"
|
2021-07-22 11:46:54 +02:00
|
|
|
|
|
2024-05-13 17:45:48 +02:00
|
|
|
|
const git_version* {.strdefine.} = "n/a"
|
2024-02-07 12:42:20 +01:00
|
|
|
|
|
|
|
|
|
|
{.pop.}
|
|
|
|
|
|
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
|
2022-10-21 15:01:01 +02:00
|
|
|
|
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
|
2022-11-23 10:08:00 +01:00
|
|
|
|
|
2024-05-03 14:07:15 +02:00
|
|
|
|
const versionString = "version / git commit hash: " & waku.git_version
|
2022-11-03 10:45:06 +01:00
|
|
|
|
|
2025-05-08 07:05:35 +10:00
|
|
|
|
var wakuNodeConf = WakuNodeConf.load(version = versionString).valueOr:
|
2024-05-13 17:45:48 +02:00
|
|
|
|
error "failure while loading the configuration", error = error
|
2022-11-03 10:45:06 +01:00
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
2025-05-08 07:05:35 +10:00
|
|
|
|
## Also called within Waku.new. The call to startRestServerEssentials needs the following line
|
|
|
|
|
|
logging.setupLog(wakuNodeConf.logLevel, wakuNodeConf.logFormat)
|
2022-11-23 10:08:00 +01:00
|
|
|
|
|
2025-05-08 07:05:35 +10:00
|
|
|
|
case wakuNodeConf.cmd
|
2023-11-09 15:18:39 +05:30
|
|
|
|
of generateRlnKeystore:
|
2025-05-08 07:05:35 +10:00
|
|
|
|
let conf = wakuNodeConf.toKeystoreGeneratorConf()
|
2023-11-09 15:18:39 +05:30
|
|
|
|
doRlnKeystoreGenerator(conf)
|
|
|
|
|
|
of noCommand:
|
2025-05-08 07:05:35 +10:00
|
|
|
|
let conf = wakuNodeConf.toWakuConf().valueOr:
|
|
|
|
|
|
error "Waku configuration failed", error = error
|
2024-04-23 18:53:18 +02:00
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
2025-07-10 19:49:47 +03:00
|
|
|
|
var waku = (waitFor Waku.new(conf)).valueOr:
|
2024-05-03 14:07:15 +02:00
|
|
|
|
error "Waku initialization failed", error = error
|
2023-11-09 15:18:39 +05:30
|
|
|
|
quit(QuitFailure)
|
2020-09-01 04:09:54 +02:00
|
|
|
|
|
2024-05-03 14:07:15 +02:00
|
|
|
|
(waitFor startWaku(addr waku)).isOkOr:
|
|
|
|
|
|
error "Starting waku failed", error = error
|
2023-11-09 15:18:39 +05:30
|
|
|
|
quit(QuitFailure)
|
2022-10-28 00:05:02 +02:00
|
|
|
|
|
2025-10-15 10:49:36 +02:00
|
|
|
|
info "Setting up shutdown hooks"
|
2025-06-16 18:44:21 +02:00
|
|
|
|
proc asyncStopper(waku: Waku) {.async: (raises: [Exception]).} =
|
|
|
|
|
|
await waku.stop()
|
2023-11-09 15:18:39 +05:30
|
|
|
|
quit(QuitSuccess)
|
2022-12-06 11:51:33 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
# 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"
|
2024-05-03 14:07:15 +02:00
|
|
|
|
asyncSpawn asyncStopper(waku)
|
2022-11-23 10:08:00 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
setControlCHook(handleCtrlC)
|
2021-04-15 10:18:14 +02:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
# Handle SIGTERM
|
|
|
|
|
|
when defined(posix):
|
|
|
|
|
|
proc handleSigterm(signal: cint) {.noconv.} =
|
|
|
|
|
|
notice "Shutting down after receiving SIGTERM"
|
2024-05-03 14:07:15 +02:00
|
|
|
|
asyncSpawn asyncStopper(waku)
|
2022-11-23 10:08:00 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
c_signal(ansi_c.SIGTERM, handleSigterm)
|
2022-11-23 10:08:00 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
# Handle SIGSEGV
|
|
|
|
|
|
when defined(posix):
|
|
|
|
|
|
proc handleSigsegv(signal: cint) {.noconv.} =
|
|
|
|
|
|
# Require --debugger:native
|
2024-02-07 12:42:20 +01:00
|
|
|
|
fatal "Shutting down after receiving SIGSEGV", stacktrace = getBacktrace()
|
2022-11-29 16:02:18 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
# Not available in -d:release mode
|
|
|
|
|
|
writeStackTrace()
|
2022-11-29 16:02:18 +01:00
|
|
|
|
|
2024-05-03 14:07:15 +02:00
|
|
|
|
waitFor waku.stop()
|
2023-11-09 15:18:39 +05:30
|
|
|
|
quit(QuitFailure)
|
2022-11-29 16:02:18 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
c_signal(ansi_c.SIGSEGV, handleSigsegv)
|
2022-11-29 16:02:18 +01:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
info "Node setup complete"
|
2020-09-01 04:09:54 +02:00
|
|
|
|
|
2023-11-09 15:18:39 +05:30
|
|
|
|
runForever()
|