2023-03-21 02:44:35 +01:00
|
|
|
import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
|
2023-03-31 03:17:41 +02:00
|
|
|
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2023-11-14 21:22:52 +05:30
|
|
|
import type { PubsubTopic } from "./misc.js";
|
|
|
|
|
import type { IReceiver } from "./receiver.js";
|
2023-03-21 02:07:59 +01:00
|
|
|
import type { ISender } from "./sender.js";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2023-08-16 16:11:27 +05:30
|
|
|
/**
|
|
|
|
|
* Interface representing the Relay API, providing control and information about the GossipSub protocol.
|
|
|
|
|
*
|
|
|
|
|
* @property gossipSub - The GossipSub instance used for managing pub/sub behavior.
|
|
|
|
|
* @property start - Function to start the relay, returning a Promise that resolves when initialization is complete.
|
|
|
|
|
* @property getMeshPeers - Function to retrieve the mesh peers for a given topic or all topics if none is specified. Returns an array of peer IDs as strings.
|
|
|
|
|
*/
|
2023-08-16 20:18:13 +05:30
|
|
|
export interface IRelayAPI {
|
2023-11-14 21:22:52 +05:30
|
|
|
readonly pubsubTopics: Set<PubsubTopic>;
|
2023-03-31 03:17:41 +02:00
|
|
|
readonly gossipSub: GossipSub;
|
|
|
|
|
start: () => Promise<void>;
|
2024-10-09 00:43:34 +02:00
|
|
|
waitForPeers: () => Promise<void>;
|
2023-03-31 03:17:41 +02:00
|
|
|
getMeshPeers: (topic?: TopicStr) => PeerIdStr[];
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
2023-03-15 21:47:56 +01:00
|
|
|
|
2023-03-31 03:17:41 +02:00
|
|
|
export type IRelay = IRelayAPI & ISender & IReceiver;
|