From 6135127e5d108ba25097967c3a35c7ae0feb44f9 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Wed, 21 Jul 2021 15:02:38 +1000 Subject: [PATCH 1/3] Correct name --- src/lib/waku_relay/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/waku_relay/constants.ts b/src/lib/waku_relay/constants.ts index 3733f9b9c7..2b1dd9f221 100644 --- a/src/lib/waku_relay/constants.ts +++ b/src/lib/waku_relay/constants.ts @@ -7,7 +7,7 @@ export const minute = 60 * second; export const RelayCodec = '/vac/waku/relay/2.0.0-beta2'; /** - * RelayDefaultTopic is the default gossipsub topic to use for waku relay + * DefaultPubsubTopic is the default gossipsub topic to use for Waku. */ export const DefaultPubsubTopic = '/waku/2/default-waku/proto'; From 92a76b3be0047345909aebf74a8d7669c8274397 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Wed, 21 Jul 2021 15:15:11 +1000 Subject: [PATCH 2/3] Support multiple protocol id for relay Support id of latest nim-waku release 0.4 and current master. --- CHANGELOG.md | 3 +++ src/index.ts | 2 +- src/lib/waku.spec.ts | 3 +-- src/lib/waku.ts | 4 ++-- src/lib/waku_relay/constants.ts | 5 ++++- src/lib/waku_relay/get_relay_peers.ts | 4 ++-- src/lib/waku_relay/index.spec.ts | 4 ++-- src/lib/waku_relay/index.ts | 8 ++++---- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce3503ad6..eff8bc3518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Examples (web-chat): New `/fleet` command to switch connection between Status prod and test fleets. - Export `generatePrivateKey` and `getPublicKey` directly from the root. - Usage of the encryption and signature APIs to the readme. +- Support multiple protocol ids for Waku Relay, allowing interoperability with nim-waku v0.4 and latest master + ([#238](https://github.com/status-im/js-waku/issues/238)). ### Changed - **Breaking**: Renamed `WakuRelay.(add|delete)PrivateDecryptionKey` to `WakuRelay.(add|delete)DecryptionKey` to make it clearer that it accepts both symmetric keys and asymmetric private keys. ### Fix - Align `WakuMessage` readme example with actual code behaviour. +- Remove infinite loop when an error with Waku Store is encountered. ## [0.8.0] - 2021-07-15 diff --git a/src/index.ts b/src/index.ts index 0220140537..c318754cea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ export { PushResponse, } from './lib/waku_light_push'; -export { WakuRelay, RelayCodec } from './lib/waku_relay'; +export { WakuRelay, RelayCodecs } from './lib/waku_relay'; export { Direction, WakuStore, StoreCodec } from './lib/waku_store'; diff --git a/src/lib/waku.spec.ts b/src/lib/waku.spec.ts index 287b44b380..fd6d15fe9a 100644 --- a/src/lib/waku.spec.ts +++ b/src/lib/waku.spec.ts @@ -6,7 +6,6 @@ import TCP from 'libp2p-tcp'; import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../test_utils/'; import { Waku } from './waku'; -import { RelayCodec } from './waku_relay'; describe('Waku Dial', function () { describe('Interop: Nim', function () { @@ -30,7 +29,7 @@ describe('Waku Dial', function () { expect(nimPeers).to.deep.equal([ { multiaddr: multiAddrWithId, - protocol: RelayCodec, + protocol: '/vac/waku/relay/2.0.0-beta2', connected: true, }, ]); diff --git a/src/lib/waku.ts b/src/lib/waku.ts index 45c520c2ba..ea2f93f23b 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -16,7 +16,7 @@ import { Multiaddr, multiaddr } from 'multiaddr'; import PeerId from 'peer-id'; import { WakuLightPush } from './waku_light_push'; -import { RelayCodec, WakuRelay } from './waku_relay'; +import { RelayCodecs, WakuRelay } from './waku_relay'; import { StoreCodec, WakuStore } from './waku_store'; const websocketsTransportKey = Websockets.prototype[Symbol.toStringTag]; @@ -170,7 +170,7 @@ export class Waku { stream: MuxedStream; protocol: string; }> { - return this.libp2p.dialProtocol(peer, [RelayCodec, StoreCodec]); + return this.libp2p.dialProtocol(peer, [StoreCodec].concat(RelayCodecs)); } /** diff --git a/src/lib/waku_relay/constants.ts b/src/lib/waku_relay/constants.ts index 2b1dd9f221..b4b17fe4ea 100644 --- a/src/lib/waku_relay/constants.ts +++ b/src/lib/waku_relay/constants.ts @@ -4,7 +4,10 @@ export const minute = 60 * second; /** * RelayCodec is the libp2p identifier for the waku relay protocol */ -export const RelayCodec = '/vac/waku/relay/2.0.0-beta2'; +export const RelayCodecs = [ + '/vac/waku/relay/2.0.0-beta2', + '/vac/waku/relay/2.0.0', +]; /** * DefaultPubsubTopic is the default gossipsub topic to use for Waku. diff --git a/src/lib/waku_relay/get_relay_peers.ts b/src/lib/waku_relay/get_relay_peers.ts index 5f5922ad22..f4fd10fefb 100644 --- a/src/lib/waku_relay/get_relay_peers.ts +++ b/src/lib/waku_relay/get_relay_peers.ts @@ -1,7 +1,7 @@ import Gossipsub from 'libp2p-gossipsub'; import { shuffle } from 'libp2p-gossipsub/src/utils'; -import { RelayCodec } from './index'; +import { RelayCodecs } from './index'; /** * Given a topic, returns up to count peers subscribed to that topic @@ -33,7 +33,7 @@ export function getRelayPeers( if (!peerStreams) { return; } - if (peerStreams.protocol == RelayCodec && filter(id)) { + if (RelayCodecs.includes(peerStreams.protocol) && filter(id)) { peers.push(id); } }); diff --git a/src/lib/waku_relay/index.spec.ts b/src/lib/waku_relay/index.spec.ts index 7342221cf6..078d644a47 100644 --- a/src/lib/waku_relay/index.spec.ts +++ b/src/lib/waku_relay/index.spec.ts @@ -14,7 +14,7 @@ import { delay } from '../delay'; import { Waku } from '../waku'; import { WakuMessage } from '../waku_message'; -import { DefaultPubsubTopic, RelayCodec } from './index'; +import { DefaultPubsubTopic } from './index'; const log = debug('waku:test'); @@ -72,7 +72,7 @@ describe('Waku Relay', () => { it('Register correct protocols', async function () { const protocols = Array.from(waku1.libp2p.upgrader.protocols.keys()); - expect(protocols).to.contain(RelayCodec); + expect(protocols).to.contain('/vac/waku/relay/2.0.0-beta2'); expect(protocols.findIndex((value) => value.match(/sub/))).to.eq(-1); }); diff --git a/src/lib/waku_relay/index.ts b/src/lib/waku_relay/index.ts index d14703ec9b..d0e1882939 100644 --- a/src/lib/waku_relay/index.ts +++ b/src/lib/waku_relay/index.ts @@ -21,13 +21,13 @@ import { CreateOptions } from '../waku'; import { WakuMessage } from '../waku_message'; import * as constants from './constants'; -import { DefaultPubsubTopic, RelayCodec } from './constants'; +import { DefaultPubsubTopic, RelayCodecs } from './constants'; import { getRelayPeers } from './get_relay_peers'; import { RelayHeartbeat } from './relay_heartbeat'; const dbg = debug('waku:relay'); -export { RelayCodec, DefaultPubsubTopic }; +export { RelayCodecs, DefaultPubsubTopic }; /** * See constructor libp2p-gossipsub [API](https://github.com/ChainSafe/js-libp2p-gossipsub#api). @@ -93,7 +93,7 @@ export class WakuRelay extends Gossipsub { this.observers = {}; this.decryptionKeys = new Set(); - const multicodecs = [constants.RelayCodec]; + const multicodecs = constants.RelayCodecs; Object.assign(this, { multicodecs }); @@ -420,7 +420,7 @@ export class WakuRelay extends Gossipsub { if ( !exclude.has(id) && !this.direct.has(id) && - peerStreams.protocol == constants.RelayCodec && + constants.RelayCodecs.includes(peerStreams.protocol) && this.score.score(id) >= this._options.scoreThresholds.gossipThreshold ) { peersToGossip.push(id); From be007f483990dc930be1e82baa99163d47702984 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Wed, 21 Jul 2021 15:33:58 +1000 Subject: [PATCH 3/3] Ensure there is no infinite loop on error --- CHANGELOG.md | 2 +- src/lib/waku_store/index.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eff8bc3518..d72a9b387e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - **Breaking**: Renamed `WakuRelay.(add|delete)PrivateDecryptionKey` to `WakuRelay.(add|delete)DecryptionKey` to make it clearer that it accepts both symmetric keys and asymmetric private keys. -### Fix +### Fixed - Align `WakuMessage` readme example with actual code behaviour. - Remove infinite loop when an error with Waku Store is encountered. diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index 0d757daab9..83a3966f5c 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -168,15 +168,18 @@ export class WakuStore { } } catch (err) { console.log('Failed to decode store reply', err); + return null; } } catch (err) { console.log('Failed to send waku store query', err); + return null; } } catch (err) { console.log( 'Failed to negotiate waku store protocol stream with peer', err ); + return null; } } }