2022-12-05 17:00:24 +11:00
|
|
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
|
|
|
|
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
import type { IMessage } from "./message.js";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
|
|
|
|
export enum Protocols {
|
|
|
|
|
Relay = "relay",
|
|
|
|
|
Store = "store",
|
|
|
|
|
LightPush = "lightpush",
|
|
|
|
|
Filter = "filter",
|
|
|
|
|
PeerExchange = "peer-exchange",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PointToPointProtocol {
|
2023-01-25 16:36:30 +11:00
|
|
|
multicodec: string;
|
2022-12-05 17:00:24 +11:00
|
|
|
peerStore: PeerStore;
|
|
|
|
|
peers: () => Promise<Peer[]>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ProtocolOptions = {
|
|
|
|
|
pubSubTopic?: string;
|
|
|
|
|
/**
|
|
|
|
|
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
|
|
|
|
|
*/
|
|
|
|
|
peerId?: PeerId;
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export type Callback<T extends IMessage> = (msg: T) => void | Promise<void>;
|
2022-12-05 17:00:24 +11:00
|
|
|
|
|
|
|
|
export interface SendResult {
|
|
|
|
|
recipients: PeerId[];
|
|
|
|
|
}
|