2022-11-04 10:52:27 +01:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-07-17 16:25:21 +02:00
|
|
|
|
|
|
|
import
|
|
|
|
stew/shims/net,
|
|
|
|
chronicles,
|
|
|
|
json_rpc/rpcserver
|
|
|
|
import
|
2023-02-10 10:43:16 +01:00
|
|
|
../../waku/v2/node/message_cache,
|
2023-04-05 11:58:59 +02:00
|
|
|
../../waku/v2/waku_node,
|
2023-02-10 10:43:16 +01:00
|
|
|
../../waku/v2/node/jsonrpc/admin/handlers as admin_api,
|
|
|
|
../../waku/v2/node/jsonrpc/debug/handlers as debug_api,
|
|
|
|
../../waku/v2/node/jsonrpc/filter/handlers as filter_api,
|
|
|
|
../../waku/v2/node/jsonrpc/relay/handlers as relay_api,
|
|
|
|
../../waku/v2/node/jsonrpc/store/handlers as store_api,
|
2022-10-18 12:35:26 -05:00
|
|
|
./config
|
2022-07-17 16:25:21 +02:00
|
|
|
|
|
|
|
logScope:
|
2022-11-04 09:40:13 +01:00
|
|
|
topics = "wakunode jsonrpc"
|
2022-07-17 16:25:21 +02:00
|
|
|
|
|
|
|
|
2023-02-10 10:43:16 +01:00
|
|
|
proc startRpcServer*(node: WakuNode, address: ValidIpAddress, port: Port, conf: WakuNodeConf)
|
2023-01-11 08:06:30 +02:00
|
|
|
{.raises: [CatchableError].} =
|
2022-07-17 16:25:21 +02:00
|
|
|
|
|
|
|
let
|
2023-02-10 10:43:16 +01:00
|
|
|
ta = initTAddress(address, port)
|
|
|
|
server = newRpcHttpServer([ta])
|
2023-01-11 08:06:30 +02:00
|
|
|
|
2023-02-10 10:43:16 +01:00
|
|
|
installDebugApiHandlers(node, server)
|
2022-07-17 16:25:21 +02:00
|
|
|
|
2022-11-15 22:03:06 +01:00
|
|
|
# TODO: Move to setup protocols proc
|
2022-07-17 16:25:21 +02:00
|
|
|
if conf.relay:
|
2023-02-10 10:43:16 +01:00
|
|
|
let relayMessageCache = relay_api.MessageCache.init(capacity=30)
|
|
|
|
installRelayApiHandlers(node, server, relayMessageCache)
|
2022-07-17 16:25:21 +02:00
|
|
|
if conf.rpcPrivate:
|
2023-02-10 10:43:16 +01:00
|
|
|
installRelayPrivateApiHandlers(node, server, relayMessageCache)
|
2023-01-11 08:06:30 +02:00
|
|
|
|
2022-11-15 22:03:06 +01:00
|
|
|
# TODO: Move to setup protocols proc
|
|
|
|
if conf.filternode != "":
|
2023-02-10 10:43:16 +01:00
|
|
|
let filterMessageCache = filter_api.MessageCache.init(capacity=30)
|
|
|
|
installFilterApiHandlers(node, server, filterMessageCache)
|
2023-01-11 08:06:30 +02:00
|
|
|
|
2023-04-12 09:26:26 +02:00
|
|
|
installStoreApiHandlers(node, server)
|
2023-01-11 08:06:30 +02:00
|
|
|
|
2022-07-17 16:25:21 +02:00
|
|
|
if conf.rpcAdmin:
|
2023-02-10 10:43:16 +01:00
|
|
|
installAdminApiHandlers(node, server)
|
2023-01-11 08:06:30 +02:00
|
|
|
|
2023-02-10 10:43:16 +01:00
|
|
|
server.start()
|
2023-01-11 08:06:30 +02:00
|
|
|
info "RPC Server started", address=ta
|