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

Use filter protocol #301

Closed
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion packages/status-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions packages/status-js/src/client/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -204,6 +205,7 @@ export class Chat {
this.#fetchingMessages = false
},
})
console.log('chat:fetch:end', new Date().toISOString())

this.#previousFetchedStartTime = startTime

Expand Down
17 changes: 16 additions & 1 deletion packages/status-js/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: use diff pinging

libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } },
})
await waku.waitForRemotePeer()
console.log('waku:ready', new Date().toISOString())
const wakuDisconnectionTimer = setInterval(async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: see if works for Filter too

const connectionsToClose: Promise<void>[] = []

Expand Down Expand Up @@ -144,6 +158,7 @@ class Client {
symKey,
})

// todo: use light push
await this.waku.relay.send(wakuMesage)
}

Expand Down
43 changes: 31 additions & 12 deletions packages/status-js/src/client/community/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Community {
public chats: Map<string, Chat>
#members: Map<string, Member>
#callbacks: Set<(description: CommunityDescription) => void>
#subscriptions: Map<string, () => Promise<void>>

constructor(client: Client, publicKey: string) {
this.client = client
Expand All @@ -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() {
Expand All @@ -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, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: explain why to filter now and when to relay again

contentTopics: [this.contentTopic],
})

Expand All @@ -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
Expand Down Expand Up @@ -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,
])
}
Expand All @@ -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(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: see stream limits and consider changing js-waku/go-waku's so one content topic can be unsubscribed from a stream serving many other topics without service interruption

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 (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: await where called

chatDescription: CommunityDescription['chats']
) => {
const contentTopics: string[] = []
Expand All @@ -161,17 +177,20 @@ export class Community {
const contentTopic = chat.contentTopic

this.chats.delete(chatUuid)
await this.#subscriptions.get(contentTopic)?.() // unsubscribe
contentTopics.push(contentTopic)
}

if (!contentTopics.length) {
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']) => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down