refactor: start moving discovery modules to waku/discovery (#2587)

This commit is contained in:
Ivan FB 2024-04-17 21:48:20 +02:00 committed by GitHub
parent aa9c3025db
commit 828583adc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 73 additions and 41 deletions

View File

@ -39,7 +39,7 @@ import
../../waku/waku_lightpush/rpc, ../../waku/waku_lightpush/rpc,
../../waku/waku_enr, ../../waku/waku_enr,
../../waku/waku_store, ../../waku/waku_store,
../../waku/waku_dnsdisc, ../../waku/discovery/waku_dnsdisc,
../../waku/waku_node, ../../waku/waku_node,
../../waku/node/waku_metrics, ../../waku/node/waku_metrics,
../../waku/node/peer_manager, ../../waku/node/peer_manager,
@ -523,7 +523,9 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
if msg.contentTopic == chat.contentTopic: if msg.contentTopic == chat.contentTopic:
chat.printReceivedMessage(msg) chat.printReceivedMessage(msg)
node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(WakuRelayHandler(handler))) node.subscribe(
(kind: PubsubSub, topic: DefaultPubsubTopic), some(WakuRelayHandler(handler))
)
if conf.rlnRelay: if conf.rlnRelay:
info "WakuRLNRelay is enabled" info "WakuRLNRelay is enabled"

View File

