-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: waku rendezvous wrapper (#2962)
- Loading branch information
Showing
11 changed files
with
391 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,63 @@ | ||
{.used.} | ||
|
||
import chronos, testutils/unittests, libp2p/builders, libp2p/protocols/rendezvous | ||
import std/options, chronos, testutils/unittests, libp2p/builders | ||
|
||
import waku/node/waku_switch, ./testlib/common, ./testlib/wakucore | ||
|
||
proc newRendezvousClientSwitch(rdv: RendezVous): Switch = | ||
SwitchBuilder | ||
.new() | ||
.withRng(rng()) | ||
.withAddresses(@[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()]) | ||
.withTcpTransport() | ||
.withMplex() | ||
.withNoise() | ||
.withRendezVous(rdv) | ||
.build() | ||
import | ||
waku/waku_core/peers, | ||
waku/node/waku_node, | ||
waku/node/peer_manager/peer_manager, | ||
waku/waku_rendezvous/protocol, | ||
./testlib/[wakucore, wakunode] | ||
|
||
procSuite "Waku Rendezvous": | ||
asyncTest "Waku Switch uses Rendezvous": | ||
## Setup | ||
|
||
asyncTest "Simple remote test": | ||
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 | ||
clusterId = 10.uint16 | ||
node1 = newTestWakuNode( | ||
generateSecp256k1Key(), | ||
parseIpAddress("0.0.0.0"), | ||
Port(0), | ||
clusterId = clusterId, | ||
) | ||
node2 = newTestWakuNode( | ||
generateSecp256k1Key(), | ||
parseIpAddress("0.0.0.0"), | ||
Port(0), | ||
clusterId = clusterId, | ||
) | ||
node3 = newTestWakuNode( | ||
generateSecp256k1Key(), | ||
parseIpAddress("0.0.0.0"), | ||
Port(0), | ||
clusterId = clusterId, | ||
) | ||
|
||
await allFutures( | ||
[node1.mountRendezvous(), node2.mountRendezvous(), node3.mountRendezvous()] | ||
) | ||
await allFutures([node1.start(), node2.start(), node3.start()]) | ||
|
||
let peerInfo1 = node1.switch.peerInfo.toRemotePeerInfo() | ||
let peerInfo2 = node2.switch.peerInfo.toRemotePeerInfo() | ||
let peerInfo3 = node3.switch.peerInfo.toRemotePeerInfo() | ||
|
||
node1.peerManager.addPeer(peerInfo2) | ||
node2.peerManager.addPeer(peerInfo1) | ||
node2.peerManager.addPeer(peerInfo3) | ||
node3.peerManager.addPeer(peerInfo2) | ||
|
||
let namespace = "test/name/space" | ||
|
||
let res = await node1.wakuRendezvous.batchAdvertise( | ||
namespace, 60.seconds, @[peerInfo2.peerId] | ||
) | ||
assert res.isOk(), $res.error | ||
|
||
let response = | ||
await node3.wakuRendezvous.batchRequest(namespace, 1, @[peerInfo2.peerId]) | ||
assert response.isOk(), $response.error | ||
let records = response.get() | ||
|
||
await allFutures(wakuSwitch.stop(), sourceSwitch.stop(), destSwitch.stop()) | ||
check: | ||
records.len == 1 | ||
records[0].peerId == peerInfo1.peerId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ./waku_rendezvous/protocol | ||
|
||
export protocol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{.push raises: [].} | ||
|
||
import std/options, chronos | ||
|
||
import ../common/enr, ../waku_enr/capabilities, ../waku_enr/sharding | ||
|
||
const DiscoverLimit* = 1000 | ||
const DefaultRegistrationTTL* = 60.seconds | ||
const DefaultRegistrationInterval* = 10.seconds | ||
const PeersRequestedCount* = 12 | ||
|
||
proc computeNamespace*(clusterId: uint16, shard: uint16): string = | ||
var namespace = "rs/" | ||
|
||
namespace &= $clusterId | ||
namespace &= '/' | ||
namespace &= $shard | ||
|
||
return namespace | ||
|
||
proc computeNamespace*(clusterId: uint16, shard: uint16, cap: Capabilities): string = | ||
var namespace = "rs/" | ||
|
||
namespace &= $clusterId | ||
namespace &= '/' | ||
namespace &= $shard | ||
namespace &= '/' | ||
namespace &= $cap | ||
|
||
return namespace | ||
|
||
proc getRelayShards*(enr: enr.Record): Option[RelayShards] = | ||
let typedRecord = enr.toTyped().valueOr: | ||
return none(RelayShards) | ||
|
||
return typedRecord.relaySharding() |
Oops, something went wrong.