Allow passing multiaddr to bootstrap.peers (#608)

This commit is contained in:
Franck R 2022-03-09 18:38:28 +11:00 committed by GitHub
parent e4024d5c72
commit ed23332965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- When using `Waku.create`, `bootstrap.peers` now accepts an array of `Multiaddr`.
## [0.19.0] - 2022-03-09
### Added

View File

@ -185,8 +185,7 @@ async function initWaku(setter: (waku: Waku) => void) {
},
},
bootstrap: {
getPeers: () =>
Promise.resolve(getPredefinedBootstrapNodes(selectFleetEnv())),
peers: getPredefinedBootstrapNodes(selectFleetEnv()),
},
});

View File

@ -31,7 +31,7 @@ export interface BootstrapOptions {
/**
* Multiaddrs of peers to connect to.
*/
peers?: string[];
peers?: string[] | Multiaddr[];
/**
* Getter that retrieve multiaddrs of peers to connect to.
*/
@ -64,7 +64,13 @@ export class Bootstrap {
};
} else if (opts.peers !== undefined && opts.peers.length > 0) {
const allPeers: Multiaddr[] = opts.peers.map(
(node: string) => new Multiaddr(node)
(node: string | Multiaddr) => {
if (typeof node === "string") {
return new Multiaddr(node);
} else {
return node;
}
}
);
const peers = getPseudoRandomSubset(allPeers, maxPeers);
dbg(

View File

@ -62,7 +62,7 @@ describe("Waku Dial [node only]", function () {
waku = await Waku.create({
staticNoiseKey: NOISE_KEY_1,
bootstrap: { peers: [multiAddrWithId.toString()] },
bootstrap: { peers: [multiAddrWithId] },
});
const connectedPeerID: PeerId = await new Promise((resolve) => {