mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-13 05:23:13 +00:00
* implement proto * implement filter v2 * add tests * minor improvements - make unsubscribe functions private in filter - enable all tests * enable all tests * readd multiaddrinput * address comment removals * unsubscribe based on contentFilters passed * update unsubscribe function parameters in test * reset interfaces & filter v1 * refactor filterv2 into 2 classes - removes generics from types on filter which means manual typecasting to filter version is required on consumer side - defaults to filterv2 - splits filterv2 into 2 classes: - one to create the subscription object with a peer which returns the second class - the other to manage all subscription functions * updates filter tests for the new API - also fixes an interface import * update `toAsyncIterator` test for Filter V1 * implement IReceiver on FilterV2 * remove return values from subscription functions * update `to_async_iterator` * address variable naming * add tsdoc comments for hidden function * address minor comments * update docs to default to filter v2 * address comments * rename `wakuFilter` to `wakuFilterV1` * chore: Remove static variables (#1371) * chore: Remove static variables - Remove internal types from `@core/interfaces` - Remove data being redundantly stored (pubsub topic) - Remove usage of static variables - Clean up callbacks and decoders when using `unsubscribe` - Clean up callbacks and decoders when using `unsubscribeAll` * fix setting activeSubscription --------- Co-authored-by: danisharora099 <danisharora099@gmail.com> * make activeSub getter and setter private * update size-limit --------- Co-authored-by: fryorcraken.eth <110212804+fryorcraken@users.noreply.github.com>
83 lines
2.7 KiB
TypeScript
83 lines
2.7 KiB
TypeScript
import type { PeerId } from "@libp2p/interface-peer-id";
|
|
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
|
import type { Libp2pOptions } from "libp2p";
|
|
|
|
import type { IDecodedMessage } from "./message.js";
|
|
|
|
export enum Protocols {
|
|
Relay = "relay",
|
|
Store = "store",
|
|
LightPush = "lightpush",
|
|
Filter = "filter",
|
|
}
|
|
|
|
export interface PointToPointProtocol {
|
|
multicodec: string;
|
|
peerStore: PeerStore;
|
|
peers: () => Promise<Peer[]>;
|
|
}
|
|
|
|
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.
|
|
*
|
|
*/
|
|
pubSubTopic?: string;
|
|
/**
|
|
* You can pass options to the `Libp2p` instance used by {@link @waku/core.WakuNode} using the `libp2p` property.
|
|
* This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
|
|
* apart that we made the `modules` property optional and partial,
|
|
* allowing its omission and letting Waku set good defaults.
|
|
* Notes that some values are overridden by {@link @waku/core.WakuNode} to ensure it implements the Waku protocol.
|
|
*/
|
|
libp2p?: Partial<Libp2pOptions>;
|
|
/**
|
|
* Byte array used as key for the noise protocol used for connection encryption
|
|
* by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
|
|
* This is only used for test purposes to not run out of entropy during CI runs.
|
|
*/
|
|
staticNoiseKey?: Uint8Array;
|
|
/**
|
|
* Use recommended bootstrap method to discovery and connect to new nodes.
|
|
*/
|
|
defaultBootstrap?: boolean;
|
|
/**
|
|
* FilterV2 has been set to default
|
|
* Use this flag to enable the previous version of the filter protocol
|
|
* See [Improved Filter protocol specifications](https://github.com/vacp2p/rfc/pull/562)
|
|
*/
|
|
useFilterV1?: boolean;
|
|
};
|
|
|
|
export type ProtocolOptions = {
|
|
/**
|
|
* Optionally specify an PeerId for the protocol request. If not included, will use a random peer.
|
|
*/
|
|
peerId?: PeerId;
|
|
};
|
|
|
|
export type Callback<T extends IDecodedMessage> = (
|
|
msg: T
|
|
) => void | Promise<void>;
|
|
|
|
export enum SendError {
|
|
GENERIC_FAIL = "Generic error",
|
|
ENCODE_FAILED = "Failed to encode",
|
|
DECODE_FAILED = "Failed to decode",
|
|
SIZE_TOO_BIG = "Size is too big",
|
|
NO_RPC_RESPONSE = "No RPC response",
|
|
}
|
|
|
|
export interface SendResult {
|
|
error?: SendError;
|
|
recipients: PeerId[];
|
|
}
|