mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-04-03 00:33:35 +00:00
chore: add bootstrap nodes
This commit is contained in:
parent
56c9c8d889
commit
e3128876de
@ -21,5 +21,9 @@ export const NETWORK_CONFIG: NetworkConfig = {
|
|||||||
* Bootstrap nodes for the Waku network
|
* Bootstrap nodes for the Waku network
|
||||||
* These are public Waku nodes that our node will connect to on startup
|
* These are public Waku nodes that our node will connect to on startup
|
||||||
*/
|
*/
|
||||||
export const BOOTSTRAP_NODES = [
|
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"]
|
||||||
|
};
|
||||||
@ -32,7 +32,7 @@ class MessageManager {
|
|||||||
defaultBootstrap: false,
|
defaultBootstrap: false,
|
||||||
networkConfig: NETWORK_CONFIG,
|
networkConfig: NETWORK_CONFIG,
|
||||||
autoStart: true,
|
autoStart: true,
|
||||||
bootstrapPeers: BOOTSTRAP_NODES,
|
bootstrapPeers: BOOTSTRAP_NODES[42],
|
||||||
lightPush:{autoRetry: true, retryIntervalMs: 1000}
|
lightPush:{autoRetry: true, retryIntervalMs: 1000}
|
||||||
});
|
});
|
||||||
return new MessageManager(node);
|
return new MessageManager(node);
|
||||||
@ -48,6 +48,32 @@ class MessageManager {
|
|||||||
this.storeManager = new StoreManager(node);
|
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) {
|
private updateCache(message: OpchanMessage) {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case MessageType.CELL:
|
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();
|
const messageManager = await MessageManager.create();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user