fix: Use libp2p options passed to `createWaku`

This commit is contained in:
Franck Royer 2022-07-25 16:33:23 +10:00 committed by fryorcraken.eth
parent ee12ec0ab5
commit ba1c7b86ea
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 20 additions and 16 deletions

View File

@ -90,25 +90,26 @@ export async function createWaku(options?: CreateOptions): Promise<Waku> {
peerDiscovery.push(new Bootstrap(options?.bootstrap));
}
// TODO: Use options
const libp2pOpts = {
transports: [new WebSockets({ filter: filterAll })],
streamMuxers: [new Mplex()],
pubsub: new WakuRelay(),
connectionEncryption: [new Noise()],
};
const libp2pOpts = Object.assign(
{
transports: [new WebSockets({ filter: filterAll })],
streamMuxers: [new Mplex()],
pubsub: new WakuRelay(options),
connectionEncryption: [new Noise()],
},
options?.libp2p ?? {}
);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: modules property is correctly set thanks to voodoo
const libp2p = await createLibp2p(libp2pOpts);
const wakuStore = new WakuStore(libp2p);
const wakuLightPush = new WakuLightPush(libp2p);
const wakuStore = new WakuStore(libp2p, options);
const wakuLightPush = new WakuLightPush(libp2p, options);
// TODO pass options
const wakuFilter = new WakuFilter(libp2p);
await libp2p.start();
return new Waku({}, libp2p, wakuStore, wakuLightPush, wakuFilter);
return new Waku(options ?? {}, libp2p, wakuStore, wakuLightPush, wakuFilter);
}
export class Waku {

View File

@ -49,6 +49,7 @@ export class WakuFilter {
{ method?: DecryptionMethod; contentTopics?: string[] }
>;
// TODO: Accept options (pubsubtopic)
constructor(public libp2p: Libp2p) {
this.subscriptions = new Map();
this.decryptionKeys = new Map();

View File

@ -71,10 +71,12 @@ describe("Waku Relay [node only]", () => {
it("Subscribe", async function () {
log("Getting subscribers");
const subscribers1 =
waku1.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
const subscribers2 =
waku2.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
const subscribers1 = waku1.libp2p.pubsub
.getSubscribers(DefaultPubSubTopic)
.map((p) => p.toString());
const subscribers2 = waku2.libp2p.pubsub
.getSubscribers(DefaultPubSubTopic)
.map((p) => p.toString());
log("Asserting mutual subscription");
expect(subscribers1).to.contain(waku2.libp2p.peerId.toString());