-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filter): use protocol peer management (#2047)
* feat: leverage protocol peer management * chore: add test * chore: address comments * chore: add todo
- Loading branch information
1 parent
42126a6
commit 4db508b
Showing
7 changed files
with
128 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,10 @@ | ||
import type { IEncoder, IMessage } from "./message.js"; | ||
import { SDKProtocolResult } from "./protocols.js"; | ||
import { ProtocolUseOptions, SDKProtocolResult } from "./protocols.js"; | ||
|
||
export interface ISender { | ||
send: ( | ||
encoder: IEncoder, | ||
message: IMessage, | ||
sendOptions?: SendOptions | ||
sendOptions?: ProtocolUseOptions | ||
) => Promise<SDKProtocolResult>; | ||
} | ||
|
||
/** | ||
* Options for using LightPush | ||
*/ | ||
export type SendOptions = { | ||
/** | ||
* Optional flag to enable auto-retry with exponential backoff | ||
*/ | ||
autoRetry?: boolean; | ||
/** | ||
* Optional flag to force using all available peers | ||
*/ | ||
forceUseAllPeers?: boolean; | ||
/** | ||
* Optional maximum number of attempts for exponential backoff | ||
*/ | ||
maxAttempts?: number; | ||
/** | ||
* Optional initial delay in milliseconds for exponential backoff | ||
*/ | ||
initialDelay?: number; | ||
/** | ||
* Optional maximum delay in milliseconds for exponential backoff | ||
*/ | ||
maxDelay?: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { DefaultPubsubTopic, LightNode } from "@waku/interfaces"; | ||
import { | ||
createDecoder, | ||
createEncoder, | ||
DecodedMessage, | ||
utf8ToBytes | ||
} from "@waku/sdk"; | ||
import { expect } from "chai"; | ||
import { describe } from "mocha"; | ||
|
||
import { | ||
afterEachCustom, | ||
beforeEachCustom, | ||
ServiceNodesFleet | ||
} from "../../src/index.js"; | ||
import { | ||
runMultipleNodes, | ||
teardownNodesWithRedundancy | ||
} from "../filter/utils.js"; | ||
|
||
//TODO: add unit tests, | ||
|
||
describe("Waku Filter: Peer Management: E2E", function () { | ||
this.timeout(15000); | ||
let waku: LightNode; | ||
let serviceNodes: ServiceNodesFleet; | ||
|
||
beforeEachCustom(this, async () => { | ||
[serviceNodes, waku] = await runMultipleNodes( | ||
this.ctx, | ||
undefined, | ||
undefined, | ||
5 | ||
); | ||
}); | ||
|
||
afterEachCustom(this, async () => { | ||
await teardownNodesWithRedundancy(serviceNodes, waku); | ||
}); | ||
|
||
const pubsubTopic = DefaultPubsubTopic; | ||
const contentTopic = "/test"; | ||
|
||
const encoder = createEncoder({ | ||
pubsubTopic, | ||
contentTopic | ||
}); | ||
|
||
const decoder = createDecoder(contentTopic, pubsubTopic); | ||
|
||
it("Number of peers are maintained correctly", async function () { | ||
const { error, subscription } = | ||
await waku.filter.createSubscription(pubsubTopic); | ||
if (!subscription || error) { | ||
expect.fail("Could not create subscription"); | ||
} | ||
|
||
const messages: DecodedMessage[] = []; | ||
const { failures, successes } = await subscription.subscribe( | ||
[decoder], | ||
(msg) => { | ||
messages.push(msg); | ||
} | ||
); | ||
|
||
await waku.lightPush.send(encoder, { | ||
payload: utf8ToBytes("Hello_World") | ||
}); | ||
|
||
expect(successes.length).to.be.greaterThan(0); | ||
expect(successes.length).to.be.equal(waku.filter.numPeersToUse); | ||
|
||
if (failures) { | ||
expect(failures.length).to.equal(0); | ||
} | ||
}); | ||
}); |