diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index 8d0b2342c..207f621b2 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # Generated automatically by config.status (libbacktrace) version-unused -# Libtool was configured on host fv-az180-641: +# Libtool was configured on host fv-az47-448: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku/v2/node/waku_setup.nim b/waku/v2/node/waku_setup.nim deleted file mode 100644 index e512231b6..000000000 --- a/waku/v2/node/waku_setup.nim +++ /dev/null @@ -1,115 +0,0 @@ -{.push raises: [Defect].} - -## Collection of utilities commonly used -## during the setup phase of a Waku v2 node - -import - std/tables, - chronos, - chronicles, - json_rpc/rpcserver, - metrics, - metrics/chronos_httpserver, - stew/results, - stew/shims/net, - ./storage/sqlite, - ./storage/migration/migration_types, - ./jsonrpc/[admin_api, - debug_api, - filter_api, - relay_api, - store_api, - private_api, - debug_api], - ./config, - ./wakunode2 - -logScope: - topics = "wakunode.setup" - -type - SetupResult*[T] = Result[T, string] - -########################## -# Setup helper functions # -########################## - -proc startRpc*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf) - {.raises: [Defect, RpcBindError, CatchableError].} = - # @TODO: API handlers still raise CatchableError - - let - ta = initTAddress(rpcIp, rpcPort) - rpcServer = newRpcHttpServer([ta]) - installDebugApiHandlers(node, rpcServer) - - # Install enabled API handlers: - if conf.relay: - let topicCache = newTable[string, seq[WakuMessage]]() - installRelayApiHandlers(node, rpcServer, topicCache) - if conf.rpcPrivate: - # Private API access allows WakuRelay functionality that - # is backwards compatible with Waku v1. - installPrivateApiHandlers(node, rpcServer, node.rng, topicCache) - - if conf.filter: - let messageCache = newTable[ContentTopic, seq[WakuMessage]]() - installFilterApiHandlers(node, rpcServer, messageCache) - - if conf.store: - installStoreApiHandlers(node, rpcServer) - - if conf.rpcAdmin: - installAdminApiHandlers(node, rpcServer) - - rpcServer.start() - info "RPC Server started", ta - -proc startMetricsServer*(serverIp: ValidIpAddress, serverPort: Port) = - info "Starting metrics HTTP server", serverIp, serverPort - - try: - startMetricsHttpServer($serverIp, serverPort) - except Exception as e: - raiseAssert("Exception while starting metrics HTTP server: " & e.msg) - - info "Metrics HTTP server started", serverIp, serverPort - -proc startMetricsLog*() = - # https://github.com/nim-lang/Nim/issues/17369 - var logMetrics: proc(udata: pointer) {.gcsafe, raises: [Defect].} - logMetrics = proc(udata: pointer) = - {.gcsafe.}: - # TODO: libp2p_pubsub_peers is not public, so we need to make this either - # public in libp2p or do our own peer counting after all. - var - totalMessages = 0.float64 - - for key in waku_node_messages.metrics.keys(): - try: - totalMessages = totalMessages + waku_node_messages.value(key) - except KeyError: - discard - - info "Node metrics", totalMessages - discard setTimer(Moment.fromNow(2.seconds), logMetrics) - discard setTimer(Moment.fromNow(2.seconds), logMetrics) - -proc runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) = - # Run migration scripts on persistent storage - - var migrationPath: string - if conf.persistPeers and conf.persistMessages: - migrationPath = migration_types.ALL_STORE_MIGRATION_PATH - elif conf.persistPeers: - migrationPath = migration_types.PEER_STORE_MIGRATION_PATH - elif conf.persistMessages: - migrationPath = migration_types.MESSAGE_STORE_MIGRATION_PATH - - # run migration - info "running migration ...", migrationPath=migrationPath - let migrationResult = sqliteDatabase.migrate(migrationPath) - if migrationResult.isErr: - warn "migration failed", error=migrationResult.error - else: - info "migration is done" diff --git a/waku/v2/node/wakunode2.nim b/waku/v2/node/wakunode2.nim index 7be90cc86..80ec95341 100644 --- a/waku/v2/node/wakunode2.nim +++ b/waku/v2/node/wakunode2.nim @@ -790,8 +790,11 @@ when isMainModule: libp2p/nameresolving/dnsresolver, ../../common/utils/nat, ./config, - ./waku_setup, + ./wakunode2_setup, ./wakunode2_setup_rest, + ./wakunode2_setup_metrics, + ./wakunode2_setup_rpc, + ./wakunode2_setup_sql_migrations, ./storage/message/waku_message_store, ./storage/peer/waku_peer_storage @@ -1083,7 +1086,7 @@ when isMainModule: ## monitoring ports. if conf.rpc: - startRpc(node, conf.rpcAddress, Port(conf.rpcPort + conf.portsShift), conf) + startRpcServer(node, conf.rpcAddress, Port(conf.rpcPort + conf.portsShift), conf) if conf.rest: startRestServer(node, conf.restAddress, Port(conf.restPort + conf.portsShift), conf) diff --git a/waku/v2/node/wakunode2_setup.nim b/waku/v2/node/wakunode2_setup.nim new file mode 100644 index 000000000..a3870bcaf --- /dev/null +++ b/waku/v2/node/wakunode2_setup.nim @@ -0,0 +1,5 @@ +{.push raises: [Defect].} + +import stew/results + +type SetupResult*[T] = Result[T, string] diff --git a/waku/v2/node/wakunode2_setup_metrics.nim b/waku/v2/node/wakunode2_setup_metrics.nim new file mode 100644 index 000000000..7b5dd970a --- /dev/null +++ b/waku/v2/node/wakunode2_setup_metrics.nim @@ -0,0 +1,47 @@ +{.push raises: [Defect].} + +import + stew/results, + stew/shims/net, + chronicles, + chronos, + metrics, + metrics/chronos_httpserver, + ./config, + ./wakunode2 + +logScope: + topics = "wakunode.setup.metrics" + + +proc startMetricsServer*(serverIp: ValidIpAddress, serverPort: Port) = + info "Starting metrics HTTP server", serverIp, serverPort + + try: + startMetricsHttpServer($serverIp, serverPort) + except Exception as e: + raiseAssert("Exception while starting metrics HTTP server: " & e.msg) + + info "Metrics HTTP server started", serverIp, serverPort + + +proc startMetricsLog*() = + # https://github.com/nim-lang/Nim/issues/17369 + var logMetrics: proc(udata: pointer) {.gcsafe, raises: [Defect].} + + logMetrics = proc(udata: pointer) = + {.gcsafe.}: + # TODO: libp2p_pubsub_peers is not public, so we need to make this either + # public in libp2p or do our own peer counting after all. + var totalMessages = 0.float64 + for key in waku_node_messages.metrics.keys(): + try: + totalMessages = totalMessages + waku_node_messages.value(key) + except KeyError: + discard + + info "Node metrics", totalMessages + discard setTimer(Moment.fromNow(2.seconds), logMetrics) + + discard setTimer(Moment.fromNow(2.seconds), logMetrics) + \ No newline at end of file diff --git a/waku/v2/node/wakunode2_setup_rpc.nim b/waku/v2/node/wakunode2_setup_rpc.nim new file mode 100644 index 000000000..4e35467e5 --- /dev/null +++ b/waku/v2/node/wakunode2_setup_rpc.nim @@ -0,0 +1,52 @@ +{.push raises: [Defect].} + +import + std/tables, + stew/shims/net, + chronicles, + json_rpc/rpcserver +import + ./config, + ./wakunode2, + ./jsonrpc/[admin_api, + debug_api, + filter_api, + relay_api, + store_api, + private_api, + debug_api] + +logScope: + topics = "wakunode.setup.rpc" + + +proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf) + {.raises: [Defect, RpcBindError].} = + + let + ta = initTAddress(rpcIp, rpcPort) + rpcServer = newRpcHttpServer([ta]) + + installDebugApiHandlers(node, rpcServer) + + if conf.relay: + let topicCache = newTable[string, seq[WakuMessage]]() + installRelayApiHandlers(node, rpcServer, topicCache) + + if conf.rpcPrivate: + # Private API access allows WakuRelay functionality that + # is backwards compatible with Waku v1. + installPrivateApiHandlers(node, rpcServer, node.rng, topicCache) + + if conf.filter: + let messageCache = newTable[ContentTopic, seq[WakuMessage]]() + installFilterApiHandlers(node, rpcServer, messageCache) + + if conf.store: + installStoreApiHandlers(node, rpcServer) + + if conf.rpcAdmin: + installAdminApiHandlers(node, rpcServer) + + rpcServer.start() + info "RPC Server started", ta \ No newline at end of file diff --git a/waku/v2/node/wakunode2_setup_sql_migrations.nim b/waku/v2/node/wakunode2_setup_sql_migrations.nim new file mode 100644 index 000000000..d2ff655ce --- /dev/null +++ b/waku/v2/node/wakunode2_setup_sql_migrations.nim @@ -0,0 +1,29 @@ +{.push raises: [Defect].} + +import + chronicles, + ./storage/sqlite, + ./storage/migration/migration_types, + ./config, + ./wakunode2 + +logScope: + topics = "wakunode.setup.migrations" + + +proc runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) = + # Run migration scripts on persistent storage + var migrationPath: string + if conf.persistPeers and conf.persistMessages: + migrationPath = migration_types.ALL_STORE_MIGRATION_PATH + elif conf.persistPeers: + migrationPath = migration_types.PEER_STORE_MIGRATION_PATH + elif conf.persistMessages: + migrationPath = migration_types.MESSAGE_STORE_MIGRATION_PATH + + info "running migration ...", migrationPath=migrationPath + let migrationResult = sqliteDatabase.migrate(migrationPath) + if migrationResult.isErr: + warn "migration failed", error=migrationResult.error + else: + info "migration is done"