@ -25,8 +25,8 @@ import
../../waku/node/peer_manager, ../../waku/node/peer_manager,
../../waku/waku_node, ../../waku/waku_node,
../../waku/waku_enr, ../../waku/waku_enr,
../../waku/waku_discv5, ../../waku/discovery/waku_discv5,
../../waku/waku_dnsdisc, ../../waku/discovery/waku_dnsdisc,
../../waku/waku_relay, ../../waku/waku_relay,
../../waku/waku_rln_relay, ../../waku/waku_rln_relay,
../../waku/factory/builder, ../../waku/factory/builder,
@ -131,12 +131,12 @@ proc setConnectedPeersMetrics(
var analyzeFuts: seq[Future[Result[string, string]]] var analyzeFuts: seq[Future[Result[string, string]]]
var (inConns, outConns) = node.peer_manager.connectedPeers(WakuRelayCodec) var (inConns, outConns) = node.peer_manager.connectedPeers(WakuRelayCodec)
info "connected peers", inConns=inConns.len, outConns=outConns.len info "connected peers", inConns = inConns.len, outConns = outConns.len
shuffle(outConns) shuffle(outConns)
if outConns.len >= toInt(MaxConnectedPeers/2): if outConns.len >= toInt(MaxConnectedPeers / 2):
for p in outConns[0 ..< toInt(outConns.len/2)]: for p in outConns[0 ..< toInt(outConns.len / 2)]:
trace "Pruning Peer", Peer = $p trace "Pruning Peer", Peer = $p
asyncSpawn(node.switch.disconnect(p)) asyncSpawn(node.switch.disconnect(p))

View File

@ -40,9 +40,9 @@ import
../../waku/waku_api/rest/health/handlers as rest_health_api, ../../waku/waku_api/rest/health/handlers as rest_health_api,
../../waku/waku_api/rest/admin/handlers as rest_admin_api, ../../waku/waku_api/rest/admin/handlers as rest_admin_api,
../../waku/waku_archive, ../../waku/waku_archive,
../../waku/waku_dnsdisc, ../../waku/discovery/waku_dnsdisc,
../../waku/discovery/waku_discv5,
../../waku/waku_enr/sharding, ../../waku/waku_enr/sharding,
../../waku/waku_discv5,
../../waku/waku_peer_exchange, ../../waku/waku_peer_exchange,
../../waku/waku_rln_relay, ../../waku/waku_rln_relay,
../../waku/waku_store, ../../waku/waku_store,
@ -366,9 +366,7 @@ proc startRestServer(
"/relay endpoints are not available. Please check your configuration: --relay" "/relay endpoints are not available. Please check your configuration: --relay"
## Filter REST API ## Filter REST API
if conf.filternode != "" and if conf.filternode != "" and app.node.wakuFilterClient != nil:
app.node.wakuFilterClient != nil:
let filterCache = MessageCache.init() let filterCache = MessageCache.init()
let filterDiscoHandler = let filterDiscoHandler =

View File

@ -15,7 +15,7 @@ import
../../../waku/waku_core, ../../../waku/waku_core,
../../../waku/waku_node, ../../../waku/waku_node,
../../../waku/waku_enr, ../../../waku/waku_enr,
../../../waku/waku_discv5, ../../../waku/discovery/waku_discv5,
../../../waku/factory/builder ../../../waku/factory/builder
proc now*(): Timestamp = proc now*(): Timestamp =

View File

@ -15,7 +15,7 @@ import
../../../waku/waku_core, ../../../waku/waku_core,
../../../waku/waku_node, ../../../waku/waku_node,
../../../waku/waku_enr, ../../../waku/waku_enr,
../../../waku/waku_discv5, ../../../waku/discovery/waku_discv5,
../../../waku/factory/builder, ../../../waku/factory/builder,
../../../waku/waku_relay ../../../waku/waku_relay

View File

@ -15,7 +15,7 @@ import
import import
../../../waku/[ ../../../waku/[
waku_node, waku_node,
waku_discv5, discovery/waku_discv5,
waku_peer_exchange, waku_peer_exchange,
node/peer_manager, node/peer_manager,
waku_relay/protocol, waku_relay/protocol,

View File

@ -13,7 +13,7 @@ import
import import
../../waku/node/peer_manager, ../../waku/node/peer_manager,
../../waku/waku_node, ../../waku/waku_node,
../../waku/waku_dnsdisc, ../../waku/discovery/waku_dnsdisc,
./testlib/common, ./testlib/common,
./testlib/wakucore, ./testlib/wakucore,
./testlib/wakunode ./testlib/wakunode

View File

@ -17,7 +17,7 @@ import
../../waku/waku_node, ../../waku/waku_node,
../../waku/waku_core/topics, ../../waku/waku_core/topics,
../../waku/node/peer_manager, ../../waku/node/peer_manager,
../../waku/waku_discv5, ../../waku/discovery/waku_discv5,
../../waku/waku_metadata, ../../waku/waku_metadata,
./testlib/wakucore, ./testlib/wakucore,
./testlib/wakunode ./testlib/wakunode

View File

@ -12,7 +12,7 @@ import
../../../waku/waku_node, ../../../waku/waku_node,
../../../waku/node/peer_manager, ../../../waku/node/peer_manager,
../../../waku/waku_enr, ../../../waku/waku_enr,
../../../waku/waku_discv5, ../../../waku/discovery/waku_discv5,
../../../waku/factory/external_config, ../../../waku/factory/external_config,
../../../waku/factory/internal_config, ../../../waku/factory/internal_config,
../../../waku/factory/builder, ../../../waku/factory/builder,

View File

@ -11,7 +11,7 @@ import
eth/keys as eth_keys eth/keys as eth_keys
import import
../../../waku/[waku_core/topics, waku_enr, waku_discv5, common/enr], ../../../waku/[waku_core/topics, waku_enr, discovery/waku_discv5, common/enr],
../testlib/[wakucore, testasync, assertions, futures], ../testlib/[wakucore, testasync, assertions, futures],
../waku_enr/utils, ../waku_enr/utils,
./utils ./utils

View File

@ -6,7 +6,8 @@ import
eth/keys as eth_keys eth/keys as eth_keys
import import
../../../waku/[waku_core/topics, waku_enr, waku_discv5], ../testlib/[common, wakucore] ../../../waku/[waku_core/topics, waku_enr, discovery/waku_discv5],
../testlib/[common, wakucore]
proc newTestDiscv5*( proc newTestDiscv5*(
privKey: libp2p_keys.PrivateKey, privKey: libp2p_keys.PrivateKey,

View File

@ -9,7 +9,7 @@ import
eth/keys as eth_keys eth/keys as eth_keys
import import
../../../waku/[waku_enr, waku_discv5, waku_core], ../../../waku/[waku_enr, discovery/waku_discv5, waku_core],
../testlib/wakucore, ../testlib/wakucore,
../waku_discv5/utils, ../waku_discv5/utils,
./utils ./utils

View File

@ -7,7 +7,7 @@ import
eth/keys as eth_keys eth/keys as eth_keys
import import
../../../waku/[waku_core/topics, waku_enr, waku_discv5, waku_enr/sharding], ../../../waku/[waku_core/topics, waku_enr, discovery/waku_discv5, waku_enr/sharding],
../testlib/[common, wakucore] ../testlib/[common, wakucore]
proc newTestEnrRecord*( proc newTestEnrRecord*(

View File

@ -13,7 +13,7 @@ import
../../../waku/[ ../../../waku/[
waku_node, waku_node,
node/peer_manager, node/peer_manager,
waku_discv5, discovery/waku_discv5,
waku_peer_exchange, waku_peer_exchange,
waku_peer_exchange/rpc, waku_peer_exchange/rpc,
waku_peer_exchange/rpc_codec, waku_peer_exchange/rpc_codec,

View File

@ -12,13 +12,12 @@ import
eth/p2p/discoveryv5/enr eth/p2p/discoveryv5/enr
import import
../../../waku/ ../../../waku/[
[ node/peer_manager,
node/peer_manager, discovery/waku_discv5,
waku_discv5, waku_peer_exchange/rpc,
waku_peer_exchange/rpc, waku_peer_exchange/rpc_codec,
waku_peer_exchange/rpc_codec, ],
],
../testlib/[wakucore] ../testlib/[wakucore]
suite "Peer Exchange RPC": suite "Peer Exchange RPC":

View File

@ -13,7 +13,7 @@ import
import import
../../../waku/[ ../../../waku/[
waku_node, waku_node,
waku_discv5, discovery/waku_discv5,
waku_peer_exchange, waku_peer_exchange,
waku_peer_exchange/rpc, waku_peer_exchange/rpc,
waku_peer_exchange/protocol, waku_peer_exchange/protocol,

View File

@ -0,0 +1,33 @@
when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}
import waku_discv5, ../../waku_core
## This module contains the logic needed to discover other peers and
## also to make the "self" node discoverable by other peers.
type DiscoveryManager* = object
wakuDiscv5*: Option[WakuDiscoveryV5]
dynamicBootstrapNodes*: seq[RemotePeerInfo]
#[
TODO: in future PRs we will have:
App* = object
version: string
conf: WakuNodeConf
rng: ref HmacDrbgContext
key: crypto.PrivateKey
## in future PRs, the following two items will be encapsulated by 'DiscoveryManager'
wakuDiscv5: Option[WakuDiscoveryV5] <-- this will get removed
dynamicBootstrapNodes: seq[RemotePeerInfo] <-- this will get removed
node: WakuNode <-- this will contain a discManager instance
restServer: Option[WakuRestServerRef]
metricsServer: Option[MetricsHttpServerRef]
]#

View File

@ -14,7 +14,7 @@ import
eth/keys as eth_keys, eth/keys as eth_keys,
eth/p2p/discoveryv5/node, eth/p2p/discoveryv5/node,
eth/p2p/discoveryv5/protocol eth/p2p/discoveryv5/protocol
import ./node/peer_manager/peer_manager, ./waku_core, ./waku_enr import ../node/peer_manager/peer_manager, ../waku_core, ../waku_enr
export protocol, waku_enr export protocol, waku_enr

View File

@ -21,7 +21,7 @@ import
libp2p/multiaddress, libp2p/multiaddress,
libp2p/peerid, libp2p/peerid,
dnsdisc/client dnsdisc/client
import ./waku_core import ../waku_core
export client export client

View File

@ -12,7 +12,7 @@ import
libp2p/builders, libp2p/builders,
libp2p/nameresolving/nameresolver, libp2p/nameresolving/nameresolver,
libp2p/transports/wstransport libp2p/transports/wstransport
import ../waku_enr, ../waku_discv5, ../waku_node, ../node/peer_manager import ../waku_enr, ../discovery/waku_discv5, ../waku_node, ../node/peer_manager
type type
WakuNodeBuilder* = object # General WakuNodeBuilder* = object # General

View File

@ -16,7 +16,7 @@ import
../waku_node, ../waku_node,
../waku_core, ../waku_core,
../waku_rln_relay, ../waku_rln_relay,
../waku_dnsdisc, ../discovery/waku_dnsdisc,
../waku_archive, ../waku_archive,
../waku_store, ../waku_store,
../waku_filter_v2, ../waku_filter_v2,

View File

@ -41,11 +41,11 @@ import
../waku_lightpush/common, ../waku_lightpush/common,
../waku_lightpush/protocol, ../waku_lightpush/protocol,
../waku_enr, ../waku_enr,
../waku_dnsdisc,
../waku_peer_exchange, ../waku_peer_exchange,
../waku_rln_relay, ../waku_rln_relay,
./config, ./config,
./peer_manager, ./peer_manager,
../discovery/waku_dnsdisc,
../common/ratelimit ../common/ratelimit
declarePublicCounter waku_node_messages, "number of messages received", ["type"] declarePublicCounter waku_node_messages, "number of messages received", ["type"]
@ -446,8 +446,7 @@ proc filterHandleMessage*(
node: WakuNode, pubsubTopic: PubsubTopic, message: WakuMessage node: WakuNode, pubsubTopic: PubsubTopic, message: WakuMessage
) {.async.} = ) {.async.} =
if node.wakuFilter.isNil(): if node.wakuFilter.isNil():
error "cannot handle filter message", error "cannot handle filter message", error = "waku filter is required"
error = "waku filter is required"
return return
await node.wakuFilter.handleMessage(pubsubTopic, message) await node.wakuFilter.handleMessage(pubsubTopic, message)
@ -546,7 +545,7 @@ proc filterSubscribe*(
proc filterUnsubscribe*( proc filterUnsubscribe*(
node: WakuNode, node: WakuNode,
pubsubTopic: Option[PubsubTopic], pubsubTopic: Option[PubsubTopic],
contentTopics: ContentTopic|seq[ContentTopic], contentTopics: ContentTopic | seq[ContentTopic],
peer: RemotePeerInfo | string, peer: RemotePeerInfo | string,
): Future[FilterSubscribeResult] {.async, gcsafe, raises: [Defect, ValueError].} = ): Future[FilterSubscribeResult] {.async, gcsafe, raises: [Defect, ValueError].} =
## Unsubscribe from a content filter V2". ## Unsubscribe from a content filter V2".

View File

@ -4,7 +4,7 @@ else:
{.push raises: [].} {.push raises: [].}
import chronos, chronicles, std/[options, sequtils], stew/results import chronos, chronicles, std/[options, sequtils], stew/results
import ../waku_discv5, ../waku_relay, ../waku_core, ./message_cache import ../discovery/waku_discv5, ../waku_relay, ../waku_core, ./message_cache
### Discovery ### Discovery

View File

@ -11,7 +11,7 @@ import
../common/nimchronos, ../common/nimchronos,
../node/peer_manager, ../node/peer_manager,
../waku_core, ../waku_core,
../waku_discv5, ../discovery/waku_discv5,
./rpc, ./rpc,
./rpc_codec ./rpc_codec