diff --git a/waku/v2/node/waku_setup.nim b/waku/v2/node/waku_setup.nim index 29037f76d..10262220e 100644 --- a/waku/v2/node/waku_setup.nim +++ b/waku/v2/node/waku_setup.nim @@ -7,20 +7,12 @@ 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 @@ -34,37 +26,6 @@ type # 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 runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) = # Run migration scripts on persistent storage diff --git a/waku/v2/node/wakunode2.nim b/waku/v2/node/wakunode2.nim index ab4af75bb..7844a0542 100644 --- a/waku/v2/node/wakunode2.nim +++ b/waku/v2/node/wakunode2.nim @@ -791,11 +791,9 @@ when isMainModule: ../../common/utils/nat, ./config, ./waku_setup, -<<<<<<< HEAD ./wakunode2_setup_rest, -======= ./wakunode2_setup_metrics, ->>>>>>> 37a9c0c1 (refactor(wakunode2): Split wankunode2 metrics setup to its own file) + ./wakunode2_setup_rpc, ./storage/message/waku_message_store, ./storage/peer/waku_peer_storage @@ -1087,7 +1085,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_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