mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-19 11:09:26 +00:00
WIP logosdeliverynode app initial commit
This commit is contained in:
parent
ce918b0819
commit
359cbf4a78
13
Makefile
13
Makefile
@ -219,7 +219,7 @@ testcommon: | build-deps build
|
||||
##########
|
||||
## Waku ##
|
||||
##########
|
||||
.PHONY: testwaku wakunode2 testwakunode2 example2 chat2 chat2bridge liteprotocoltester
|
||||
.PHONY: testwaku wakunode2 logosdeliverynode testwakunode2 example2 chat2 chat2bridge liteprotocoltester
|
||||
|
||||
testwaku: | build-deps build rln-deps librln
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
@ -236,6 +236,17 @@ else
|
||||
$(NIMBLE) wakunode2
|
||||
endif
|
||||
|
||||
# Windows: build with nim directly — `nimble <task>` re-clones git deps every
|
||||
# build and they intermittently hang on the MSYS2 runner. Flags mirror logos_delivery.nimble.
|
||||
logosdeliverynode: | build-deps build deps librln
|
||||
ifeq ($(detected_OS),Windows)
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
nim c --out:build/logos_delivery_node --mm:refc --cpu:amd64 $(NIM_PARAMS) -d:chronicles_log_level=TRACE apps/logos_delivery_node/logos_delivery_node.nim
|
||||
else
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(NIMBLE) logosdeliverynode
|
||||
endif
|
||||
|
||||
benchmarks: | build-deps build deps librln
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(NIMBLE) benchmarks
|
||||
|
||||
98
apps/logos_delivery_node/logos_delivery_node.nim
Normal file
98
apps/logos_delivery_node/logos_delivery_node.nim
Normal file
@ -0,0 +1,98 @@
|
||||
{.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 full stack bottom-up:
|
||||
# Waku <- MessagingClient <- ReliableChannelManager
|
||||
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()
|
||||
10
apps/logos_delivery_node/nim.cfg
Normal file
10
apps/logos_delivery_node/nim.cfg
Normal file
@ -0,0 +1,10 @@
|
||||
-d:chronicles_line_numbers
|
||||
-d:discv5_protocol_id="d5waku"
|
||||
-d:chronicles_runtime_filtering=on
|
||||
-d:chronicles_sinks="textlines,json"
|
||||
-d:chronicles_default_output_device=dynamic
|
||||
# Disabling the following topics from nim-eth and nim-dnsdisc since some types cannot be serialized
|
||||
-d:chronicles_disabled_topics="eth,dnsdisc.client"
|
||||
# Results in empty output for some reason
|
||||
#-d:"chronicles_enabled_topics=GossipSub:TRACE,WakuRelay:TRACE"
|
||||
path = "../.."
|
||||
@ -388,6 +388,10 @@ task wakunode2, "Build Waku v2 cli node":
|
||||
let name = "wakunode2"
|
||||
buildBinary name, "apps/wakunode2/", " -d:chronicles_log_level=TRACE "
|
||||
|
||||
task logosdeliverynode, "Build Logos Delivery cli node":
|
||||
let name = "logos_delivery_node"
|
||||
buildBinary name, "apps/logos_delivery_node/", " -d:chronicles_log_level=TRACE "
|
||||
|
||||
task benchmarks, "Some benchmarks":
|
||||
let name = "benchmarks"
|
||||
buildBinary name, "apps/benchmarks/", "-p:../.."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user