2024-06-28 16:04:57 +05:30
|
|
|
|
{.push raises: [].}
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
import
|
|
|
|
|
|
std/[options, strutils, os, sequtils, net],
|
|
|
|
|
|
chronicles,
|
|
|
|
|
|
chronos,
|
|
|
|
|
|
metrics,
|
|
|
|
|
|
libbacktrace,
|
|
|
|
|
|
system/ansi_c,
|
|
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
|
|
confutils
|
|
|
|
|
|
|
|
|
|
|
|
import
|
2025-11-15 23:31:09 +01:00
|
|
|
|
tools/confutils/cli_args,
|
2024-07-06 03:33:38 +05:30
|
|
|
|
waku/[
|
2024-10-25 22:59:02 +02:00
|
|
|
|
common/enr,
|
2024-07-06 03:33:38 +05:30
|
|
|
|
common/logging,
|
2025-06-16 18:44:21 +02:00
|
|
|
|
factory/waku as waku_factory,
|
2024-10-25 22:59:02 +02:00
|
|
|
|
waku_node,
|
2024-07-06 03:33:38 +05:30
|
|
|
|
node/waku_metrics,
|
2024-10-25 22:59:02 +02:00
|
|
|
|
node/peer_manager,
|
2024-08-21 14:54:18 +02:00
|
|
|
|
waku_lightpush/common,
|
|
|
|
|
|
waku_filter_v2,
|
2024-10-25 22:59:02 +02:00
|
|
|
|
waku_peer_exchange/protocol,
|
|
|
|
|
|
waku_core/peers,
|
|
|
|
|
|
waku_core/multiaddrstr,
|
2024-07-06 03:33:38 +05:30
|
|
|
|
],
|
2024-05-21 23:03:33 +02:00
|
|
|
|
./tester_config,
|
2025-06-16 12:46:20 +02:00
|
|
|
|
./publisher,
|
|
|
|
|
|
./receiver,
|
2024-10-25 22:59:02 +02:00
|
|
|
|
./diagnose_connections,
|
|
|
|
|
|
./service_peer_management
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
logScope:
|
|
|
|
|
|
topics = "liteprotocoltester main"
|
|
|
|
|
|
|
|
|
|
|
|
proc logConfig(conf: LiteProtocolTesterConf) =
|
|
|
|
|
|
info "Configuration: Lite protocol tester", conf = $conf
|
|
|
|
|
|
|
|
|
|
|
|
{.pop.}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
const versionString = "version / git commit hash: " & waku_factory.git_version
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
2025-10-27 14:07:06 -03:00
|
|
|
|
let conf = LiteProtocolTesterConf.load(version = versionString).valueOr:
|
|
|
|
|
|
error "failure while loading the configuration", error = error
|
2024-05-21 23:03:33 +02:00
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
|
|
|
|
|
## Logging setup
|
|
|
|
|
|
logging.setupLog(conf.logLevel, conf.logFormat)
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
info "Running Lite Protocol Tester node", version = waku_factory.git_version
|
2024-05-21 23:03:33 +02:00
|
|
|
|
logConfig(conf)
|
|
|
|
|
|
|
|
|
|
|
|
##Prepare Waku configuration
|
|
|
|
|
|
## - load from config file
|
|
|
|
|
|
## - override according to tester functionality
|
|
|
|
|
|
##
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
var wakuNodeConf: WakuNodeConf
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
if conf.configFile.isSome():
|
|
|
|
|
|
try:
|
|
|
|
|
|
var configFile {.threadvar.}: InputFile
|
|
|
|
|
|
configFile = conf.configFile.get()
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf = WakuNodeConf.load(
|
2024-05-21 23:03:33 +02:00
|
|
|
|
version = versionString,
|
|
|
|
|
|
printUsage = false,
|
|
|
|
|
|
secondarySources = proc(
|
|
|
|
|
|
wnconf: WakuNodeConf, sources: auto
|
|
|
|
|
|
) {.gcsafe, raises: [ConfigurationError].} =
|
|
|
|
|
|
echo "Loading secondary configuration file into WakuNodeConf"
|
2024-09-11 11:51:42 +10:00
|
|
|
|
sources.addConfigFile(Toml, configFile),
|
2024-05-21 23:03:33 +02:00
|
|
|
|
)
|
|
|
|
|
|
except CatchableError:
|
|
|
|
|
|
error "Loading Waku configuration failed", error = getCurrentExceptionMsg()
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf.logLevel = conf.logLevel
|
|
|
|
|
|
wakuNodeConf.logFormat = conf.logFormat
|
|
|
|
|
|
wakuNodeConf.nat = conf.nat
|
|
|
|
|
|
wakuNodeConf.maxConnections = 500
|
|
|
|
|
|
wakuNodeConf.restAddress = conf.restAddress
|
|
|
|
|
|
wakuNodeConf.restPort = conf.restPort
|
|
|
|
|
|
wakuNodeConf.restAllowOrigin = conf.restAllowOrigin
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf.dnsAddrsNameServers =
|
|
|
|
|
|
@[parseIpAddress("8.8.8.8"), parseIpAddress("1.1.1.1")]
|
2024-10-25 22:59:02 +02:00
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf.shards = @[conf.shard]
|
|
|
|
|
|
wakuNodeConf.contentTopics = conf.contentTopics
|
|
|
|
|
|
wakuNodeConf.clusterId = conf.clusterId
|
2024-05-21 23:03:33 +02:00
|
|
|
|
## TODO: Depending on the tester needs we might extend here with shards, clusterId, etc...
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf.metricsServer = true
|
|
|
|
|
|
wakuNodeConf.metricsServerAddress = parseIpAddress("0.0.0.0")
|
|
|
|
|
|
wakuNodeConf.metricsServerPort = conf.metricsPort
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
2024-10-25 22:59:02 +02:00
|
|
|
|
# If bootstrap option is chosen we expect our clients will not mounted
|
|
|
|
|
|
# so we will mount PeerExchange manually to gather possible service peers,
|
|
|
|
|
|
# if got some we will mount the client protocols afterward.
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf.peerExchange = false
|
|
|
|
|
|
wakuNodeConf.relay = false
|
|
|
|
|
|
wakuNodeConf.filter = false
|
|
|
|
|
|
wakuNodeConf.lightpush = false
|
|
|
|
|
|
wakuNodeConf.store = false
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
wakuNodeConf.rest = false
|
|
|
|
|
|
wakuNodeConf.relayServiceRatio = "40:60"
|
2025-06-16 12:46:20 +02:00
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
let wakuConf = wakuNodeConf.toWakuConf().valueOr:
|
|
|
|
|
|
error "Issue converting toWakuConf", error = $error
|
2024-05-21 23:03:33 +02:00
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
2025-07-10 19:49:47 +03:00
|
|
|
|
var waku = (waitFor Waku.new(wakuConf)).valueOr:
|
2025-06-16 18:44:21 +02:00
|
|
|
|
error "Waku initialization failed", error = error
|
|
|
|
|
|
quit(QuitFailure)
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
(waitFor startWaku(addr waku)).isOkOr:
|
2024-05-21 23:03:33 +02:00
|
|
|
|
error "Starting waku failed", error = error
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
2025-10-15 10:49:36 +02:00
|
|
|
|
info "Setting up shutdown hooks"
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
proc asyncStopper(waku: Waku) {.async: (raises: [Exception]).} =
|
|
|
|
|
|
await waku.stop()
|
2024-05-21 23:03:33 +02:00
|
|
|
|
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"
|
2025-06-16 18:44:21 +02:00
|
|
|
|
asyncSpawn asyncStopper(waku)
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
setControlCHook(handleCtrlC)
|
|
|
|
|
|
|
|
|
|
|
|
# Handle SIGTERM
|
|
|
|
|
|
when defined(posix):
|
|
|
|
|
|
proc handleSigterm(signal: cint) {.noconv.} =
|
|
|
|
|
|
notice "Shutting down after receiving SIGTERM"
|
2025-06-16 18:44:21 +02:00
|
|
|
|
asyncSpawn asyncStopper(waku)
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
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", stacktrace = getBacktrace()
|
|
|
|
|
|
|
|
|
|
|
|
# Not available in -d:release mode
|
|
|
|
|
|
writeStackTrace()
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
waitFor waku.stop()
|
2024-05-21 23:03:33 +02:00
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
|
|
|
|
|
c_signal(ansi_c.SIGSEGV, handleSigsegv)
|
|
|
|
|
|
|
|
|
|
|
|
info "Node setup complete"
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
var codec = WakuLightPushCodec
|
2024-10-25 22:59:02 +02:00
|
|
|
|
# mounting relevant client, for PX filter client must be mounted ahead
|
2025-06-16 18:44:21 +02:00
|
|
|
|
if conf.testFunc == TesterFunctionality.SENDER:
|
|
|
|
|
|
codec = WakuLightPushCodec
|
|
|
|
|
|
else:
|
|
|
|
|
|
codec = WakuFilterSubscribeCodec
|
2024-10-25 22:59:02 +02:00
|
|
|
|
|
|
|
|
|
|
var lookForServiceNode = false
|
|
|
|
|
|
var serviceNodePeerInfo: RemotePeerInfo
|
|
|
|
|
|
if conf.serviceNode.len == 0:
|
|
|
|
|
|
if conf.bootstrapNode.len > 0:
|
|
|
|
|
|
info "Bootstrapping with PeerExchange to gather random service node"
|
2025-06-16 18:44:21 +02:00
|
|
|
|
let futForServiceNode = pxLookupServiceNode(waku.node, conf)
|
2024-10-25 22:59:02 +02:00
|
|
|
|
if not (waitFor futForServiceNode.withTimeout(20.minutes)):
|
|
|
|
|
|
error "Service node not found in time via PX"
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
2025-10-27 14:07:06 -03:00
|
|
|
|
futForServiceNode.read().isOkOr:
|
2024-10-25 22:59:02 +02:00
|
|
|
|
error "Service node for test not found via PX"
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
|
|
|
|
|
serviceNodePeerInfo = selectRandomServicePeer(
|
2025-06-16 18:44:21 +02:00
|
|
|
|
waku.node.peerManager, none(RemotePeerInfo), codec
|
2024-10-25 22:59:02 +02:00
|
|
|
|
).valueOr:
|
|
|
|
|
|
error "Service node selection failed"
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
else:
|
|
|
|
|
|
error "No service or bootstrap node provided"
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
else:
|
|
|
|
|
|
# support for both ENR and URI formatted service node addresses
|
|
|
|
|
|
serviceNodePeerInfo = translateToRemotePeerInfo(conf.serviceNode).valueOr:
|
|
|
|
|
|
error "failed to parse service-node", node = conf.serviceNode
|
|
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
|
|
|
|
|
info "Service node to be used", serviceNode = $serviceNodePeerInfo
|
|
|
|
|
|
|
2025-06-16 18:44:21 +02:00
|
|
|
|
logSelfPeers(waku.node.peerManager)
|
2024-10-25 22:59:02 +02:00
|
|
|
|
|
2024-05-21 23:03:33 +02:00
|
|
|
|
if conf.testFunc == TesterFunctionality.SENDER:
|
2025-06-16 18:44:21 +02:00
|
|
|
|
setupAndPublish(waku.node, conf, serviceNodePeerInfo)
|
2024-05-21 23:03:33 +02:00
|
|
|
|
else:
|
2025-06-16 18:44:21 +02:00
|
|
|
|
setupAndListen(waku.node, conf, serviceNodePeerInfo)
|
2024-05-21 23:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
runForever()
|