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);