diff --git a/CHANGELOG.md b/CHANGELOG.md index 8709dfc5e..c4abc7f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This release contains the following: ### Changes - Enables db migration for the message store. - The `resume` Nim API eliminates duplicates messages before storing them. +- Support for stable version of `relay` protocol, with protocol ID `/vac/waku/relay/2.0.0` #### General refactoring #### Docs diff --git a/tests/v2/test_wakunode.nim b/tests/v2/test_wakunode.nim index 0dad6cdca..841bfc280 100644 --- a/tests/v2/test_wakunode.nim +++ b/tests/v2/test_wakunode.nim @@ -387,6 +387,62 @@ procSuite "WakuNode": await node1.stop() await node2.stop() await node3.stop() + + asyncTest "Protocol matcher works as expected": + let + nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[] + node1 = WakuNode.init(nodeKey1, ValidIpAddress.init("0.0.0.0"), + Port(60000)) + nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[] + node2 = WakuNode.init(nodeKey2, ValidIpAddress.init("0.0.0.0"), + Port(60002)) + pubSubTopic = "/waku/2/default-waku/proto" + contentTopic = ContentTopic("/waku/2/default-content/proto") + payload = "hello world".toBytes() + message = WakuMessage(payload: payload, contentTopic: contentTopic) + + # Setup node 1 with stable codec "/vac/waku/relay/2.0.0" + + await node1.start() + node1.mountRelay(@[pubSubTopic]) + node1.wakuRelay.codec = "/vac/waku/relay/2.0.0" + + # Setup node 2 with beta codec "/vac/waku/relay/2.0.0-beta2" + + await node2.start() + node2.mountRelay(@[pubSubTopic]) + node2.wakuRelay.codec = "/vac/waku/relay/2.0.0-beta2" + + check: + # Check that mounted codecs are actually different + node1.wakuRelay.codec == "/vac/waku/relay/2.0.0" + node2.wakuRelay.codec == "/vac/waku/relay/2.0.0-beta2" + + # Now verify that protocol matcher returns `true` and relay works + + await node1.connectToNodes(@[node2.peerInfo]) + + var completionFut = newFuture[bool]() + proc relayHandler(topic: string, data: seq[byte]) {.async, gcsafe.} = + let msg = WakuMessage.init(data) + if msg.isOk(): + let val = msg.value() + check: + topic == pubSubTopic + val.contentTopic == contentTopic + val.payload == payload + completionFut.complete(true) + + node2.subscribe(pubSubTopic, relayHandler) + await sleepAsync(2000.millis) + + await node1.publish(pubSubTopic, message) + await sleepAsync(2000.millis) + + check: + (await completionFut.withTimeout(5.seconds)) == true + await node1.stop() + await node2.stop() asyncTest "Peer info parses correctly": ## This is such an important utility function for wakunode2 diff --git a/waku/v2/node/wakunode2.nim b/waku/v2/node/wakunode2.nim index 484c5df57..9f6f198d6 100644 --- a/waku/v2/node/wakunode2.nim +++ b/waku/v2/node/wakunode2.nim @@ -480,7 +480,13 @@ proc mountRelay*(node: WakuNode, info "mounting relay", rlnRelayEnabled=rlnRelayEnabled, relayMessages=relayMessages - node.switch.mount(wakuRelay) + proc relayMatch(proto: string): bool {.gcsafe.} = + ## Matches the WakuRelayCodec with any postfix. + ## E.g. if WakuRelayCodec is `/vac/waku/relay/2.0.0` it matches: + ## `/vac/waku/relay/2.0.0`, `/vac/waku/relay/2.0.0-beta2`, `/vac/waku/relay/2.0.0-actualnonsense` + return proto.startsWith(WakuRelayCodec) + + node.switch.mount(wakuRelay, relayMatch) if not relayMessages: ## Some nodes may choose not to have the capability to relay messages (e.g. "light" nodes). diff --git a/waku/v2/protocol/waku_relay.nim b/waku/v2/protocol/waku_relay.nim index 0057150f0..be227714c 100644 --- a/waku/v2/protocol/waku_relay.nim +++ b/waku/v2/protocol/waku_relay.nim @@ -15,7 +15,7 @@ logScope: topics = "wakurelay" const - WakuRelayCodec* = "/vac/waku/relay/2.0.0-beta2" + WakuRelayCodec* = "/vac/waku/relay/2.0.0" type WakuRelay* = ref object of GossipSub