Support multiple protocol id for relay

Support id of latest nim-waku release 0.4 and current master.
This commit is contained in:
Franck Royer 2021-07-21 15:15:11 +10:00
parent 6135127e5d
commit 92a76b3be0
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
8 changed files with 19 additions and 14 deletions

View File

@ -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. - Examples (web-chat): New `/fleet` command to switch connection between Status prod and test fleets.
- Export `generatePrivateKey` and `getPublicKey` directly from the root. - Export `generatePrivateKey` and `getPublicKey` directly from the root.
- Usage of the encryption and signature APIs to the readme. - 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 ### 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. - **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 ### Fix
- Align `WakuMessage` readme example with actual code behaviour. - 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 ## [0.8.0] - 2021-07-15

View File

@ -16,7 +16,7 @@ export {
PushResponse, PushResponse,
} from './lib/waku_light_push'; } 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'; export { Direction, WakuStore, StoreCodec } from './lib/waku_store';

View File

@ -6,7 +6,6 @@ import TCP from 'libp2p-tcp';
import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../test_utils/'; import { makeLogFileName, NimWaku, NOISE_KEY_1 } from '../test_utils/';
import { Waku } from './waku'; import { Waku } from './waku';
import { RelayCodec } from './waku_relay';
describe('Waku Dial', function () { describe('Waku Dial', function () {
describe('Interop: Nim', function () { describe('Interop: Nim', function () {
@ -30,7 +29,7 @@ describe('Waku Dial', function () {
expect(nimPeers).to.deep.equal([ expect(nimPeers).to.deep.equal([
{ {
multiaddr: multiAddrWithId, multiaddr: multiAddrWithId,
protocol: RelayCodec, protocol: '/vac/waku/relay/2.0.0-beta2',
connected: true, connected: true,
}, },
]); ]);

View File

@ -16,7 +16,7 @@ import { Multiaddr, multiaddr } from 'multiaddr';
import PeerId from 'peer-id'; import PeerId from 'peer-id';
import { WakuLightPush } from './waku_light_push'; import { WakuLightPush } from './waku_light_push';
import { RelayCodec, WakuRelay } from './waku_relay'; import { RelayCodecs, WakuRelay } from './waku_relay';
import { StoreCodec, WakuStore } from './waku_store'; import { StoreCodec, WakuStore } from './waku_store';
const websocketsTransportKey = Websockets.prototype[Symbol.toStringTag]; const websocketsTransportKey = Websockets.prototype[Symbol.toStringTag];
@ -170,7 +170,7 @@ export class Waku {
stream: MuxedStream; stream: MuxedStream;
protocol: string; protocol: string;
}> { }> {
return this.libp2p.dialProtocol(peer, [RelayCodec, StoreCodec]); return this.libp2p.dialProtocol(peer, [StoreCodec].concat(RelayCodecs));
} }
/** /**

View File

@ -4,7 +4,10 @@ export const minute = 60 * second;
/** /**
* RelayCodec is the libp2p identifier for the waku relay protocol * 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. * DefaultPubsubTopic is the default gossipsub topic to use for Waku.

View File

@ -1,7 +1,7 @@
import Gossipsub from 'libp2p-gossipsub'; import Gossipsub from 'libp2p-gossipsub';
import { shuffle } from 'libp2p-gossipsub/src/utils'; 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 * Given a topic, returns up to count peers subscribed to that topic
@ -33,7 +33,7 @@ export function getRelayPeers(
if (!peerStreams) { if (!peerStreams) {
return; return;
} }
if (peerStreams.protocol == RelayCodec && filter(id)) { if (RelayCodecs.includes(peerStreams.protocol) && filter(id)) {
peers.push(id); peers.push(id);
} }
}); });

View File

@ -14,7 +14,7 @@ import { delay } from '../delay';
import { Waku } from '../waku'; import { Waku } from '../waku';
import { WakuMessage } from '../waku_message'; import { WakuMessage } from '../waku_message';
import { DefaultPubsubTopic, RelayCodec } from './index'; import { DefaultPubsubTopic } from './index';
const log = debug('waku:test'); const log = debug('waku:test');
@ -72,7 +72,7 @@ describe('Waku Relay', () => {
it('Register correct protocols', async function () { it('Register correct protocols', async function () {
const protocols = Array.from(waku1.libp2p.upgrader.protocols.keys()); 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); expect(protocols.findIndex((value) => value.match(/sub/))).to.eq(-1);
}); });

View File

@ -21,13 +21,13 @@ import { CreateOptions } from '../waku';
import { WakuMessage } from '../waku_message'; import { WakuMessage } from '../waku_message';
import * as constants from './constants'; import * as constants from './constants';
import { DefaultPubsubTopic, RelayCodec } from './constants'; import { DefaultPubsubTopic, RelayCodecs } from './constants';
import { getRelayPeers } from './get_relay_peers'; import { getRelayPeers } from './get_relay_peers';
import { RelayHeartbeat } from './relay_heartbeat'; import { RelayHeartbeat } from './relay_heartbeat';
const dbg = debug('waku:relay'); const dbg = debug('waku:relay');
export { RelayCodec, DefaultPubsubTopic }; export { RelayCodecs, DefaultPubsubTopic };
/** /**
* See constructor libp2p-gossipsub [API](https://github.com/ChainSafe/js-libp2p-gossipsub#api). * 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.observers = {};
this.decryptionKeys = new Set(); this.decryptionKeys = new Set();
const multicodecs = [constants.RelayCodec]; const multicodecs = constants.RelayCodecs;
Object.assign(this, { multicodecs }); Object.assign(this, { multicodecs });
@ -420,7 +420,7 @@ export class WakuRelay extends Gossipsub {
if ( if (
!exclude.has(id) && !exclude.has(id) &&
!this.direct.has(id) && !this.direct.has(id) &&
peerStreams.protocol == constants.RelayCodec && constants.RelayCodecs.includes(peerStreams.protocol) &&
this.score.score(id) >= this._options.scoreThresholds.gossipThreshold this.score.score(id) >= this._options.scoreThresholds.gossipThreshold
) { ) {
peersToGossip.push(id); peersToGossip.push(id);