From 757804c9ee76fd53406fed96dfbc1b08f02c066a Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Tue, 18 Oct 2022 12:35:26 -0500 Subject: [PATCH] chore(wakunode2): move wakunode2 to apps directory --- {waku/v2/node => apps/wakunode2}/config.nim | 0 apps/wakunode2/nim.cfg | 5 ++ .../v2/node => apps/wakunode2}/wakunode2.nim | 82 ++++++++++--------- .../wakunode2}/wakunode2_setup_metrics.nim | 26 +++--- .../wakunode2}/wakunode2_setup_rest.nim | 10 +-- .../wakunode2}/wakunode2_setup_rpc.nim | 20 ++--- .../wakunode2_setup_sql_migrations.nim | 7 +- examples/v2/basic2.nim | 3 +- waku.nimble | 2 +- waku/v2/node/discv5/waku_discv5.nim | 2 +- waku/v2/node/wakunode2_setup.nim | 5 -- .../waku_rln_relay/waku_rln_relay_utils.nim | 2 +- 12 files changed, 87 insertions(+), 77 deletions(-) rename {waku/v2/node => apps/wakunode2}/config.nim (100%) create mode 100644 apps/wakunode2/nim.cfg rename {waku/v2/node => apps/wakunode2}/wakunode2.nim (92%) rename {waku/v2/node => apps/wakunode2}/wakunode2_setup_metrics.nim (82%) rename {waku/v2/node => apps/wakunode2}/wakunode2_setup_rest.nim (82%) rename {waku/v2/node => apps/wakunode2}/wakunode2_setup_rpc.nim (72%) rename {waku/v2/node => apps/wakunode2}/wakunode2_setup_sql_migrations.nim (87%) delete mode 100644 waku/v2/node/wakunode2_setup.nim diff --git a/waku/v2/node/config.nim b/apps/wakunode2/config.nim similarity index 100% rename from waku/v2/node/config.nim rename to apps/wakunode2/config.nim diff --git a/apps/wakunode2/nim.cfg b/apps/wakunode2/nim.cfg new file mode 100644 index 000000000..a31adc759 --- /dev/null +++ b/apps/wakunode2/nim.cfg @@ -0,0 +1,5 @@ +-d:chronicles_line_numbers +-d:"chronicles_runtime_filtering=on" +-d:nimDebugDlOpen +# Results in empty output for some reason +#-d:"chronicles_enabled_topics=GossipSub:TRACE,WakuRelay:TRACE" diff --git a/waku/v2/node/wakunode2.nim b/apps/wakunode2/wakunode2.nim similarity index 92% rename from waku/v2/node/wakunode2.nim rename to apps/wakunode2/wakunode2.nim index e495850d1..f46b17286 100644 --- a/waku/v2/node/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -2,29 +2,54 @@ import std/[options, tables, strutils, sequtils, os], - chronos, chronicles, metrics, stew/shims/net as stewNet, + chronicles, + chronos, + metrics, + confutils, + toml_serialization, + system/ansi_c, eth/keys, eth/p2p/discoveryv5/enr, + libp2p/[builders, multihash], libp2p/crypto/crypto, libp2p/protocols/ping, libp2p/protocols/pubsub/[gossipsub, rpc/messages], - libp2p/[builders, multihash], - libp2p/transports/[transport, wstransport] + libp2p/transports/[transport, wstransport], + libp2p/nameresolving/dnsresolver import - ../protocol/waku_store, - ../protocol/waku_filter, - ../protocol/waku_rln_relay/waku_rln_relay_types, - ../protocol/waku_peer_exchange, - ../utils/[peers, wakuenr], - ./peer_manager/peer_manager, - ./storage/message/waku_store_queue, - ./storage/message/message_retention_policy_capacity, - ./storage/message/message_retention_policy_time, - ./dnsdisc/waku_dnsdisc, - ./discv5/waku_discv5, - ./wakuswitch, - ./waku_node + ../../waku/v2/protocol/waku_store, + ../../waku/v2/protocol/waku_filter, + ../../waku/v2/protocol/waku_peer_exchange, + ../../waku/v2/node/peer_manager/peer_manager, + ../../waku/v2/node/dnsdisc/waku_dnsdisc, + ../../waku/v2/node/discv5/waku_discv5, + ../../waku/v2/node/storage/sqlite, + ../../waku/v2/node/storage/peer/waku_peer_storage, + ../../waku/v2/node/storage/message/waku_store_queue, + ../../waku/v2/node/storage/message/dual_message_store, + ../../waku/v2/node/storage/message/sqlite_store, + ../../waku/v2/node/storage/message/message_retention_policy_capacity, + ../../waku/v2/node/storage/message/message_retention_policy_time, + ../../waku/v2/node/wakuswitch, + ../../waku/v2/node/waku_node, + ../../waku/v2/utils/peers, + ../../waku/v2/utils/wakuenr, + ../../waku/common/utils/nat, + ./wakunode2_setup_rest, + ./wakunode2_setup_metrics, + ./wakunode2_setup_rpc, + ./wakunode2_setup_sql_migrations, + ./config + +when defined(rln) or defined(rlnzerokit): + import + ../../waku/v2/protocol/waku_rln_relay/waku_rln_relay_types, + ../../waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils + + +logScope: + topics = "wakunode.setup" {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError @@ -36,34 +61,13 @@ when isMainModule: ## 4. Start node and mounted protocols ## 5. Start monitoring tools and external interfaces ## 6. Setup graceful shutdown hooks - - import - confutils, toml_serialization, - system/ansi_c, - libp2p/nameresolving/dnsresolver, - ../../common/utils/nat, - ./config, - ./wakunode2_setup, - ./wakunode2_setup_rest, - ./wakunode2_setup_metrics, - ./wakunode2_setup_rpc, - ./wakunode2_setup_sql_migrations, - ./storage/sqlite, - ./storage/message/dual_message_store, - ./storage/message/sqlite_store, - ./storage/peer/waku_peer_storage - - when defined(rln) or defined(rlnzerokit): - import ../protocol/waku_rln_relay/waku_rln_relay_utils - - - logScope: - topics = "wakunode.setup" ################### # Setup functions # ################### + type SetupResult[T] = Result[T, string] + # 1/7 Setup storage proc setupStorage(conf: WakuNodeConf): SetupResult[tuple[pStorage: WakuPeerStorage, mStorage: MessageStore]] = diff --git a/waku/v2/node/wakunode2_setup_metrics.nim b/apps/wakunode2/wakunode2_setup_metrics.nim similarity index 82% rename from waku/v2/node/wakunode2_setup_metrics.nim rename to apps/wakunode2/wakunode2_setup_metrics.nim index 9da0a7c64..e5819a244 100644 --- a/waku/v2/node/wakunode2_setup_metrics.nim +++ b/apps/wakunode2/wakunode2_setup_metrics.nim @@ -6,17 +6,21 @@ import chronicles, chronos, metrics, - metrics/chronos_httpserver, - ./config, - ./waku_node, - ./peer_manager/peer_manager, - ../protocol/waku_filter, - ../protocol/waku_store, - ../protocol/waku_lightpush, - ../protocol/waku_swap/waku_swap, - ../protocol/waku_peer_exchange, - ../protocol/waku_rln_relay/waku_rln_relay_metrics, - ../utils/collector + metrics/chronos_httpserver +import + ../../waku/v2/protocol/waku_filter, + ../../waku/v2/protocol/waku_store, + ../../waku/v2/protocol/waku_lightpush, + ../../waku/v2/protocol/waku_swap/waku_swap, + ../../waku/v2/protocol/waku_peer_exchange, + ../../waku/v2/utils/collector, + ../../waku/v2/node/peer_manager/peer_manager, + ../../waku/v2/node/waku_node, + ./config + +when defined(rln) or defined(rlnzerokit): + import ../../waku/v2/protocol/waku_rln_relay/waku_rln_relay_metrics + logScope: topics = "wakunode.setup.metrics" diff --git a/waku/v2/node/wakunode2_setup_rest.nim b/apps/wakunode2/wakunode2_setup_rest.nim similarity index 82% rename from waku/v2/node/wakunode2_setup_rest.nim rename to apps/wakunode2/wakunode2_setup_rest.nim index a83313c64..41648996e 100644 --- a/waku/v2/node/wakunode2_setup_rest.nim +++ b/apps/wakunode2/wakunode2_setup_rest.nim @@ -5,11 +5,11 @@ import chronicles, presto import - ./config, - ./waku_node, - ./rest/server, - ./rest/debug/debug_api, - ./rest/relay/[relay_api, topic_cache] + ../../waku/v2/node/waku_node, + ../../waku/v2/node/rest/server, + ../../waku/v2/node/rest/debug/debug_api, + ../../waku/v2/node/rest/relay/[relay_api, topic_cache], + ./config logScope: diff --git a/waku/v2/node/wakunode2_setup_rpc.nim b/apps/wakunode2/wakunode2_setup_rpc.nim similarity index 72% rename from waku/v2/node/wakunode2_setup_rpc.nim rename to apps/wakunode2/wakunode2_setup_rpc.nim index 749011e93..dbc1fe6bd 100644 --- a/waku/v2/node/wakunode2_setup_rpc.nim +++ b/apps/wakunode2/wakunode2_setup_rpc.nim @@ -6,16 +6,16 @@ import chronicles, json_rpc/rpcserver import - ./config, - ../protocol/waku_message, - ./waku_node, - ./jsonrpc/[admin_api, - debug_api, - filter_api, - relay_api, - store_api, - private_api, - debug_api] + ../../waku/v2/protocol/waku_message, + ../../waku/v2/node/waku_node, + ../../waku/v2/node/jsonrpc/[admin_api, + debug_api, + filter_api, + relay_api, + store_api, + private_api, + debug_api], + ./config logScope: topics = "wakunode.setup.rpc" diff --git a/waku/v2/node/wakunode2_setup_sql_migrations.nim b/apps/wakunode2/wakunode2_setup_sql_migrations.nim similarity index 87% rename from waku/v2/node/wakunode2_setup_sql_migrations.nim rename to apps/wakunode2/wakunode2_setup_sql_migrations.nim index 2906fba9c..b68406f91 100644 --- a/waku/v2/node/wakunode2_setup_sql_migrations.nim +++ b/apps/wakunode2/wakunode2_setup_sql_migrations.nim @@ -2,9 +2,10 @@ import stew/results, - chronicles, - ./storage/sqlite, - ./storage/migration, + chronicles +import + ../../waku/v2/node/storage/sqlite, + ../../waku/v2/node/storage/migration, ./config logScope: diff --git a/examples/v2/basic2.nim b/examples/v2/basic2.nim index 217d9191e..475656734 100644 --- a/examples/v2/basic2.nim +++ b/examples/v2/basic2.nim @@ -8,7 +8,8 @@ import libp2p/crypto/[crypto,secp], eth/keys, json_rpc/[rpcclient, rpcserver], - ../../waku/v2/node/[config, waku_node], + ../../waku/v2/node/waku_node, + ../../apps/wakunode2/config, ../../waku/common/utils/nat, ../../waku/v2/protocol/waku_message diff --git a/waku.nimble b/waku.nimble index aa9b260be..f4865f381 100644 --- a/waku.nimble +++ b/waku.nimble @@ -65,7 +65,7 @@ task test1, "Build & run Waku v1 tests": ### Waku v2 tasks task wakunode2, "Build Waku v2 (experimental) cli node": let name = "wakunode2" - buildBinary name, "waku/v2/node/", "-d:chronicles_log_level=DEBUG" + buildBinary name, "apps/wakunode2/", "-d:chronicles_log_level=DEBUG" task bridge, "Build Waku v1 - v2 bridge": let name = "wakubridge" diff --git a/waku/v2/node/discv5/waku_discv5.nim b/waku/v2/node/discv5/waku_discv5.nim index eb979962c..cb63b0385 100644 --- a/waku/v2/node/discv5/waku_discv5.nim +++ b/waku/v2/node/discv5/waku_discv5.nim @@ -6,7 +6,7 @@ import eth/keys, eth/p2p/discoveryv5/[enr, node, protocol], stew/results, - ../config, + ../../../../apps/wakunode2/config, ## TODO: Remove dependency on wakunode2 config module ../../utils/[peers, wakuenr] export protocol, wakuenr diff --git a/waku/v2/node/wakunode2_setup.nim b/waku/v2/node/wakunode2_setup.nim deleted file mode 100644 index a3870bcaf..000000000 --- a/waku/v2/node/wakunode2_setup.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.push raises: [Defect].} - -import stew/results - -type SetupResult*[T] = Result[T, string] diff --git a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim index 30af8f870..3b4f983c5 100644 --- a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim +++ b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim @@ -17,7 +17,7 @@ import waku_rln_relay_metrics, ../../utils/time, ../../node/waku_node, - ../../node/config, ## TODO: Decouple the protocol code from the app configuration + ../../../../../apps/wakunode2/config, ## TODO: Decouple the protocol code from the app configuration ../../../../../apps/chat2/config_chat2, ## TODO: Decouple the protocol code from the app configuration ../waku_message