2023-06-01 19:43:10 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-11-10 08:27:04 +00:00
|
|
|
import chronos, testutils/unittests, libp2p/builders, libp2p/protocols/rendezvous
|
2023-06-01 19:43:10 +00:00
|
|
|
|
2024-07-05 22:03:38 +00:00
|
|
|
import waku/node/waku_switch, ./testlib/common, ./testlib/wakucore
|
2023-06-01 19:43:10 +00:00
|
|
|
|
|
|
|
proc newRendezvousClientSwitch(rdv: RendezVous): Switch =
|
2024-03-15 23:08:47 +00:00
|
|
|
SwitchBuilder
|
|
|
|
.new()
|
|
|
|
.withRng(rng())
|
|
|
|
.withAddresses(@[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()])
|
|
|
|
.withTcpTransport()
|
|
|
|
.withMplex()
|
|
|
|
.withNoise()
|
|
|
|
.withRendezVous(rdv)
|
|
|
|
.build()
|
2023-06-01 19:43:10 +00:00
|
|
|
|
|
|
|
procSuite "Waku Rendezvous":
|
|
|
|
asyncTest "Waku Switch uses Rendezvous":
|
|
|
|
## Setup
|
|
|
|
|
|
|
|
let
|
|
|
|
wakuClient = RendezVous.new()
|
|
|
|
sourceClient = RendezVous.new()
|
|
|
|
destClient = RendezVous.new()
|
|
|
|
wakuSwitch = newRendezvousClientSwitch(wakuClient) #rendezvous point
|
|
|
|
sourceSwitch = newRendezvousClientSwitch(sourceClient) #client
|
|
|
|
destSwitch = newRendezvousClientSwitch(destClient) #client
|
|
|
|
|
|
|
|
# Setup client rendezvous
|
|
|
|
wakuClient.setup(wakuSwitch)
|
|
|
|
sourceClient.setup(sourceSwitch)
|
|
|
|
destClient.setup(destSwitch)
|
|
|
|
|
|
|
|
await allFutures(wakuSwitch.start(), sourceSwitch.start(), destSwitch.start())
|
|
|
|
|
|
|
|
# Connect clients to the rendezvous point
|
|
|
|
await sourceSwitch.connect(wakuSwitch.peerInfo.peerId, wakuSwitch.peerInfo.addrs)
|
|
|
|
await destSwitch.connect(wakuSwitch.peerInfo.peerId, wakuSwitch.peerInfo.addrs)
|
|
|
|
|
|
|
|
let res0 = await sourceClient.request("empty")
|
|
|
|
check res0.len == 0
|
|
|
|
|
|
|
|
# Check that source client gets peer info of dest client from rendezvous point
|
|
|
|
await sourceClient.advertise("foo")
|
|
|
|
let res1 = await destClient.request("foo")
|
|
|
|
check:
|
|
|
|
res1.len == 1
|
|
|
|
res1[0] == sourceSwitch.peerInfo.signedPeerRecord.data
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
await allFutures(wakuSwitch.stop(), sourceSwitch.stop(), destSwitch.stop())
|