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[]>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 08:02:06 +05:30
|
|
|
export type ProtocolCreateOptions = {
|
|
|
|
|
/**
|
|
|
|
|
* The PubSub Topic to use. Defaults to {@link @waku/core/DefaultPubSubTopic }.
|
|
|
|
|
*
|
|
|
|
|
* One and only one pubsub topic is used by Waku. This is used by:
|
|
|
|
|
* - WakuRelay to receive, route and send messages,
|
|
|
|
|
* - WakuLightPush to send messages,
|
|
|
|
|
* - WakuStore to retrieve messages.
|
|
|
|
|
*
|
|
|
|
|
* The usage of the default pubsub topic is recommended.
|
|
|
|
|
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-12-05 17:00:24 +11:00
|
|
|
pubSubTopic?: string;
|
2023-02-02 08:02:06 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
// we can probably move `peerId` into `ProtocolCreateOptions` and remove `ProtocolOptions` and pass it in the constructor
|
|
|
|
|
// however, filter protocol can use multiple peers, so we need to think about this
|
|
|
|
|
export type ProtocolOptions = {
|
2022-12-05 17:00:24 +11:00
|
|
|
/**
|
|
|
|
|
* 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[];
|
|
|
|
|
}
|