feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
import type {
|
|
|
|
|
Peer,
|
|
|
|
|
PeerId,
|
|
|
|
|
Stream,
|
|
|
|
|
TypedEventEmitter
|
|
|
|
|
} from "@libp2p/interface";
|
2024-04-28 11:15:17 +02:00
|
|
|
import type { MultiaddrInput } from "@multiformats/multiaddr";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2024-10-04 13:53:54 +02:00
|
|
|
import type { IFilter } from "./filter.js";
|
2025-07-15 00:59:45 +02:00
|
|
|
import type { HealthStatus } from "./health_status.js";
|
2023-07-25 02:17:52 +02:00
|
|
|
import type { Libp2p } from "./libp2p.js";
|
2024-10-04 10:50:58 +02:00
|
|
|
import type { ILightPush } from "./light_push.js";
|
2025-04-14 10:46:47 +02:00
|
|
|
import { IDecodedMessage, IDecoder, IEncoder } from "./message.js";
|
2025-02-05 13:24:50 +01:00
|
|
|
import type { Protocols } from "./protocols.js";
|
2022-12-06 12:36:29 +11:00
|
|
|
import type { IRelay } from "./relay.js";
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
import type { ShardId } from "./sharding.js";
|
2024-10-04 13:53:54 +02:00
|
|
|
import type { IStore } from "./store.js";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2025-04-14 10:46:47 +02:00
|
|
|
export type CreateDecoderParams = {
|
|
|
|
|
contentTopic: string;
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
shardId?: ShardId;
|
2025-04-14 10:46:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type CreateEncoderParams = CreateDecoderParams & {
|
|
|
|
|
ephemeral?: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-04 08:12:59 +02:00
|
|
|
export const WakuEvent = {
|
|
|
|
|
Connection: "waku:connection",
|
|
|
|
|
Health: "waku:health"
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
export type WakuEvent = (typeof WakuEvent)[keyof typeof WakuEvent];
|
2025-08-27 12:29:22 +10:00
|
|
|
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
export interface IWakuEvents {
|
2025-07-15 00:59:45 +02:00
|
|
|
/**
|
|
|
|
|
* Emitted when a connection is established or lost.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
2025-09-04 08:12:59 +02:00
|
|
|
* waku.events.addEventListener("waku:connection", (event) => {
|
2025-07-15 00:59:45 +02:00
|
|
|
* console.log(event.detail); // true if connected, false if disconnected
|
|
|
|
|
* });
|
|
|
|
|
*/
|
2025-09-04 08:12:59 +02:00
|
|
|
"waku:connection": CustomEvent<boolean>;
|
2025-07-15 00:59:45 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Emitted when the health status changes.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
2025-09-04 08:12:59 +02:00
|
|
|
* waku.events.addEventListener("waku:health", (event) => {
|
2025-07-15 00:59:45 +02:00
|
|
|
* console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy'
|
|
|
|
|
* });
|
|
|
|
|
*/
|
2025-09-04 08:12:59 +02:00
|
|
|
"waku:health": CustomEvent<HealthStatus>;
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>;
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
export interface IWaku {
|
2022-12-05 17:00:24 +11:00
|
|
|
libp2p: Libp2p;
|
2022-12-06 12:36:29 +11:00
|
|
|
relay?: IRelay;
|
2024-10-04 13:53:54 +02:00
|
|
|
store?: IStore;
|
|
|
|
|
filter?: IFilter;
|
2024-10-04 10:50:58 +02:00
|
|
|
lightPush?: ILightPush;
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
|
2025-07-15 00:59:45 +02:00
|
|
|
/**
|
|
|
|
|
* Emits events related to the Waku node.
|
|
|
|
|
* Those are:
|
2025-09-04 08:12:59 +02:00
|
|
|
* - "waku:connection"
|
|
|
|
|
* - "waku:health"
|
2025-07-15 00:59:45 +02:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
2025-09-04 08:12:59 +02:00
|
|
|
* waku.events.addEventListener("waku:connection", (event) => {
|
2025-07-15 00:59:45 +02:00
|
|
|
* console.log(event.detail); // true if connected, false if disconnected
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
events: IWakuEventEmitter;
|
2023-07-31 13:54:39 +05:30
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* Returns a unique identifier for a node on the network.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* console.log(waku.peerId); // 12D3KooWNmk9yXHfHJ4rUduRqD1TCTHkNFMPF9WP2dqWpZDL4aUb
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
peerId: PeerId;
|
|
|
|
|
|
2025-07-15 00:59:45 +02:00
|
|
|
/**
|
|
|
|
|
* The health status can be one of three states:
|
|
|
|
|
* - Unhealthy: No peer connections
|
|
|
|
|
* - MinimallyHealthy: At least 1 peer supporting both Filter and LightPush protocols
|
|
|
|
|
* - SufficientlyHealthy: At least 2 peers supporting both Filter and LightPush protocols
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* console.log(waku.health); // 'Unhealthy'
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
health: HealthStatus;
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* Returns a list of supported protocols.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* console.log(waku.protocols); // ['/ipfs/id/1.0.0', '/ipfs/ping/1.0.0', '/vac/waku/filter-push/2.0.0-beta1', '/vac/waku/metadata/1.0.0']
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
protocols: string[];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dials to the provided peer
|
|
|
|
|
*
|
|
|
|
|
* @param {PeerId | MultiaddrInput} peer information to use for dialing
|
|
|
|
|
* @param {Protocols[]} [protocols] array of Waku protocols to be used for dialing. If no provided - will be derived from mounted protocols.
|
|
|
|
|
*
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
* @returns {Promise<Stream>} `Promise` that will resolve to a `Stream` to a dialed peer and will reject if the connection fails
|
2024-10-09 00:43:34 +02:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* await waku.dial(remotePeerId, [Protocols.LightPush]);
|
|
|
|
|
*
|
|
|
|
|
* waku.isConnected() === true;
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
2024-04-28 11:15:17 +02:00
|
|
|
dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise<Stream>;
|
2022-12-05 17:00:24 +11:00
|
|
|
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
/**
|
|
|
|
|
* Hang up a connection to a peer
|
|
|
|
|
*
|
|
|
|
|
* @param {PeerId | MultiaddrInput} peer information to use for hanging up
|
|
|
|
|
*
|
|
|
|
|
* @returns {Promise<boolean>} `Promise` that will resolve to `true` if the connection is hung up, `false` otherwise
|
|
|
|
|
*/
|
|
|
|
|
hangUp(peer: PeerId | MultiaddrInput): Promise<boolean>;
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* Starts all services and components related to functionality of Waku node.
|
|
|
|
|
*
|
|
|
|
|
* @returns {Promise<boolean>} `Promise` that will resolve when started.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* await waku.start();
|
|
|
|
|
*
|
|
|
|
|
* waku.isStarted() === true;
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
2022-12-05 17:00:24 +11:00
|
|
|
start(): Promise<void>;
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* Stops all recurring processes and services that are needed for functionality of Waku node.
|
|
|
|
|
*
|
|
|
|
|
* @returns {Promise<boolean>} `Promise` that resolves when stopped.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* await waku.stop();
|
|
|
|
|
*
|
|
|
|
|
* waku.isStarted === false;
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
2022-12-05 17:00:24 +11:00
|
|
|
stop(): Promise<void>;
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* Resolves when Waku successfully gains connection to a remote peers that fits provided requirements.
|
|
|
|
|
* Must be used after attempting to connect to nodes, using {@link IWaku.dial} or
|
|
|
|
|
* if was bootstrapped by using {@link IPeerExchange} or {@link DnsDiscoveryComponents}.
|
|
|
|
|
*
|
|
|
|
|
* @param {Protocols[]} [protocols] Protocols that need to be enabled by remote peers
|
|
|
|
|
* @param {number} [timeoutMs] Timeout value in milliseconds after which promise rejects
|
|
|
|
|
*
|
|
|
|
|
* @returns {Promise<void>} `Promise` that **resolves** if all desired protocols are fulfilled by
|
|
|
|
|
* at least one remote peer, **rejects** if the timeoutMs is reached
|
|
|
|
|
* @throws If passing a protocol that is not mounted or Waku node is not started
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* try {
|
|
|
|
|
* // let's wait for at least one LightPush node and timeout in 1 second
|
|
|
|
|
* await waku.waitForPeers([Protocols.LightPush], 1000);
|
|
|
|
|
* } catch(e) {
|
|
|
|
|
* waku.isConnected() === false;
|
|
|
|
|
* console.error("Failed to connect due to", e);
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* waku.isConnected() === true;
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
waitForPeers(protocols?: Protocols[], timeoutMs?: number): Promise<void>;
|
|
|
|
|
|
2025-04-14 10:46:47 +02:00
|
|
|
/**
|
|
|
|
|
* Creates a decoder for Waku messages on a specific content topic.
|
|
|
|
|
*
|
|
|
|
|
* A decoder is used to decode messages from the Waku network format.
|
|
|
|
|
* The decoder automatically handles shard configuration based on the Waku node's network settings.
|
|
|
|
|
*
|
|
|
|
|
* @param {CreateDecoderParams} params - Configuration for the decoder
|
|
|
|
|
* @returns {IDecoder<IDecodedMessage>} A decoder instance configured for the specified content topic
|
|
|
|
|
* @throws {Error} If the shard configuration is incompatible with the node's network settings
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* // Create a decoder with default network shard settings
|
|
|
|
|
* const decoder = waku.createDecoder({
|
|
|
|
|
* contentTopic: "/my-app/1/chat/proto"
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a decoder with custom shard settings
|
|
|
|
|
* const customDecoder = waku.createDecoder({
|
|
|
|
|
* contentTopic: "/my-app/1/chat/proto",
|
|
|
|
|
* shardInfo: {
|
|
|
|
|
* clusterId: 1,
|
|
|
|
|
* shard: 5
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
createDecoder(params: CreateDecoderParams): IDecoder<IDecodedMessage>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an encoder for Waku messages on a specific content topic.
|
|
|
|
|
*
|
|
|
|
|
* An encoder is used to encode messages into the Waku network format.
|
|
|
|
|
* The encoder automatically handles shard configuration based on the Waku node's network settings.
|
|
|
|
|
*
|
|
|
|
|
* @param {CreateEncoderParams} params - Configuration for the encoder including content topic and optionally shard information and ephemeral flag
|
|
|
|
|
* @returns {IEncoder} An encoder instance configured for the specified content topic
|
|
|
|
|
* @throws {Error} If the shard configuration is incompatible with the node's network settings
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* // Create a basic encoder with default network shard settings
|
|
|
|
|
* const encoder = waku.createEncoder({
|
|
|
|
|
* contentTopic: "/my-app/1/chat/proto"
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create an ephemeral encoder (messages won't be stored by store nodes)
|
|
|
|
|
* const ephemeralEncoder = waku.createEncoder({
|
|
|
|
|
* contentTopic: "/my-app/1/notifications/proto",
|
|
|
|
|
* ephemeral: true,
|
|
|
|
|
* shardInfo: {
|
|
|
|
|
* clusterId: 2,
|
|
|
|
|
* shardsUnderCluster: 16
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
createEncoder(params: CreateEncoderParams): IEncoder;
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* @returns {boolean} `true` if the node was started and `false` otherwise
|
|
|
|
|
*/
|
2022-12-05 17:00:24 +11:00
|
|
|
isStarted(): boolean;
|
2023-11-27 03:44:49 -08:00
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
/**
|
|
|
|
|
* @returns {boolean} `true` if the node has working connection and `false` otherwise
|
|
|
|
|
*/
|
2023-11-27 03:44:49 -08:00
|
|
|
isConnected(): boolean;
|
2025-01-31 00:16:00 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns {Peer[]} an array of all connected peers
|
|
|
|
|
*/
|
|
|
|
|
getConnectedPeers(): Promise<Peer[]>;
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
export interface LightNode extends IWaku {
|
2022-12-05 17:00:24 +11:00
|
|
|
relay: undefined;
|
2024-10-04 13:53:54 +02:00
|
|
|
store: IStore;
|
|
|
|
|
filter: IFilter;
|
2024-10-04 10:50:58 +02:00
|
|
|
lightPush: ILightPush;
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
|
|
|
|
|
2024-10-09 00:43:34 +02:00
|
|
|
export interface RelayNode extends IWaku {
|
2022-12-06 12:36:29 +11:00
|
|
|
relay: IRelay;
|
2022-12-05 17:00:24 +11:00
|
|
|
store: undefined;
|
|
|
|
|
filter: undefined;
|
|
|
|
|
lightPush: undefined;
|
|
|
|
|
}
|