mirror of https://github.com/waku-org/js-waku.git
Merge pull request #1025 from waku-org/nwaku-v0.13.0
This commit is contained in:
commit
07e3a1ad69
|
@ -9,7 +9,7 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NWAKU_VERSION: "v0.11"
|
NWAKU_VERSION: "v0.13.0"
|
||||||
NODE_JS: "16"
|
NODE_JS: "16"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
2
nwaku
2
nwaku
|
@ -1 +1 @@
|
||||||
Subproject commit fec13974836149c2b81cab8d4178dee7bfc56db1
|
Subproject commit 9debd44e2aebf07eaf96b4525a4497c69aaf4445
|
|
@ -13,8 +13,8 @@ import { FilterCodec, WakuFilter } from "./waku_filter";
|
||||||
import { LightPushCodec, WakuLightPush } from "./waku_light_push";
|
import { LightPushCodec, WakuLightPush } from "./waku_light_push";
|
||||||
import { EncoderV0 } from "./waku_message/version_0";
|
import { EncoderV0 } from "./waku_message/version_0";
|
||||||
import { WakuRelay } from "./waku_relay";
|
import { WakuRelay } from "./waku_relay";
|
||||||
import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants";
|
|
||||||
import * as relayConstants from "./waku_relay/constants";
|
import * as relayConstants from "./waku_relay/constants";
|
||||||
|
import { RelayCodecs, RelayPingContentTopic } from "./waku_relay/constants";
|
||||||
import { StoreCodec, WakuStore } from "./waku_store";
|
import { StoreCodec, WakuStore } from "./waku_store";
|
||||||
|
|
||||||
export const DefaultPingKeepAliveValueSecs = 0;
|
export const DefaultPingKeepAliveValueSecs = 0;
|
||||||
|
@ -109,13 +109,20 @@ export class WakuNode implements Waku {
|
||||||
* Dials to the provided peer.
|
* Dials to the provided peer.
|
||||||
*
|
*
|
||||||
* @param peer The peer to dial
|
* @param peer The peer to dial
|
||||||
* @param protocols Waku protocols we expect from the peer; Default to Relay
|
* @param protocols Waku protocols we expect from the peer; Defaults to mounted protocols
|
||||||
*/
|
*/
|
||||||
async dial(
|
async dial(
|
||||||
peer: PeerId | Multiaddr,
|
peer: PeerId | Multiaddr,
|
||||||
protocols?: Protocols[]
|
protocols?: Protocols[]
|
||||||
): Promise<Stream> {
|
): Promise<Stream> {
|
||||||
const _protocols = protocols ?? [Protocols.Relay];
|
const _protocols = protocols ?? [];
|
||||||
|
|
||||||
|
if (typeof protocols === "undefined") {
|
||||||
|
this.relay && _protocols.push(Protocols.Relay);
|
||||||
|
this.store && _protocols.push(Protocols.Store);
|
||||||
|
this.filter && _protocols.push(Protocols.Filter);
|
||||||
|
this.lightPush && _protocols.push(Protocols.LightPush);
|
||||||
|
}
|
||||||
|
|
||||||
const codecs: string[] = [];
|
const codecs: string[] = [];
|
||||||
if (_protocols.includes(Protocols.Relay)) {
|
if (_protocols.includes(Protocols.Relay)) {
|
||||||
|
@ -131,8 +138,6 @@ export class WakuNode implements Waku {
|
||||||
codecs.push(FilterCodec);
|
codecs.push(FilterCodec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore: new Multiaddr is not backward compatible
|
|
||||||
return this.libp2p.dialProtocol(peer, codecs);
|
return this.libp2p.dialProtocol(peer, codecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,8 +227,8 @@ export class WakuStore {
|
||||||
);
|
);
|
||||||
|
|
||||||
log("Querying history with the following options", {
|
log("Querying history with the following options", {
|
||||||
peerId: options?.peerId?.toString(),
|
|
||||||
...options,
|
...options,
|
||||||
|
peerId: options?.peerId?.toString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await selectPeerForProtocol(
|
const res = await selectPeerForProtocol(
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
"check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"",
|
"check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"",
|
||||||
"check:tsc": "tsc -p tsconfig.dev.json",
|
"check:tsc": "tsc -p tsconfig.dev.json",
|
||||||
"test": "run-s test:*",
|
"test": "run-s test:*",
|
||||||
"test:node": "TS_NODE_PROJECT=./tsconfig.json mocha",
|
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
||||||
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -44,10 +44,10 @@ export interface Args {
|
||||||
nodekey?: string;
|
nodekey?: string;
|
||||||
portsShift?: number;
|
portsShift?: number;
|
||||||
logLevel?: LogLevel;
|
logLevel?: LogLevel;
|
||||||
persistMessages?: boolean;
|
|
||||||
lightpush?: boolean;
|
lightpush?: boolean;
|
||||||
filter?: boolean;
|
filter?: boolean;
|
||||||
store?: boolean;
|
store?: boolean;
|
||||||
|
storeMessageDbUrl?: string;
|
||||||
topics?: string;
|
topics?: string;
|
||||||
rpcPrivate?: boolean;
|
rpcPrivate?: boolean;
|
||||||
websocketSupport?: boolean;
|
websocketSupport?: boolean;
|
||||||
|
@ -407,7 +407,7 @@ export class Nwaku {
|
||||||
headers: new Headers({ "Content-Type": "application/json" }),
|
headers: new Headers({ "Content-Type": "application/json" }),
|
||||||
});
|
});
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
log(`RPC Response: `, res, JSON.stringify(json));
|
log(`RPC Response: `, JSON.stringify(json));
|
||||||
return json.result;
|
return json.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ export function argsToArray(args: Args): Array<string> {
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(args)) {
|
for (const [key, value] of Object.entries(args)) {
|
||||||
// Change the key from camelCase to kebab-case
|
// Change the key from camelCase to kebab-case
|
||||||
const kebabKey = key.replace(/([A-Z])/, (_, capital) => {
|
const kebabKey = key.replace(/([A-Z])/g, (_, capital) => {
|
||||||
return "-" + capital.toLowerCase();
|
return "-" + capital.toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -442,6 +442,7 @@ export function defaultArgs(): Args {
|
||||||
rpc: true,
|
rpc: true,
|
||||||
rpcAdmin: true,
|
rpcAdmin: true,
|
||||||
websocketSupport: true,
|
websocketSupport: true,
|
||||||
|
storeMessageDbUrl: "sqlite://:memory:",
|
||||||
logLevel: LogLevel.Debug,
|
logLevel: LogLevel.Debug,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ describe("nwaku", () => {
|
||||||
"--rpc=true",
|
"--rpc=true",
|
||||||
"--rpc-admin=true",
|
"--rpc-admin=true",
|
||||||
"--websocket-support=true",
|
"--websocket-support=true",
|
||||||
|
"--store-message-db-url=sqlite://:memory:",
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--ports-shift=42",
|
"--ports-shift=42",
|
||||||
];
|
];
|
||||||
|
|
|
@ -32,7 +32,7 @@ describe("Waku Store", () => {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
this.timeout(15_000);
|
this.timeout(15_000);
|
||||||
nwaku = new Nwaku(makeLogFileName(this));
|
nwaku = new Nwaku(makeLogFileName(this));
|
||||||
await nwaku.start({ persistMessages: true, store: true, lightpush: true });
|
await nwaku.start({ store: true, lightpush: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
|
@ -48,7 +48,7 @@ describe("Waku Store", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -78,7 +78,7 @@ describe("Waku Store", () => {
|
||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
const result = messages?.findIndex((msg) => {
|
const result = messages?.findIndex((msg) => {
|
||||||
return bytesToUtf8(msg.payload!) === "Message 0";
|
return msg.payload![0]! === 0;
|
||||||
});
|
});
|
||||||
expect(result).to.not.eq(-1);
|
expect(result).to.not.eq(-1);
|
||||||
});
|
});
|
||||||
|
@ -119,7 +119,7 @@ describe("Waku Store", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -146,7 +146,7 @@ describe("Waku Store", () => {
|
||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
const result = messages?.findIndex((msg) => {
|
const result = messages?.findIndex((msg) => {
|
||||||
return bytesToUtf8(msg.payload!) === "Message 0";
|
return msg.payload![0]! === 0;
|
||||||
});
|
});
|
||||||
expect(result).to.not.eq(-1);
|
expect(result).to.not.eq(-1);
|
||||||
});
|
});
|
||||||
|
@ -160,7 +160,7 @@ describe("Waku Store", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -199,7 +199,7 @@ describe("Waku Store", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -225,13 +225,8 @@ describe("Waku Store", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
for (let index = 0; index < totalMsgs; index++) {
|
const payloads = messages.map((msg) => msg.payload![0]!);
|
||||||
expect(
|
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
||||||
messages?.findIndex((msg) => {
|
|
||||||
return bytesToUtf8(msg.payload!) === `Message ${index}`;
|
|
||||||
})
|
|
||||||
).to.eq(index);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Ordered Callback - Backward", async function () {
|
it("Ordered Callback - Backward", async function () {
|
||||||
|
@ -242,7 +237,7 @@ describe("Waku Store", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -270,13 +265,8 @@ describe("Waku Store", () => {
|
||||||
messages = messages.reverse();
|
messages = messages.reverse();
|
||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
for (let index = 0; index < totalMsgs; index++) {
|
const payloads = messages.map((msg) => msg.payload![0]!);
|
||||||
expect(
|
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
||||||
messages?.findIndex((msg) => {
|
|
||||||
return bytesToUtf8(msg.payload!) === `Message ${index}`;
|
|
||||||
})
|
|
||||||
).to.eq(index);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Generator, with asymmetric & symmetric encrypted messages", async function () {
|
it("Generator, with asymmetric & symmetric encrypted messages", async function () {
|
||||||
|
@ -385,27 +375,27 @@ describe("Waku Store", () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
const startTime = new Date();
|
const startTime = new Date();
|
||||||
// Set start time 5 minutes in the past
|
// Set start time 15 seconds in the past
|
||||||
startTime.setTime(now.getTime() - 5 * 60 * 1000);
|
startTime.setTime(now.getTime() - 15 * 1000);
|
||||||
|
|
||||||
const message1Timestamp = new Date();
|
const message1Timestamp = new Date();
|
||||||
// Set first message was 4 minutes in the past
|
// Set first message was 10 seconds in the past
|
||||||
message1Timestamp.setTime(now.getTime() - 4 * 60 * 1000);
|
message1Timestamp.setTime(now.getTime() - 10 * 1000);
|
||||||
|
|
||||||
const message2Timestamp = new Date();
|
const message2Timestamp = new Date();
|
||||||
// Set second message 2 minutes in the past
|
// Set second message 2 seconds in the past
|
||||||
message2Timestamp.setTime(now.getTime() - 2 * 60 * 1000);
|
message2Timestamp.setTime(now.getTime() - 2 * 1000);
|
||||||
const messageTimestamps = [message1Timestamp, message2Timestamp];
|
const messageTimestamps = [message1Timestamp, message2Timestamp];
|
||||||
|
|
||||||
const endTime = new Date();
|
const endTime = new Date();
|
||||||
// Set end time 1 minute in the past
|
// Set end time 1 second in the past
|
||||||
endTime.setTime(now.getTime() - 60 * 1000);
|
endTime.setTime(now.getTime() - 1000);
|
||||||
|
|
||||||
for (let i = 0; i < 2; i++) {
|
for (let i = 0; i < 2; i++) {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
timestamp: messageTimestamps[i],
|
timestamp: messageTimestamps[i],
|
||||||
})
|
})
|
||||||
|
@ -453,7 +443,7 @@ describe("Waku Store", () => {
|
||||||
|
|
||||||
expect(firstMessages?.length).eq(1);
|
expect(firstMessages?.length).eq(1);
|
||||||
|
|
||||||
expect(bytesToUtf8(firstMessages[0].payload!)).eq("Message 0");
|
expect(firstMessages[0].payload![0]!).eq(0);
|
||||||
|
|
||||||
expect(bothMessages?.length).eq(2);
|
expect(bothMessages?.length).eq(2);
|
||||||
});
|
});
|
||||||
|
@ -467,7 +457,7 @@ describe("Waku Store", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -505,7 +495,6 @@ describe("Waku Store, custom pubsub topic", () => {
|
||||||
this.timeout(15_000);
|
this.timeout(15_000);
|
||||||
nwaku = new Nwaku(makeLogFileName(this));
|
nwaku = new Nwaku(makeLogFileName(this));
|
||||||
await nwaku.start({
|
await nwaku.start({
|
||||||
persistMessages: true,
|
|
||||||
store: true,
|
store: true,
|
||||||
topics: customPubSubTopic,
|
topics: customPubSubTopic,
|
||||||
});
|
});
|
||||||
|
@ -524,7 +513,7 @@ describe("Waku Store, custom pubsub topic", () => {
|
||||||
expect(
|
expect(
|
||||||
await nwaku.sendMessage(
|
await nwaku.sendMessage(
|
||||||
Nwaku.toMessageRpcQuery({
|
Nwaku.toMessageRpcQuery({
|
||||||
payload: utf8ToBytes(`Message ${i}`),
|
payload: new Uint8Array([i]),
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
}),
|
}),
|
||||||
customPubSubTopic
|
customPubSubTopic
|
||||||
|
@ -556,7 +545,7 @@ describe("Waku Store, custom pubsub topic", () => {
|
||||||
|
|
||||||
expect(messages?.length).eq(totalMsgs);
|
expect(messages?.length).eq(totalMsgs);
|
||||||
const result = messages?.findIndex((msg) => {
|
const result = messages?.findIndex((msg) => {
|
||||||
return bytesToUtf8(msg.payload!) === "Message 0";
|
return msg.payload![0]! === 0;
|
||||||
});
|
});
|
||||||
expect(result).to.not.eq(-1);
|
expect(result).to.not.eq(-1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -101,7 +101,6 @@ describe("Wait for remote peer", function () {
|
||||||
relay: false,
|
relay: false,
|
||||||
lightpush: false,
|
lightpush: false,
|
||||||
filter: false,
|
filter: false,
|
||||||
persistMessages: true,
|
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
|
@ -128,7 +127,6 @@ describe("Wait for remote peer", function () {
|
||||||
relay: false,
|
relay: false,
|
||||||
lightpush: false,
|
lightpush: false,
|
||||||
filter: false,
|
filter: false,
|
||||||
persistMessages: true,
|
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
|
@ -213,7 +211,6 @@ describe("Wait for remote peer", function () {
|
||||||
lightpush: true,
|
lightpush: true,
|
||||||
relay: false,
|
relay: false,
|
||||||
store: true,
|
store: true,
|
||||||
persistMessages: true,
|
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ describe("Waku Dial [node only]", function () {
|
||||||
filter: true,
|
filter: true,
|
||||||
store: true,
|
store: true,
|
||||||
lightpush: true,
|
lightpush: true,
|
||||||
persistMessages: true,
|
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue