-
Notifications
You must be signed in to change notification settings - Fork 36
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
Use filter protocol #301
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: see if works for Filter too |
||
const connectionsToClose: Promise<void>[] = [] | ||
|
||
|
@@ -144,6 +158,7 @@ class Client { | |
symKey, | ||
}) | ||
|
||
// todo: use light push | ||
await this.waku.relay.send(wakuMesage) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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], | ||
}) | ||
|
||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: await where called |
||
chatDescription: CommunityDescription['chats'] | ||
) => { | ||
const contentTopics: string[] = [] | ||
|
@@ -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']) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: use diff pinging