mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-04 19:14:47 +00:00
a8dbf8a7b6
* Upgrade all submodules * Use stock standard_setup and remove our version Switch no longer relies on Pubsub argument * Fix peerId * Add reference to WakuRelay in WakuNode * Use WakuRelay ref directly instead of via switch * Tweak standard switch sig * Fix start_network peerid * Import nim-libp2p utils test * Use WakuRelay in test utils * Fix utils imports * Tweak * Fix trigger self test * Disable broken filter test * Fix and amend logscope topics * Make subscribe calls async to use await * Add debug stuff to nimble file * Await for subscribe content * Sleeping in tests * Local checkout fixes * XXX: Try to use .PubSub on WakuRelay * Revert "XXX: Try to use .PubSub on WakuRelay" This reverts commit 3a3139e4cfbb5ae9500fd30b2e79c676ccc4a53b. * Only using gossip seems to work Subscribe for floodsub broken * Fix await in examples * Get rid of double publish, still need sleep
77 lines
2.5 KiB
Nim
77 lines
2.5 KiB
Nim
# compile time options here
|
|
const
|
|
libp2p_pubsub_sign {.booldefine.} = true
|
|
libp2p_pubsub_verify {.booldefine.} = true
|
|
|
|
import random
|
|
import chronos
|
|
import libp2p/[standard_setup,
|
|
protocols/pubsub/pubsub,
|
|
protocols/pubsub/floodsub,
|
|
protocols/pubsub/gossipsub,
|
|
protocols/secure/secure]
|
|
import ../../waku/protocol/v2/waku_relay,
|
|
../../waku/node/v2/waku_types
|
|
|
|
export standard_setup
|
|
|
|
randomize()
|
|
|
|
proc generateNodes*(
|
|
num: Natural,
|
|
secureManagers: openarray[SecureProtocol] = [
|
|
# array cos order matters
|
|
SecureProtocol.Secio,
|
|
SecureProtocol.Noise,
|
|
],
|
|
msgIdProvider: MsgIdProvider = nil,
|
|
gossip: bool = false,
|
|
triggerSelf: bool = false,
|
|
verifySignature: bool = libp2p_pubsub_verify,
|
|
sign: bool = libp2p_pubsub_sign): seq[PubSub] =
|
|
|
|
for i in 0..<num:
|
|
let switch = newStandardSwitch(secureManagers = secureManagers)
|
|
let wakuRelay = WakuRelay.init(
|
|
switch = switch,
|
|
triggerSelf = triggerSelf,
|
|
verifySignature = verifySignature,
|
|
sign = sign,
|
|
# XXX unclear why including this causes a compiler error, it is part of WakuRelay type
|
|
#gossipEnabled = gossip,
|
|
msgIdProvider = msgIdProvider).PubSub
|
|
|
|
switch.mount(wakuRelay)
|
|
result.add(wakuRelay)
|
|
|
|
proc subscribeNodes*(nodes: seq[PubSub]) {.async.} =
|
|
for dialer in nodes:
|
|
for node in nodes:
|
|
if dialer.switch.peerInfo.peerId != node.switch.peerInfo.peerId:
|
|
await dialer.switch.connect(node.peerInfo.peerId, node.peerInfo.addrs)
|
|
dialer.subscribePeer(node.peerInfo.peerId)
|
|
|
|
proc subscribeSparseNodes*(nodes: seq[PubSub], degree: int = 2) {.async.} =
|
|
if nodes.len < degree:
|
|
raise (ref CatchableError)(msg: "nodes count needs to be greater or equal to degree!")
|
|
|
|
for i, dialer in nodes:
|
|
if (i mod degree) != 0:
|
|
continue
|
|
|
|
for node in nodes:
|
|
if dialer.switch.peerInfo.peerId != node.peerInfo.peerId:
|
|
await dialer.switch.connect(node.peerInfo.peerId, node.peerInfo.addrs)
|
|
dialer.subscribePeer(node.peerInfo.peerId)
|
|
|
|
proc subscribeRandom*(nodes: seq[PubSub]) {.async.} =
|
|
for dialer in nodes:
|
|
var dialed: seq[PeerID]
|
|
while dialed.len < nodes.len - 1:
|
|
let node = sample(nodes)
|
|
if node.peerInfo.peerId notin dialed:
|
|
if dialer.peerInfo.peerId != node.peerInfo.peerId:
|
|
await dialer.switch.connect(node.peerInfo.peerId, node.peerInfo.addrs)
|
|
dialer.subscribePeer(node.peerInfo.peerId)
|
|
dialed.add(node.peerInfo.peerId)
|