UNPKG

@waku/relay

Version:
65 lines (64 loc) 2.6 kB
import { GossipSub, GossipSubComponents, GossipsubOpts } from "@chainsafe/libp2p-gossipsub"; import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types"; import { Callback, CreateNodeOptions, IAsyncIterator, IDecodedMessage, IDecoder, IEncoder, IMessage, IRelay, Libp2p, PubsubTopic, SDKProtocolResult } from "@waku/interfaces"; export type Observer<T extends IDecodedMessage> = { decoder: IDecoder<T>; callback: Callback<T>; }; export type RelayCreateOptions = CreateNodeOptions & GossipsubOpts; export type ContentTopic = string; type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>; type RelayConstructorParams = { libp2p: Libp2p; pubsubTopics: PubsubTopic[]; }; /** * Implements the [Waku v2 Relay protocol](https://rfc.vac.dev/spec/11/). * Throws if libp2p.pubsub does not support Waku Relay */ export declare class Relay implements IRelay { readonly pubsubTopics: Set<PubsubTopic>; private defaultDecoder; static multicodec: string; readonly gossipSub: GossipSub; /** * observers called when receiving new message. * Observers under key `""` are always called. */ private observers; constructor(params: RelayConstructorParams); /** * Mounts the gossipsub protocol onto the libp2p node * and subscribes to all the topics. * * @override * @returns {void} */ start(): Promise<void>; /** * Wait for at least one peer with the given protocol to be connected and in the gossipsub * mesh for all pubsubTopics. */ waitForPeers(): Promise<void>; /** * Send Waku message. */ send(encoder: IEncoder, message: IMessage): Promise<SDKProtocolResult>; subscribeWithUnsubscribe<T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>): () => void; subscribe: <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>) => () => void; private removeObservers; toSubscriptionIterator<T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[]): Promise<IAsyncIterator<T>>; getActiveSubscriptions(): ActiveSubscriptions; getMeshPeers(topic?: TopicStr): PeerIdStr[]; private subscribeToAllTopics; private processIncomingMessage; /** * Subscribe to a pubsub topic and start emitting Waku messages to observers. * * @override */ private gossipSubSubscribe; private isRelayPubsub; } export declare function wakuGossipSub(init?: Partial<RelayCreateOptions>): (components: GossipSubComponents) => GossipSub; export {};