From 5688161f0a6dcf11a354b78d549502385e99a4bc Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Mon, 1 Aug 2022 10:29:29 +0200 Subject: [PATCH 1/2] install js-waku@^0.24.0 --- packages/status-js/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/status-js/package.json b/packages/status-js/package.json index 70534b9b6..64a8822ff 100644 --- a/packages/status-js/package.json +++ b/packages/status-js/package.json @@ -32,7 +32,7 @@ }, "dependencies": { "ethereum-cryptography": "^1.0.3", - "js-waku": "^0.23.0", + "js-waku": "^0.24.0", "long": "^5.2.0", "protobufjs": "^6.11.3", "protons-runtime": "^1.0.4" diff --git a/yarn.lock b/yarn.lock index c7ef3bd4a..65ab6a486 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4927,10 +4927,10 @@ js-sha3@^0.8.0: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-waku@^0.23.0: - version "0.23.0" - resolved "https://registry.yarnpkg.com/js-waku/-/js-waku-0.23.0.tgz#9f0d37b0ce6741fc39f5ff1be66eeff2b4ada1f7" - integrity sha512-M09UhXC7916Jo7isZbXij42CUbDYvcBIbFM7fkePC2cQV1rXNbD+989BATlfUtiNqjaLIZStoR8fwIfFeCY0kg== +js-waku@^0.24.0: + version "0.24.0" + resolved "https://registry.yarnpkg.com/js-waku/-/js-waku-0.24.0.tgz#509dc5e2fa30a4b1476b79665594d7b149717d4c" + integrity sha512-8l7/WuadaaGy6XmVKutZpJ61JohbBe8WamJUtNiTd8WdxhBuz/rXh5RUiD8mjiiG8kEzQ+3+E68rvIpb/+BbXw== dependencies: "@chainsafe/libp2p-noise" "^5.0.0" "@ethersproject/rlp" "^5.5.0" From 2ab1d13a10c77e150031177eaa908f660a14071a Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Mon, 1 Aug 2022 10:30:38 +0200 Subject: [PATCH 2/2] use filter protocol --- packages/status-js/src/client/chat.ts | 2 + packages/status-js/src/client/client.ts | 17 +++++++- .../src/client/community/community.ts | 43 +++++++++++++------ 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/packages/status-js/src/client/chat.ts b/packages/status-js/src/client/chat.ts index 36fc39717..1ae3220ac 100644 --- a/packages/status-js/src/client/chat.ts +++ b/packages/status-js/src/client/chat.ts @@ -184,6 +184,7 @@ export class Chat { endTime = new Date() } + console.log('chat:fetch:start', new Date().toISOString()) await this.client.waku.store.queryHistory([this.contentTopic], { timeFilter: { startTime: startTime, @@ -204,6 +205,7 @@ export class Chat { this.#fetchingMessages = false }, }) + console.log('chat:fetch:end', new Date().toISOString()) this.#previousFetchedStartTime = startTime diff --git a/packages/status-js/src/client/client.ts b/packages/status-js/src/client/client.ts index 97d53d03b..e561d0192 100644 --- a/packages/status-js/src/client/client.ts +++ b/packages/status-js/src/client/client.ts @@ -70,12 +70,26 @@ class Client { const waku = await Waku.create({ bootstrap: { default: false, - peers, + // peers, + peers: [ + // prod + // '/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA', + // test + // '/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS', + // '/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ', + // '/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ', + // test:go + // '/dns4/node-01.gc-us-central1-a.go-waku.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmPz63Xc6AuVkDeujz7YeZta18rcdau3Y1BzaxKAfDrBqz', + '/dns4/node-01.do-ams3.go-waku.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9vnvCQgCDrynDK1h7GJoEZVGvnuzq84RyDQ3DEdXmcX7', + // '/dns4/node-01.ac-cn-hongkong-c.go-waku.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmBDbMWFiG9ki8sDw6fYtraSxo4oHU9HbuN43S2HVyq1FD', + ], }, + // todo: don't relay relayKeepAlive: 15, libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } }, }) await waku.waitForRemotePeer() + console.log('waku:ready', new Date().toISOString()) const wakuDisconnectionTimer = setInterval(async () => { const connectionsToClose: Promise[] = [] @@ -144,6 +158,7 @@ class Client { symKey, }) + // todo: use light push await this.waku.relay.send(wakuMesage) } diff --git a/packages/status-js/src/client/community/community.ts b/packages/status-js/src/client/community/community.ts index 40c5426eb..d3fd74640 100644 --- a/packages/status-js/src/client/community/community.ts +++ b/packages/status-js/src/client/community/community.ts @@ -31,6 +31,7 @@ export class Community { public chats: Map #members: Map #callbacks: Set<(description: CommunityDescription) => void> + #subscriptions: Map Promise> constructor(client: Client, publicKey: string) { this.client = client @@ -42,6 +43,7 @@ export class Community { this.chats = new Map() this.#members = new Map() this.#callbacks = new Set() + this.#subscriptions = new Map() } public async start() { @@ -52,7 +54,8 @@ export class Community { this.client.waku.store.addDecryptionKey(this.symmetricKey, { contentTopics: [this.contentTopic], }) - this.client.waku.relay.addDecryptionKey(this.symmetricKey, { + // this.client.waku.relay.addDecryptionKey(this.symmetricKey, { + this.client.waku.filter.addDecryptionKey(this.symmetricKey, { contentTopics: [this.contentTopic], }) @@ -64,12 +67,14 @@ export class Community { } this.description = description + console.log('community:ready', new Date().toISOString()) this.observe() this.addMembers(this.description.members) // Chats await this.observeChatMessages(this.description.chats) + console.log('community:chats:ready', new Date().toISOString()) } // todo: rename this to chats when changing references in ui @@ -108,7 +113,8 @@ export class Community { } private observe = () => { - this.client.waku.relay.addObserver(this.client.handleWakuMessage, [ + // this.client.waku.relay.addObserver(this.client.handleWakuMessage, [ + this.client.waku.filter.subscribe(this.client.handleWakuMessage, [ this.contentTopic, ]) } @@ -129,24 +135,34 @@ export class Community { this.chats.set(chatUuid, chat) - this.client.waku.relay.addDecryptionKey(chat.symmetricKey, { + // this.client.waku.relay.addDecryptionKey(chat.symmetricKey, { + this.client.waku.filter.addDecryptionKey(chat.symmetricKey, { method: waku_message.DecryptionMethod.Symmetric, contentTopics: [contentTopic], }) + const unsubscribe = await this.client.waku.filter.subscribe( + this.client.handleWakuMessage, + [contentTopic] + ) + + this.#subscriptions.set(contentTopic, unsubscribe) + return contentTopic } ) const contentTopics = await Promise.all(chatPromises) + // await Promise.all(chatPromises) - this.client.waku.relay.addObserver( - this.client.handleWakuMessage, - contentTopics - ) + // this.client.waku.relay.addObserver( + // this.client.waku.filter.subscribe( + // this.client.handleWakuMessage, + // contentTopics + // ) } - private unobserveChatMessages = ( + private unobserveChatMessages = async ( chatDescription: CommunityDescription['chats'] ) => { const contentTopics: string[] = [] @@ -161,6 +177,7 @@ export class Community { const contentTopic = chat.contentTopic this.chats.delete(chatUuid) + await this.#subscriptions.get(contentTopic)?.() // unsubscribe contentTopics.push(contentTopic) } @@ -168,10 +185,12 @@ export class Community { return } - this.client.waku.relay.deleteObserver( - this.client.handleWakuMessage, - contentTopics - ) + // fixme: unsubscribe + // this.client.waku.relay.deleteObserver( + // this.client.handleWakuMessage, + // contentTopics + // ) + // this.client.waku.filter.unsubscribe() } private addMembers = (members: CommunityDescription['members']) => {