@waku/interfaces 0.0.26-ce62600.0 → 0.0.26-f387f59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/connection_manager.d.ts +2 -0
- package/dist/connection_manager.js.map +1 -1
- package/dist/constants.d.ts +6 -4
- package/dist/constants.js +8 -4
- package/dist/constants.js.map +1 -1
- package/dist/enr.d.ts +1 -4
- package/dist/filter.d.ts +20 -3
- package/dist/health_manager.d.ts +21 -0
- package/dist/health_manager.js +7 -0
- package/dist/health_manager.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/libp2p.d.ts +5 -0
- package/dist/metadata.d.ts +4 -4
- package/dist/protocols.d.ts +33 -37
- package/dist/protocols.js +5 -0
- package/dist/protocols.js.map +1 -1
- package/dist/receiver.d.ts +3 -1
- package/dist/sharding.d.ts +10 -0
- package/dist/sharding.js +2 -0
- package/dist/sharding.js.map +1 -0
- package/dist/store.d.ts +59 -35
- package/dist/store.js +1 -5
- package/dist/store.js.map +1 -1
- package/dist/waku.d.ts +2 -0
- package/package.json +1 -1
- package/src/connection_manager.ts +3 -0
- package/src/constants.ts +11 -4
- package/src/enr.ts +2 -5
- package/src/filter.ts +28 -7
- package/src/health_manager.ts +26 -0
- package/src/index.ts +2 -0
- package/src/libp2p.ts +5 -0
- package/src/metadata.ts +4 -4
- package/src/protocols.ts +33 -39
- package/src/receiver.ts +6 -4
- package/src/sharding.ts +12 -0
- package/src/store.ts +65 -36
- package/src/waku.ts +3 -0
package/dist/protocols.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { Libp2p } from "@libp2p/interface";
|
2
2
|
import type { PeerId } from "@libp2p/interface";
|
3
3
|
import type { Peer, PeerStore } from "@libp2p/interface";
|
4
|
-
import type { ShardInfo } from "./enr.js";
|
5
4
|
import type { CreateLibp2pOptions } from "./libp2p.js";
|
6
5
|
import type { IDecodedMessage } from "./message.js";
|
7
|
-
import {
|
6
|
+
import { ThisAndThat, ThisOrThat } from "./misc.js";
|
7
|
+
import { AutoSharding, StaticSharding } from "./sharding.js";
|
8
8
|
export declare enum Protocols {
|
9
9
|
Relay = "relay",
|
10
10
|
Store = "store",
|
@@ -12,7 +12,6 @@ export declare enum Protocols {
|
|
12
12
|
Filter = "filter"
|
13
13
|
}
|
14
14
|
export type IBaseProtocolCore = {
|
15
|
-
shardInfo?: ShardInfo;
|
16
15
|
multicodec: string;
|
17
16
|
peerStore: PeerStore;
|
18
17
|
allPeers: () => Promise<Peer[]>;
|
@@ -21,20 +20,11 @@ export type IBaseProtocolCore = {
|
|
21
20
|
removeLibp2pEventListener: Libp2p["removeEventListener"];
|
22
21
|
};
|
23
22
|
export type IBaseProtocolSDK = {
|
24
|
-
renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
|
25
23
|
readonly connectedPeers: Peer[];
|
24
|
+
renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
|
26
25
|
readonly numPeersToUse: number;
|
27
26
|
};
|
28
|
-
export type
|
29
|
-
clusterId?: number;
|
30
|
-
contentTopics: string[];
|
31
|
-
};
|
32
|
-
export type ApplicationInfo = {
|
33
|
-
clusterId: number;
|
34
|
-
application: string;
|
35
|
-
version: string;
|
36
|
-
};
|
37
|
-
export type ShardingParams = ShardInfo | ContentTopicInfo | ApplicationInfo;
|
27
|
+
export type NetworkConfig = StaticSharding | AutoSharding;
|
38
28
|
/**
|
39
29
|
* Options for using LightPush and Filter
|
40
30
|
*/
|
@@ -62,34 +52,35 @@ export type ProtocolUseOptions = {
|
|
62
52
|
};
|
63
53
|
export type ProtocolCreateOptions = {
|
64
54
|
/**
|
65
|
-
*
|
66
|
-
* Waku will stop supporting named sharding. Only static sharding and autosharding will be supported moving forward.
|
67
|
-
*/
|
68
|
-
pubsubTopics?: PubsubTopic[];
|
69
|
-
/**
|
70
|
-
* Waku supports usage of multiple pubsub topics. This is achieved through static sharding for now, and auto-sharding in the future.
|
71
|
-
* The format to specify a shard is:
|
72
|
-
* clusterId: number, shards: number[]
|
73
|
-
* To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
74
|
-
* The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
|
55
|
+
* Configuration for determining the network in use.
|
75
56
|
*
|
76
|
-
* If
|
77
|
-
*
|
78
|
-
*
|
79
|
-
*
|
80
|
-
* - WakuRelay to receive, route and send messages,
|
81
|
-
* - WakuLightPush to send messages,
|
82
|
-
* - WakuStore to retrieve messages.
|
83
|
-
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
|
57
|
+
* If using Static Sharding:
|
58
|
+
* Default value is configured for The Waku Network.
|
59
|
+
* The format to specify a shard is: clusterId: number, shards: number[]
|
60
|
+
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
84
61
|
*
|
62
|
+
* If using Auto Sharding:
|
63
|
+
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
|
64
|
+
* You cannot add or remove content topics after initialization of the node.
|
85
65
|
*/
|
86
|
-
shardInfo?: Partial<ShardingParams>;
|
87
66
|
/**
|
88
|
-
*
|
89
|
-
*
|
90
|
-
*
|
67
|
+
* Configuration for determining the network in use.
|
68
|
+
* Network configuration refers to the shards and clusters used in the network.
|
69
|
+
*
|
70
|
+
* If using Static Sharding:
|
71
|
+
* Cluster ID and shards are specified in the format: clusterId: number, shards: number[]
|
72
|
+
* The default value is configured for The Waku Network => clusterId: 0, shards: [0, 1, 2, 3, 4, 5, 6, 7]
|
73
|
+
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
74
|
+
*
|
75
|
+
* If using Auto Sharding:
|
76
|
+
* Cluster ID and content topics are specified in the format: clusterId: number, contentTopics: string[]
|
77
|
+
* Content topics are used to determine the shards to be configured for the network.
|
78
|
+
* Cluster ID is optional, and defaults to The Waku Network's cluster ID => 0
|
79
|
+
* To specify content topics, see [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details
|
80
|
+
*
|
81
|
+
* @default { clusterId: 1, shards: [0, 1, 2, 3, 4, 5, 6, 7] }
|
91
82
|
*/
|
92
|
-
|
83
|
+
networkConfig?: NetworkConfig;
|
93
84
|
/**
|
94
85
|
* You can pass options to the `Libp2p` instance used by {@link @waku/sdk!WakuNode} using the `libp2p` property.
|
95
86
|
* 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)
|
@@ -155,6 +146,11 @@ export declare enum ProtocolError {
|
|
155
146
|
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
156
147
|
*/
|
157
148
|
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
149
|
+
/**
|
150
|
+
* The topics passed in the decoders do not match each other, or don't exist at all.
|
151
|
+
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
152
|
+
*/
|
153
|
+
INVALID_DECODER_TOPICS = "Invalid decoder topics",
|
158
154
|
/**
|
159
155
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
160
156
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
package/dist/protocols.js
CHANGED
@@ -39,6 +39,11 @@ export var ProtocolError;
|
|
39
39
|
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
40
40
|
*/
|
41
41
|
ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
|
42
|
+
/**
|
43
|
+
* The topics passed in the decoders do not match each other, or don't exist at all.
|
44
|
+
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
45
|
+
*/
|
46
|
+
ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
|
42
47
|
/**
|
43
48
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
44
49
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
package/dist/protocols.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;
|
1
|
+
{"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AAiHD,MAAM,CAAN,IAAY,aAkEX;AAlED,WAAY,aAAa;IACvB,4FAA4F;IAC5F,+CAA8B,CAAA;IAC9B;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,iDAAgC,CAAA;IAChC;;;OAGG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;;;OAKG;IACH,wDAAuC,CAAA;IACvC;;;OAGG;IACH,4DAA2C,CAAA;IAC3C;;;OAGG;IACH,wDAAuC,CAAA;IACvC;;;;OAIG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,oDAAmC,CAAA;AACrC,CAAC,EAlEW,aAAa,KAAb,aAAa,QAkExB"}
|
package/dist/receiver.d.ts
CHANGED
@@ -4,5 +4,7 @@ import type { Callback } from "./protocols.js";
|
|
4
4
|
export type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>;
|
5
5
|
export interface IReceiver {
|
6
6
|
toSubscriptionIterator: <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[]) => Promise<IAsyncIterator<T>>;
|
7
|
-
|
7
|
+
subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
|
8
8
|
}
|
9
|
+
type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>) => Unsubscribe | Promise<Unsubscribe>;
|
10
|
+
export {};
|
package/dist/sharding.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sharding.js","sourceRoot":"","sources":["../src/sharding.ts"],"names":[],"mappings":""}
|
package/dist/store.d.ts
CHANGED
@@ -1,51 +1,75 @@
|
|
1
|
-
import { proto_store as proto } from "@waku/proto";
|
2
1
|
import type { IDecodedMessage, IDecoder } from "./message.js";
|
3
2
|
import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
|
4
|
-
export
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
export
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
export type StoreCursor = Uint8Array;
|
4
|
+
/**
|
5
|
+
* Parameters for a store query request, as specified in the Waku Store v3 RFC.
|
6
|
+
*/
|
7
|
+
export type QueryRequestParams = {
|
8
|
+
/**
|
9
|
+
* Whether to include the full message data in the response.
|
10
|
+
* - `true`: The response will include the message content and associated pubsub topic for each matching message.
|
11
|
+
* - `false`: The response will only include the message hashes for each matching message.
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
includeData: boolean;
|
15
|
+
/**
|
16
|
+
* The pubsub topic to query. This field is mandatory.
|
17
|
+
* The query will only return messages that were published on this specific pubsub topic.
|
18
|
+
*/
|
16
19
|
pubsubTopic: string;
|
17
|
-
}
|
18
|
-
export type StoreQueryOptions = {
|
19
20
|
/**
|
20
|
-
* The
|
21
|
-
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
*
|
21
|
+
* The content topics to filter the messages.
|
22
|
+
* The query will only return messages that have a content topic included in this array.
|
23
|
+
* This field MUST be populated together with the `pubsubTopic` field for content topic filtering to be applied.
|
24
|
+
* If either `contentTopics` or `pubsubTopic` is not provided or empty, no content topic filtering will be applied.
|
25
|
+
*/
|
26
|
+
contentTopics: string[];
|
27
|
+
/**
|
28
|
+
* The start time for the time range filter.
|
29
|
+
* The query will only return messages with a timestamp greater than or equal to `timeStart`.
|
30
|
+
* If not provided, no start time filtering will be applied.
|
31
|
+
*/
|
32
|
+
timeStart?: Date;
|
33
|
+
/**
|
34
|
+
* The end time for the time range filter.
|
35
|
+
* The query will only return messages with a timestamp strictly less than `timeEnd`.
|
36
|
+
* If not provided, no end time filtering will be applied.
|
37
|
+
*/
|
38
|
+
timeEnd?: Date;
|
39
|
+
/**
|
40
|
+
* The message hashes to lookup.
|
41
|
+
* If provided, the query will be a message hash lookup query and will only return messages that match the specified hashes.
|
42
|
+
* If not provided or empty, the query will be a content filtered query based on the other filter parameters.
|
43
|
+
* @default undefined
|
28
44
|
*/
|
29
|
-
|
45
|
+
messageHashes?: Uint8Array[];
|
30
46
|
/**
|
31
|
-
* The
|
47
|
+
* The cursor to start the query from.
|
48
|
+
* The cursor represents the message hash of the last message returned in the previous query.
|
49
|
+
* The query will start from the message immediately following the cursor, excluding the message at the cursor itself.
|
50
|
+
* If not provided, the query will start from the beginning or end of the store, depending on the `paginationForward` option.
|
51
|
+
* @default undefined
|
32
52
|
*/
|
33
|
-
|
53
|
+
paginationCursor?: Uint8Array;
|
34
54
|
/**
|
35
|
-
*
|
55
|
+
* The direction of pagination.
|
56
|
+
* - `true`: Forward pagination, starting from the oldest message and moving towards the newest.
|
57
|
+
* - `false`: Backward pagination, starting from the newest message and moving towards the oldest.
|
58
|
+
* @default false
|
36
59
|
*/
|
37
|
-
|
60
|
+
paginationForward: boolean;
|
38
61
|
/**
|
39
|
-
*
|
40
|
-
*
|
62
|
+
* The maximum number of messages to retrieve per page.
|
63
|
+
* If not provided, the store's default pagination limit will be used.
|
64
|
+
* @default undefined
|
41
65
|
*/
|
42
|
-
|
66
|
+
paginationLimit?: number;
|
43
67
|
};
|
44
68
|
export type IStoreCore = IBaseProtocolCore;
|
45
69
|
export type IStoreSDK = IBaseProtocolSDK & {
|
46
70
|
protocol: IBaseProtocolCore;
|
47
|
-
createCursor(message: IDecodedMessage):
|
48
|
-
queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?:
|
49
|
-
queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?:
|
50
|
-
queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?:
|
71
|
+
createCursor(message: IDecodedMessage): StoreCursor;
|
72
|
+
queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: Partial<QueryRequestParams>) => AsyncGenerator<Promise<T | undefined>[]>;
|
73
|
+
queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
|
74
|
+
queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
|
51
75
|
};
|
package/dist/store.js
CHANGED
package/dist/store.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}
|
package/dist/waku.d.ts
CHANGED
@@ -2,6 +2,7 @@ import type { PeerId, Stream } from "@libp2p/interface";
|
|
2
2
|
import type { MultiaddrInput } from "@multiformats/multiaddr";
|
3
3
|
import { IConnectionManager } from "./connection_manager.js";
|
4
4
|
import type { IFilterSDK } from "./filter.js";
|
5
|
+
import { IHealthManager } from "./health_manager.js";
|
5
6
|
import type { Libp2p } from "./libp2p.js";
|
6
7
|
import type { ILightPushSDK } from "./light_push.js";
|
7
8
|
import { Protocols } from "./protocols.js";
|
@@ -19,6 +20,7 @@ export interface Waku {
|
|
19
20
|
stop(): Promise<void>;
|
20
21
|
isStarted(): boolean;
|
21
22
|
isConnected(): boolean;
|
23
|
+
health: IHealthManager;
|
22
24
|
}
|
23
25
|
export interface LightNode extends Waku {
|
24
26
|
relay: undefined;
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@waku/interfaces","version":"0.0.26-
|
1
|
+
{"name":"@waku/interfaces","version":"0.0.26-f387f59.0","description":"Definition of Waku interfaces","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","fix":"run-s fix:*","fix:lint":"eslint src --fix","check":"run-s check:*","check:lint":"eslint src","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=20"},"devDependencies":{"@chainsafe/libp2p-gossipsub":"^13.1.0","@multiformats/multiaddr":"^12.0.0","cspell":"^8.6.1","npm-run-all":"^4.1.5","libp2p":"^1.8.1"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@waku/proto":"0.0.8-f387f59.0"}}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import type { Peer, PeerId, TypedEventEmitter } from "@libp2p/interface";
|
2
2
|
|
3
|
+
import { PubsubTopic } from "./misc";
|
4
|
+
|
3
5
|
export enum Tags {
|
4
6
|
BOOTSTRAP = "bootstrap",
|
5
7
|
PEER_EXCHANGE = "peer-exchange",
|
@@ -61,6 +63,7 @@ export interface IConnectionStateEvents {
|
|
61
63
|
|
62
64
|
export interface IConnectionManager
|
63
65
|
extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> {
|
66
|
+
configuredPubsubTopics: PubsubTopic[];
|
64
67
|
dropConnection(peerId: PeerId): Promise<void>;
|
65
68
|
getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
|
66
69
|
stop(): void;
|
package/src/constants.ts
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
2
|
-
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
|
3
|
-
*/
|
4
|
-
export const DefaultPubsubTopic = "/waku/2/default-waku/proto";
|
1
|
+
import type { ShardInfo } from "./sharding";
|
5
2
|
|
6
3
|
/**
|
7
4
|
* The default cluster ID for The Waku Network
|
8
5
|
*/
|
9
6
|
export const DEFAULT_CLUSTER_ID = 1;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* DefaultShardInfo is default configuration for The Waku Network.
|
10
|
+
*/
|
11
|
+
export const DefaultShardInfo: ShardInfo = {
|
12
|
+
clusterId: DEFAULT_CLUSTER_ID,
|
13
|
+
shards: [0, 1, 2, 3, 4, 5, 6, 7, 8]
|
14
|
+
};
|
15
|
+
|
16
|
+
export const DefaultNetworkConfig = DefaultShardInfo;
|
package/src/enr.ts
CHANGED
@@ -2,6 +2,8 @@ import type { PeerId } from "@libp2p/interface";
|
|
2
2
|
import type { PeerInfo } from "@libp2p/interface";
|
3
3
|
import type { Multiaddr } from "@multiformats/multiaddr";
|
4
4
|
|
5
|
+
import { ShardInfo } from "./sharding";
|
6
|
+
|
5
7
|
export type ENRKey = string;
|
6
8
|
export type ENRValue = Uint8Array;
|
7
9
|
/**
|
@@ -18,11 +20,6 @@ export interface Waku2 {
|
|
18
20
|
lightPush: boolean;
|
19
21
|
}
|
20
22
|
|
21
|
-
export interface ShardInfo {
|
22
|
-
clusterId: number;
|
23
|
-
shards: number[];
|
24
|
-
}
|
25
|
-
|
26
23
|
export interface IEnr extends Map<ENRKey, ENRValue> {
|
27
24
|
nodeId?: NodeId;
|
28
25
|
peerId?: PeerId;
|
package/src/filter.ts
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
import type { PeerId } from "@libp2p/interface";
|
2
2
|
|
3
3
|
import type { IDecodedMessage, IDecoder } from "./message.js";
|
4
|
-
import type { ContentTopic,
|
4
|
+
import type { ContentTopic, ThisOrThat } from "./misc.js";
|
5
5
|
import type {
|
6
6
|
Callback,
|
7
7
|
IBaseProtocolCore,
|
8
8
|
IBaseProtocolSDK,
|
9
9
|
ProtocolError,
|
10
10
|
ProtocolUseOptions,
|
11
|
-
SDKProtocolResult
|
12
|
-
ShardingParams
|
11
|
+
SDKProtocolResult
|
13
12
|
} from "./protocols.js";
|
14
13
|
import type { IReceiver } from "./receiver.js";
|
15
14
|
|
15
|
+
export type SubscriptionCallback<T extends IDecodedMessage> = {
|
16
|
+
decoders: IDecoder<T>[];
|
17
|
+
callback: Callback<T>;
|
18
|
+
};
|
19
|
+
|
16
20
|
export type SubscribeOptions = {
|
17
21
|
keepAlive?: number;
|
18
22
|
pingsBeforePeerRenewed?: number;
|
23
|
+
maxMissedMessagesThreshold?: number;
|
19
24
|
};
|
20
25
|
|
21
26
|
export type IFilter = IReceiver & IBaseProtocolCore;
|
@@ -36,12 +41,28 @@ export interface ISubscriptionSDK {
|
|
36
41
|
|
37
42
|
export type IFilterSDK = IReceiver &
|
38
43
|
IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
subscribe<T extends IDecodedMessage>(
|
45
|
+
decoders: IDecoder<T> | IDecoder<T>[],
|
46
|
+
callback: Callback<T>,
|
47
|
+
protocolUseOptions?: ProtocolUseOptions,
|
48
|
+
subscribeOptions?: SubscribeOptions
|
49
|
+
): Promise<SubscribeResult>;
|
43
50
|
};
|
44
51
|
|
52
|
+
export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
|
53
|
+
|
54
|
+
type SubscriptionSuccess = {
|
55
|
+
subscription: ISubscriptionSDK;
|
56
|
+
error: null;
|
57
|
+
results: SDKProtocolResult;
|
58
|
+
};
|
59
|
+
|
60
|
+
type SubscriptionError = {
|
61
|
+
subscription: null;
|
62
|
+
error: ProtocolError;
|
63
|
+
results: null;
|
64
|
+
};
|
65
|
+
|
45
66
|
export type CreateSubscriptionResult = ThisOrThat<
|
46
67
|
"subscription",
|
47
68
|
ISubscriptionSDK,
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Protocols } from "./protocols";
|
2
|
+
|
3
|
+
export enum HealthStatus {
|
4
|
+
Unhealthy = "Unhealthy",
|
5
|
+
MinimallyHealthy = "MinimallyHealthy",
|
6
|
+
SufficientlyHealthy = "SufficientlyHealthy"
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface IHealthManager {
|
10
|
+
getHealthStatus: () => HealthStatus;
|
11
|
+
getProtocolStatus: (protocol: Protocols) => ProtocolHealth | undefined;
|
12
|
+
updateProtocolHealth: (multicodec: string, connectedPeers: number) => void;
|
13
|
+
}
|
14
|
+
|
15
|
+
export type NodeHealth = {
|
16
|
+
overallStatus: HealthStatus;
|
17
|
+
protocolStatuses: ProtocolsHealthStatus;
|
18
|
+
};
|
19
|
+
|
20
|
+
export type ProtocolHealth = {
|
21
|
+
name: Protocols;
|
22
|
+
status: HealthStatus;
|
23
|
+
lastUpdate: Date;
|
24
|
+
};
|
25
|
+
|
26
|
+
export type ProtocolsHealthStatus = Map<Protocols, ProtocolHealth>;
|
package/src/index.ts
CHANGED
package/src/libp2p.ts
CHANGED
package/src/metadata.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import type { PeerId } from "@libp2p/interface";
|
2
2
|
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import type {
|
3
|
+
import { PubsubTopic, ThisOrThat } from "./misc.js";
|
4
|
+
import type { IBaseProtocolCore } from "./protocols.js";
|
5
|
+
import type { ShardInfo } from "./sharding.js";
|
6
6
|
|
7
7
|
export type MetadataQueryResult = ThisOrThat<"shardInfo", ShardInfo>;
|
8
8
|
|
9
9
|
// IMetadata always has shardInfo defined while it is optionally undefined in IBaseProtocol
|
10
10
|
export interface IMetadata extends Omit<IBaseProtocolCore, "shardInfo"> {
|
11
|
-
|
11
|
+
pubsubTopics: PubsubTopic[];
|
12
12
|
confirmOrAttemptHandshake(peerId: PeerId): Promise<MetadataQueryResult>;
|
13
13
|
query(peerId: PeerId): Promise<MetadataQueryResult>;
|
14
14
|
}
|
package/src/protocols.ts
CHANGED
@@ -2,10 +2,10 @@ import type { Libp2p } from "@libp2p/interface";
|
|
2
2
|
import type { PeerId } from "@libp2p/interface";
|
3
3
|
import type { Peer, PeerStore } from "@libp2p/interface";
|
4
4
|
|
5
|
-
import type { ShardInfo } from "./enr.js";
|
6
5
|
import type { CreateLibp2pOptions } from "./libp2p.js";
|
7
6
|
import type { IDecodedMessage } from "./message.js";
|
8
|
-
import {
|
7
|
+
import { ThisAndThat, ThisOrThat } from "./misc.js";
|
8
|
+
import { AutoSharding, StaticSharding } from "./sharding.js";
|
9
9
|
|
10
10
|
export enum Protocols {
|
11
11
|
Relay = "relay",
|
@@ -15,7 +15,6 @@ export enum Protocols {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
export type IBaseProtocolCore = {
|
18
|
-
shardInfo?: ShardInfo;
|
19
18
|
multicodec: string;
|
20
19
|
peerStore: PeerStore;
|
21
20
|
allPeers: () => Promise<Peer[]>;
|
@@ -25,23 +24,12 @@ export type IBaseProtocolCore = {
|
|
25
24
|
};
|
26
25
|
|
27
26
|
export type IBaseProtocolSDK = {
|
28
|
-
renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
|
29
27
|
readonly connectedPeers: Peer[];
|
28
|
+
renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
|
30
29
|
readonly numPeersToUse: number;
|
31
30
|
};
|
32
31
|
|
33
|
-
export type
|
34
|
-
clusterId?: number;
|
35
|
-
contentTopics: string[];
|
36
|
-
};
|
37
|
-
|
38
|
-
export type ApplicationInfo = {
|
39
|
-
clusterId: number;
|
40
|
-
application: string;
|
41
|
-
version: string;
|
42
|
-
};
|
43
|
-
|
44
|
-
export type ShardingParams = ShardInfo | ContentTopicInfo | ApplicationInfo;
|
32
|
+
export type NetworkConfig = StaticSharding | AutoSharding;
|
45
33
|
|
46
34
|
//TODO: merge this with ProtocolCreateOptions or establish distinction: https://github.com/waku-org/js-waku/issues/2048
|
47
35
|
/**
|
@@ -72,34 +60,35 @@ export type ProtocolUseOptions = {
|
|
72
60
|
|
73
61
|
export type ProtocolCreateOptions = {
|
74
62
|
/**
|
75
|
-
*
|
76
|
-
* Waku will stop supporting named sharding. Only static sharding and autosharding will be supported moving forward.
|
77
|
-
*/
|
78
|
-
pubsubTopics?: PubsubTopic[];
|
79
|
-
/**
|
80
|
-
* Waku supports usage of multiple pubsub topics. This is achieved through static sharding for now, and auto-sharding in the future.
|
81
|
-
* The format to specify a shard is:
|
82
|
-
* clusterId: number, shards: number[]
|
83
|
-
* To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
84
|
-
* The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
|
63
|
+
* Configuration for determining the network in use.
|
85
64
|
*
|
86
|
-
* If
|
87
|
-
*
|
88
|
-
*
|
89
|
-
*
|
90
|
-
* - WakuRelay to receive, route and send messages,
|
91
|
-
* - WakuLightPush to send messages,
|
92
|
-
* - WakuStore to retrieve messages.
|
93
|
-
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
|
65
|
+
* If using Static Sharding:
|
66
|
+
* Default value is configured for The Waku Network.
|
67
|
+
* The format to specify a shard is: clusterId: number, shards: number[]
|
68
|
+
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
94
69
|
*
|
70
|
+
* If using Auto Sharding:
|
71
|
+
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
|
72
|
+
* You cannot add or remove content topics after initialization of the node.
|
95
73
|
*/
|
96
|
-
shardInfo?: Partial<ShardingParams>;
|
97
74
|
/**
|
98
|
-
*
|
99
|
-
*
|
100
|
-
*
|
75
|
+
* Configuration for determining the network in use.
|
76
|
+
* Network configuration refers to the shards and clusters used in the network.
|
77
|
+
*
|
78
|
+
* If using Static Sharding:
|
79
|
+
* Cluster ID and shards are specified in the format: clusterId: number, shards: number[]
|
80
|
+
* The default value is configured for The Waku Network => clusterId: 0, shards: [0, 1, 2, 3, 4, 5, 6, 7]
|
81
|
+
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
82
|
+
*
|
83
|
+
* If using Auto Sharding:
|
84
|
+
* Cluster ID and content topics are specified in the format: clusterId: number, contentTopics: string[]
|
85
|
+
* Content topics are used to determine the shards to be configured for the network.
|
86
|
+
* Cluster ID is optional, and defaults to The Waku Network's cluster ID => 0
|
87
|
+
* To specify content topics, see [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details
|
88
|
+
*
|
89
|
+
* @default { clusterId: 1, shards: [0, 1, 2, 3, 4, 5, 6, 7] }
|
101
90
|
*/
|
102
|
-
|
91
|
+
networkConfig?: NetworkConfig;
|
103
92
|
/**
|
104
93
|
* You can pass options to the `Libp2p` instance used by {@link @waku/sdk!WakuNode} using the `libp2p` property.
|
105
94
|
* 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)
|
@@ -169,6 +158,11 @@ export enum ProtocolError {
|
|
169
158
|
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
170
159
|
*/
|
171
160
|
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
161
|
+
/**
|
162
|
+
* The topics passed in the decoders do not match each other, or don't exist at all.
|
163
|
+
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
164
|
+
*/
|
165
|
+
INVALID_DECODER_TOPICS = "Invalid decoder topics",
|
172
166
|
/**
|
173
167
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
174
168
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
package/src/receiver.ts
CHANGED
@@ -13,8 +13,10 @@ export interface IReceiver {
|
|
13
13
|
toSubscriptionIterator: <T extends IDecodedMessage>(
|
14
14
|
decoders: IDecoder<T> | IDecoder<T>[]
|
15
15
|
) => Promise<IAsyncIterator<T>>;
|
16
|
-
|
17
|
-
decoders: IDecoder<T> | IDecoder<T>[],
|
18
|
-
callback: Callback<T>
|
19
|
-
) => Unsubscribe | Promise<Unsubscribe>;
|
16
|
+
subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
|
20
17
|
}
|
18
|
+
|
19
|
+
type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(
|
20
|
+
decoders: IDecoder<T> | IDecoder<T>[],
|
21
|
+
callback: Callback<T>
|
22
|
+
) => Unsubscribe | Promise<Unsubscribe>;
|