Skip to content

Commit

Permalink
Start moving discovery modules to waku/node/discovery_manager/
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansete-status committed Apr 15, 2024
1 parent 480a62f commit 1772a62
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 33 deletions.
10 changes: 5 additions & 5 deletions apps/networkmonitor/networkmonitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import
../../waku/node/peer_manager,
../../waku/waku_node,
../../waku/waku_enr,
../../waku/waku_discv5,
../../waku/waku_dnsdisc,
../../waku/node/discovery_manager/waku_discv5,
../../waku/node/discovery_manager/waku_dnsdisc,
../../waku/waku_relay,
../../waku/waku_rln_relay,
../../waku/factory/builder,
Expand Down Expand Up @@ -131,12 +131,12 @@ proc setConnectedPeersMetrics(
var analyzeFuts: seq[Future[Result[string, string]]]

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)

if outConns.len >= toInt(MaxConnectedPeers/2):
for p in outConns[0 ..< toInt(outConns.len/2)]:
if outConns.len >= toInt(MaxConnectedPeers / 2):
for p in outConns[0 ..< toInt(outConns.len / 2)]:
trace "Pruning Peer", Peer = $p
asyncSpawn(node.switch.disconnect(p))

Expand Down
8 changes: 3 additions & 5 deletions apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import
../../waku/waku_api/rest/health/handlers as rest_health_api,
../../waku/waku_api/rest/admin/handlers as rest_admin_api,
../../waku/waku_archive,
../../waku/waku_dnsdisc,
../../waku/node/discovery_manager/waku_dnsdisc,
../../waku/node/discovery_manager/waku_discv5,
../../waku/waku_enr/sharding,
../../waku/waku_discv5,
../../waku/waku_peer_exchange,
../../waku/waku_rln_relay,
../../waku/waku_store,
Expand Down Expand Up @@ -366,9 +366,7 @@ proc startRestServer(
"/relay endpoints are not available. Please check your configuration: --relay"

## Filter REST API
if conf.filternode != "" and
app.node.wakuFilterClient != nil:

if conf.filternode != "" and app.node.wakuFilterClient != nil:
let filterCache = MessageCache.init()

let filterDiscoHandler =
Expand Down
2 changes: 1 addition & 1 deletion tests/node/test_wakunode_peer_exchange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import
import
../../../waku/[
waku_node,
waku_discv5,
node/discovery_manager/waku_discv5,
waku_peer_exchange,
node/peer_manager,
waku_relay/protocol,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_waku_dnsdisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import
import
../../waku/node/peer_manager,
../../waku/waku_node,
../../waku/waku_dnsdisc,
../../waku/node/discovery_manager/waku_dnsdisc,
./testlib/common,
./testlib/wakucore,
./testlib/wakunode
Expand Down
2 changes: 1 addition & 1 deletion tests/testlib/wakunode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import
../../../waku/waku_node,
../../../waku/node/peer_manager,
../../../waku/waku_enr,
../../../waku/waku_discv5,
../../../waku/node/discovery_manager/waku_discv5,
../../../waku/factory/external_config,
../../../waku/factory/internal_config,
../../../waku/factory/builder,
Expand Down
2 changes: 1 addition & 1 deletion tests/waku_peer_exchange/test_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import
../../../waku/[
waku_node,
node/peer_manager,
waku_discv5,
node/discovery_manager/waku_discv5,
waku_peer_exchange,
waku_peer_exchange/rpc,
waku_peer_exchange/rpc_codec,
Expand Down
13 changes: 6 additions & 7 deletions tests/waku_peer_exchange/test_rpc_codec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import
eth/p2p/discoveryv5/enr

import
../../../waku/
[
node/peer_manager,
waku_discv5,
waku_peer_exchange/rpc,
waku_peer_exchange/rpc_codec,
],
../../../waku/[
node/peer_manager,
node/discovery_manager/waku_discv5,
waku_peer_exchange/rpc,
waku_peer_exchange/rpc_codec,
],
../testlib/[wakucore]

suite "Peer Exchange RPC":
Expand Down
2 changes: 1 addition & 1 deletion tests/waku_peer_exchange/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import
import
../../../waku/[
waku_node,
waku_discv5,
node/discovery_manager/waku_discv5,
waku_peer_exchange,
waku_peer_exchange/rpc,
waku_peer_exchange/protocol,
Expand Down
3 changes: 2 additions & 1 deletion waku/factory/builder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import
libp2p/builders,
libp2p/nameresolving/nameresolver,
libp2p/transports/wstransport
import ../waku_enr, ../waku_discv5, ../waku_node, ../node/peer_manager
import
../waku_enr, ../node/discovery_manager/waku_discv5, ../waku_node, ../node/peer_manager

type
WakuNodeBuilder* = object # General
Expand Down
2 changes: 1 addition & 1 deletion waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import
../waku_node,
../waku_core,
../waku_rln_relay,
../waku_dnsdisc,
../node/discovery_manager/waku_dnsdisc,
../waku_archive,
../waku_store,
../waku_filter_v2,
Expand Down
37 changes: 37 additions & 0 deletions waku/node/discovery_manager/discovery_manager.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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:
WakuNode* = ref object
peerManager*: PeerManager
discManager*: DiscoveryManager <-- we will add this
...
App* = object
version: string
conf: WakuNodeConf
rng: ref HmacDrbgContext
key: crypto.PrivateKey
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]
]#
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import
eth/keys as eth_keys,
eth/p2p/discoveryv5/node,
eth/p2p/discoveryv5/protocol
import ./node/peer_manager/peer_manager, ./waku_core, ./waku_enr
import ../peer_manager/peer_manager, ../../waku_core, ../../waku_enr

export protocol, waku_enr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import
libp2p/multiaddress,
libp2p/peerid,
dnsdisc/client
import ./waku_core
import ../../waku_core

export client

Expand Down
9 changes: 4 additions & 5 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import
../waku_lightpush/common,
../waku_lightpush/protocol,
../waku_enr,
../waku_dnsdisc,
../waku_peer_exchange,
../waku_rln_relay,
./config,
./peer_manager
./peer_manager,
./discovery_manager/waku_dnsdisc

declarePublicCounter waku_node_messages, "number of messages received", ["type"]
declarePublicHistogram waku_histogram_message_size,
Expand Down Expand Up @@ -445,8 +445,7 @@ proc filterHandleMessage*(
node: WakuNode, pubsubTopic: PubsubTopic, message: WakuMessage
) {.async.} =
if node.wakuFilter.isNil():
error "cannot handle filter message",
error = "waku filter is required"
error "cannot handle filter message", error = "waku filter is required"
return

await node.wakuFilter.handleMessage(pubsubTopic, message)
Expand Down Expand Up @@ -545,7 +544,7 @@ proc filterSubscribe*(
proc filterUnsubscribe*(
node: WakuNode,
pubsubTopic: Option[PubsubTopic],
contentTopics: ContentTopic|seq[ContentTopic],
contentTopics: ContentTopic | seq[ContentTopic],
peer: RemotePeerInfo | string,
): Future[FilterSubscribeResult] {.async, gcsafe, raises: [Defect, ValueError].} =
## Unsubscribe from a content filter V2".
Expand Down
3 changes: 2 additions & 1 deletion waku/waku_api/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ else:
{.push raises: [].}

import chronos, chronicles, std/[options, sequtils], stew/results
import ../waku_discv5, ../waku_relay, ../waku_core, ./message_cache
import
../node/discovery_manager/waku_discv5, ../waku_relay, ../waku_core, ./message_cache

### Discovery

Expand Down
2 changes: 1 addition & 1 deletion waku/waku_peer_exchange/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import
../common/nimchronos,
../node/peer_manager,
../waku_core,
../waku_discv5,
../node/discovery_manager/waku_discv5,
./rpc,
./rpc_codec

Expand Down

0 comments on commit 1772a62

Please sign in to comment.