From e3128876de84584be2bbcd156ca3960cf30f1f1f Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Wed, 16 Apr 2025 15:40:20 +0530 Subject: [PATCH] chore: add bootstrap nodes --- src/lib/waku/constants.ts | 8 ++++-- src/lib/waku/index.ts | 59 +++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/lib/waku/constants.ts b/src/lib/waku/constants.ts index a12b6ad..2220f5e 100644 --- a/src/lib/waku/constants.ts +++ b/src/lib/waku/constants.ts @@ -21,5 +21,9 @@ export const NETWORK_CONFIG: NetworkConfig = { * Bootstrap nodes for the Waku network * These are public Waku nodes that our node will connect to on startup */ -export const BOOTSTRAP_NODES = [ -]; \ No newline at end of file +export const BOOTSTRAP_NODES = { + "42": ["/dns4/waku-test.bloxy.one/tcp/8095/wss/p2p/16Uiu2HAmSZbDB7CusdRhgkD81VssRjQV5ZH13FbzCGcdnbbh6VwZ", + "/dns4/node-01.do-ams3.waku.sandbox.status.im/tcp/30303/p2p/16Uiu2HAmNaeL4p3WEYzC9mgXBmBWSgWjPHRvatZTXnp8Jgv3iKsb", + "/dns4/waku.fryorcraken.xyz/tcp/8000/wss/p2p/16Uiu2HAmMRvhDHrtiHft1FTUYnn6cVA8AWVrTyLUayJJ3MWpUZDB", + "/dns4/vps-aaa00d52.vps.ovh.ca/tcp/8000/wss/p2p/16Uiu2HAm9PftGgHZwWE3wzdMde4m3kT2eYJFXLZfGoSED3gysofk"] + }; \ No newline at end of file diff --git a/src/lib/waku/index.ts b/src/lib/waku/index.ts index 00e6b4d..b8860a2 100644 --- a/src/lib/waku/index.ts +++ b/src/lib/waku/index.ts @@ -32,7 +32,7 @@ class MessageManager { defaultBootstrap: false, networkConfig: NETWORK_CONFIG, autoStart: true, - bootstrapPeers: BOOTSTRAP_NODES, + bootstrapPeers: BOOTSTRAP_NODES[42], lightPush:{autoRetry: true, retryIntervalMs: 1000} }); return new MessageManager(node); @@ -48,6 +48,32 @@ class MessageManager { this.storeManager = new StoreManager(node); } + public async queryStore() { + const messages = await this.storeManager.queryStore(); + + for (const message of messages) { + this.updateCache(message); + } + + return messages; + } + + public async sendMessage(message: OpchanMessage) { + await this.ephemeralProtocolsManager.sendMessage(message); + //TODO: should we update the cache here? or just from store/filter? + this.updateCache(message); + } + + public async subscribeToMessages(types: MessageType[] = [MessageType.CELL, MessageType.POST, MessageType.COMMENT, MessageType.VOTE]) { + const { result, subscription } = await this.ephemeralProtocolsManager.subscribeToMessages(types); + + for (const message of result) { + this.updateCache(message); + } + + return { messages: result, subscription }; + } + private updateCache(message: OpchanMessage) { switch (message.type) { case MessageType.CELL: @@ -72,36 +98,7 @@ class MessageManager { } } - public async queryStore() { - const messages = await this.storeManager.queryStore(); - - // Populate cache from store messages - for (const message of messages) { - this.updateCache(message); - } - - return messages; - } - - public async sendMessage(message: OpchanMessage) { - await this.ephemeralProtocolsManager.sendMessage(message); - // Also update local cache with the message we just sent - this.updateCache(message); - } - - public async subscribeToMessages(types: MessageType[] = [MessageType.CELL, MessageType.POST, MessageType.COMMENT, MessageType.VOTE]) { - const { result, subscription } = await this.ephemeralProtocolsManager.subscribeToMessages(types); - - // Set up a callback that will be triggered for new messages - // New messages from the subscription will be processed directly by the ephemeralProtocolsManager - // and returned via the result array, so we just need to add them to the cache - for (const message of result) { - this.updateCache(message); - } - - // Return result and subscription for any external processing - return { messages: result, subscription }; - } + } const messageManager = await MessageManager.create();