Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store uses multiple peers #1962

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/sdk/src/protocols/light_push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import { ensurePubsubTopicIsConfigured, Logger } from "@waku/utils";

import { BaseProtocolSDK } from "./base_protocol.js";

const DEFAULT_NUM_PEERS = 3;
const log = new Logger("sdk:light-push");

export class LightPushSDK extends BaseProtocolSDK implements ILightPushSDK {
public readonly protocol: LightPushCore;

constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super({ numPeersToUse: options?.numPeersToUse ?? DEFAULT_NUM_PEERS });
super({ numPeersToUse: options?.numPeersToUse });
this.protocol = new LightPushCore(libp2p, options);
}

Expand Down
27 changes: 12 additions & 15 deletions packages/sdk/src/protocols/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export class StoreSDK extends BaseProtocolSDK implements IStoreSDK {
public readonly protocol: StoreCore;

constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
// TODO: options.numPeersToUse is disregarded: https://github.com/waku-org/js-waku/issues/1685
super({ numPeersToUse: DEFAULT_NUM_PEERS });
super({ numPeersToUse: options?.numPeersToUse ?? DEFAULT_NUM_PEERS });

this.protocol = new StoreCore(libp2p, options);
}
Expand Down Expand Up @@ -65,23 +64,21 @@ export class StoreSDK extends BaseProtocolSDK implements IStoreSDK {
options
);

const peer = (
await this.protocol.getPeers({
numPeers: this.numPeers,
maxBootstrapPeers: 1
})
)[0];
const peers = await this.protocol.getPeers({
numPeers: this.numPeers,
maxBootstrapPeers: 1
});

if (!peer) throw new Error("No peers available to query");
if (!peers.length) throw new Error("No peers available to query");

const responseGenerator = this.protocol.queryPerPage(
queryOpts,
decodersAsMap,
peer
const responseGenerators = peers.map((peer) =>
this.protocol.queryPerPage(queryOpts, decodersAsMap, peer)
);

for await (const messages of responseGenerator) {
yield messages;
for (const responseGenerator of responseGenerators) {
for await (const messages of responseGenerator) {
yield messages;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/store/index.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("Waku Store, general", function () {
expect(result).to.not.eq(-1);
});

it("Query generator for multiple messages with different message text format", async function () {
it.only("Query generator for multiple messages with different message text format", async function () {
for (const testItem of TEST_STRING) {
expect(
await nwaku.sendMessage(
Expand Down
Loading