mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-13 15:36:58 +00:00
feat(wakunode2): enable libp2p rendezvous protocol by default (#1770)
This commit is contained in:
parent
7df6f4c851
commit
835a409d10
@ -526,6 +526,12 @@ proc setupProtocols(node: WakuNode, conf: WakuNodeConf,
|
|||||||
notice "routing only signed traffic", protectedTopic=topicKey.topic, publicKey=topicKey.key
|
notice "routing only signed traffic", protectedTopic=topicKey.topic, publicKey=topicKey.key
|
||||||
node.wakuRelay.addSignedTopicValidator(Pubsubtopic(topicKey.topic), topicKey.key)
|
node.wakuRelay.addSignedTopicValidator(Pubsubtopic(topicKey.topic), topicKey.key)
|
||||||
|
|
||||||
|
# Enable Rendezvous Discovery protocol when Relay is enabled
|
||||||
|
try:
|
||||||
|
await mountRendezvous(node)
|
||||||
|
except CatchableError:
|
||||||
|
return err("failed to mount waku rendezvous protocol: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
# Keepalive mounted on all nodes
|
# Keepalive mounted on all nodes
|
||||||
try:
|
try:
|
||||||
await mountLibp2pPing(node)
|
await mountLibp2pPing(node)
|
||||||
|
@ -66,6 +66,7 @@ import
|
|||||||
./v2/test_waku_noise,
|
./v2/test_waku_noise,
|
||||||
./v2/test_waku_noise_sessions,
|
./v2/test_waku_noise_sessions,
|
||||||
./v2/test_waku_switch,
|
./v2/test_waku_switch,
|
||||||
|
./v2/test_waku_rendezvous,
|
||||||
# Utils
|
# Utils
|
||||||
./v2/test_utils_compat
|
./v2/test_utils_compat
|
||||||
|
|
||||||
|
59
tests/v2/test_waku_rendezvous.nim
Normal file
59
tests/v2/test_waku_rendezvous.nim
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
{.used.}
|
||||||
|
|
||||||
|
import
|
||||||
|
chronos,
|
||||||
|
testutils/unittests,
|
||||||
|
libp2p,
|
||||||
|
libp2p/protocols/rendezvous
|
||||||
|
|
||||||
|
import
|
||||||
|
../../waku/v2/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()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
await allFutures(wakuSwitch.stop(), sourceSwitch.stop(), destSwitch.stop())
|
||||||
|
|
||||||
|
|
@ -67,6 +67,7 @@ proc newTestWakuNode*(nodeKey: crypto.PrivateKey,
|
|||||||
secureKey = if secureKey != "": some(secureKey) else: none(string),
|
secureKey = if secureKey != "": some(secureKey) else: none(string),
|
||||||
secureCert = if secureCert != "": some(secureCert) else: none(string),
|
secureCert = if secureCert != "": some(secureCert) else: none(string),
|
||||||
agentString = agentString,
|
agentString = agentString,
|
||||||
|
|
||||||
)
|
)
|
||||||
builder.withWakuDiscv5(wakuDiscv5.get(nil))
|
builder.withWakuDiscv5(wakuDiscv5.get(nil))
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ proc defaultTestWakuNodeConf(): WakuNodeConf =
|
|||||||
metricsServerAddress: ValidIpAddress.init("127.0.0.1"),
|
metricsServerAddress: ValidIpAddress.init("127.0.0.1"),
|
||||||
nat: "any",
|
nat: "any",
|
||||||
maxConnections: 50,
|
maxConnections: 50,
|
||||||
|
topics: @["/waku/2/default-waku/proto"],
|
||||||
|
relay: true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -77,6 +79,7 @@ suite "Wakunode2 - App initialization":
|
|||||||
node.wakuArchive.isNil()
|
node.wakuArchive.isNil()
|
||||||
node.wakuStore.isNil()
|
node.wakuStore.isNil()
|
||||||
not node.wakuStoreClient.isNil()
|
not node.wakuStoreClient.isNil()
|
||||||
|
not node.rendezvous.isNil()
|
||||||
|
|
||||||
## Cleanup
|
## Cleanup
|
||||||
waitFor wakunode2.stop()
|
waitFor wakunode2.stop()
|
||||||
|
@ -19,6 +19,7 @@ import
|
|||||||
libp2p/protocols/pubsub/rpc/messages,
|
libp2p/protocols/pubsub/rpc/messages,
|
||||||
libp2p/protocols/connectivity/autonat/client,
|
libp2p/protocols/connectivity/autonat/client,
|
||||||
libp2p/protocols/connectivity/autonat/service,
|
libp2p/protocols/connectivity/autonat/service,
|
||||||
|
libp2p/protocols/rendezvous,
|
||||||
libp2p/nameresolving/nameresolver,
|
libp2p/nameresolving/nameresolver,
|
||||||
libp2p/builders,
|
libp2p/builders,
|
||||||
libp2p/transports/tcptransport,
|
libp2p/transports/tcptransport,
|
||||||
@ -101,6 +102,7 @@ type
|
|||||||
libp2pPing*: Ping
|
libp2pPing*: Ping
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: ref rand.HmacDrbgContext
|
||||||
wakuDiscv5*: WakuDiscoveryV5
|
wakuDiscv5*: WakuDiscoveryV5
|
||||||
|
rendezvous*: RendezVous
|
||||||
announcedAddresses* : seq[MultiAddress]
|
announcedAddresses* : seq[MultiAddress]
|
||||||
started*: bool # Indicates that node has started listening
|
started*: bool # Indicates that node has started listening
|
||||||
|
|
||||||
@ -921,6 +923,16 @@ proc stopDiscv5*(node: WakuNode): Future[bool] {.async.} =
|
|||||||
|
|
||||||
debug "Successfully stopped discovery v5 service"
|
debug "Successfully stopped discovery v5 service"
|
||||||
|
|
||||||
|
proc mountRendezvous*(node: WakuNode) {.async, raises: [Defect, LPError].} =
|
||||||
|
info "mounting rendezvous discovery protocol"
|
||||||
|
|
||||||
|
node.rendezvous = RendezVous.new(node.switch)
|
||||||
|
|
||||||
|
if node.started:
|
||||||
|
await node.rendezvous.start()
|
||||||
|
|
||||||
|
node.switch.mount(node.rendezvous)
|
||||||
|
|
||||||
|
|
||||||
proc start*(node: WakuNode) {.async.} =
|
proc start*(node: WakuNode) {.async.} =
|
||||||
## Starts a created Waku Node and
|
## Starts a created Waku Node and
|
||||||
|
@ -10,6 +10,7 @@ import
|
|||||||
eth/keys,
|
eth/keys,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/pubsub/gossipsub,
|
libp2p/protocols/pubsub/gossipsub,
|
||||||
|
libp2p/protocols/rendezvous,
|
||||||
libp2p/nameresolving/nameresolver,
|
libp2p/nameresolving/nameresolver,
|
||||||
libp2p/builders,
|
libp2p/builders,
|
||||||
libp2p/switch,
|
libp2p/switch,
|
||||||
@ -78,6 +79,7 @@ proc newWakuSwitch*(
|
|||||||
agentString = none(string), # defaults to nim-libp2p version
|
agentString = none(string), # defaults to nim-libp2p version
|
||||||
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
|
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
|
||||||
services: seq[switch.Service] = @[],
|
services: seq[switch.Service] = @[],
|
||||||
|
rendezvous: RendezVous = nil,
|
||||||
): Switch
|
): Switch
|
||||||
{.raises: [Defect, IOError, LPError].} =
|
{.raises: [Defect, IOError, LPError].} =
|
||||||
|
|
||||||
@ -119,4 +121,7 @@ proc newWakuSwitch*(
|
|||||||
if services.len > 0:
|
if services.len > 0:
|
||||||
b = b.withServices(services)
|
b = b.withServices(services)
|
||||||
|
|
||||||
|
if not rendezvous.isNil():
|
||||||
|
b = b.withRendezVous(rendezvous)
|
||||||
|
|
||||||
b.build()
|
b.build()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user