@waku/interfaces 0.0.29-66cf711.0 → 0.0.29-8a6571f.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 +27 -8
- package/dist/connection_manager.js.map +1 -1
- package/dist/filter.d.ts +24 -8
- package/dist/health_indicator.d.ts +18 -0
- package/dist/{health_manager.js → health_indicator.js} +5 -1
- package/dist/health_indicator.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/light_push.d.ts +16 -1
- package/dist/protocols.d.ts +68 -79
- package/dist/protocols.js +40 -45
- package/dist/protocols.js.map +1 -1
- package/dist/sender.d.ts +3 -3
- package/dist/store.d.ts +5 -2
- package/dist/waku.d.ts +9 -5
- package/package.json +1 -1
- package/src/connection_manager.ts +31 -8
- package/src/filter.ts +29 -17
- package/src/health_indicator.ts +24 -0
- package/src/index.ts +1 -2
- package/src/light_push.ts +21 -2
- package/src/protocols.ts +102 -83
- package/src/sender.ts +4 -3
- package/src/store.ts +6 -2
- package/src/waku.ts +10 -6
- package/dist/health_manager.d.ts +0 -21
- package/dist/health_manager.js.map +0 -1
- package/dist/keep_alive_manager.d.ts +0 -4
- package/dist/keep_alive_manager.js +0 -2
- package/dist/keep_alive_manager.js.map +0 -1
- package/src/health_manager.ts +0 -26
- package/src/keep_alive_manager.ts +0 -4
package/src/protocols.ts
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
import type { Libp2p } from "@libp2p/interface";
|
2
2
|
import type { PeerId } from "@libp2p/interface";
|
3
|
-
import type { Peer } from "@libp2p/interface";
|
4
3
|
|
4
|
+
import type { ConnectionManagerOptions } from "./connection_manager.js";
|
5
|
+
import type { FilterProtocolOptions } from "./filter.js";
|
5
6
|
import type { CreateLibp2pOptions } from "./libp2p.js";
|
7
|
+
import type { LightPushProtocolOptions } from "./light_push.js";
|
6
8
|
import type { IDecodedMessage } from "./message.js";
|
7
|
-
import { ThisAndThat, ThisOrThat } from "./misc.js";
|
8
|
-
import { AutoSharding, StaticSharding } from "./sharding.js";
|
9
|
+
import type { ThisAndThat, ThisOrThat } from "./misc.js";
|
10
|
+
import type { AutoSharding, StaticSharding } from "./sharding.js";
|
11
|
+
import type { StoreProtocolOptions } from "./store.js";
|
9
12
|
|
10
13
|
export enum Protocols {
|
11
14
|
Relay = "relay",
|
@@ -16,48 +19,28 @@ export enum Protocols {
|
|
16
19
|
|
17
20
|
export type IBaseProtocolCore = {
|
18
21
|
multicodec: string;
|
19
|
-
allPeers: () => Promise<Peer[]>;
|
20
|
-
connectedPeers: () => Promise<Peer[]>;
|
21
22
|
addLibp2pEventListener: Libp2p["addEventListener"];
|
22
23
|
removeLibp2pEventListener: Libp2p["removeEventListener"];
|
23
24
|
};
|
24
25
|
|
25
|
-
export type IBaseProtocolSDK = {
|
26
|
-
readonly connectedPeers: Peer[];
|
27
|
-
renewPeer: (peerToDisconnect: PeerId) => Promise<Peer | undefined>;
|
28
|
-
readonly numPeersToUse: number;
|
29
|
-
};
|
30
|
-
|
31
26
|
export type NetworkConfig = StaticSharding | AutoSharding;
|
32
27
|
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Options for using LightPush and Filter
|
36
|
-
*/
|
37
|
-
export type ProtocolUseOptions = {
|
38
|
-
/**
|
39
|
-
* Optional flag to force using all available peers
|
40
|
-
*/
|
41
|
-
forceUseAllPeers?: boolean;
|
28
|
+
export type CreateNodeOptions = {
|
42
29
|
/**
|
43
|
-
*
|
30
|
+
* Set the user agent string to be used in identification of the node.
|
31
|
+
*
|
32
|
+
* @default "js-waku"
|
44
33
|
*/
|
45
|
-
|
46
|
-
};
|
34
|
+
userAgent?: string;
|
47
35
|
|
48
|
-
export type ProtocolCreateOptions = {
|
49
36
|
/**
|
50
|
-
*
|
37
|
+
* Starts Waku node automatically upon creations.
|
38
|
+
* Calls {@link @waku/sdk!WakuNode.start} before returning {@link @waku/sdk!WakuNode}
|
51
39
|
*
|
52
|
-
*
|
53
|
-
* Default value is configured for The Waku Network.
|
54
|
-
* The format to specify a shard is: clusterId: number, shards: number[]
|
55
|
-
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
56
|
-
*
|
57
|
-
* If using Auto Sharding:
|
58
|
-
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
|
59
|
-
* You cannot add or remove content topics after initialization of the node.
|
40
|
+
* @default true
|
60
41
|
*/
|
42
|
+
autoStart?: boolean;
|
43
|
+
|
61
44
|
/**
|
62
45
|
* Configuration for determining the network in use.
|
63
46
|
* Network configuration refers to the shards and clusters used in the network.
|
@@ -76,6 +59,7 @@ export type ProtocolCreateOptions = {
|
|
76
59
|
* @default { clusterId: 1, shards: [0, 1, 2, 3, 4, 5, 6, 7] }
|
77
60
|
*/
|
78
61
|
networkConfig?: NetworkConfig;
|
62
|
+
|
79
63
|
/**
|
80
64
|
* You can pass options to the `Libp2p` instance used by {@link @waku/sdk!WakuNode} using the `libp2p` property.
|
81
65
|
* 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)
|
@@ -84,28 +68,55 @@ export type ProtocolCreateOptions = {
|
|
84
68
|
* Notes that some values are overridden by {@link @waku/sdk!WakuNode} to ensure it implements the Waku protocol.
|
85
69
|
*/
|
86
70
|
libp2p?: Partial<CreateLibp2pOptions>;
|
71
|
+
|
87
72
|
/**
|
88
73
|
* Number of peers to connect to, for the usage of the protocol.
|
89
|
-
* This is used by
|
90
|
-
*
|
91
|
-
*
|
92
|
-
* Defaults to 2.
|
74
|
+
* This is used by Filter to retrieve messages.
|
75
|
+
*
|
76
|
+
* @default 2.
|
93
77
|
*/
|
94
78
|
numPeersToUse?: number;
|
79
|
+
|
95
80
|
/**
|
96
81
|
* Byte array used as key for the noise protocol used for connection encryption
|
97
82
|
* by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
|
98
83
|
* This is only used for test purposes to not run out of entropy during CI runs.
|
99
84
|
*/
|
100
85
|
staticNoiseKey?: Uint8Array;
|
86
|
+
|
101
87
|
/**
|
102
88
|
* Use recommended bootstrap method to discovery and connect to new nodes.
|
103
89
|
*/
|
104
90
|
defaultBootstrap?: boolean;
|
91
|
+
|
105
92
|
/**
|
106
93
|
* List of peers to use to bootstrap the node. Ignored if defaultBootstrap is set to true.
|
107
94
|
*/
|
108
95
|
bootstrapPeers?: string[];
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Configuration for connection manager.
|
99
|
+
* If not specified - default values are applied.
|
100
|
+
*/
|
101
|
+
connectionManager?: Partial<ConnectionManagerOptions>;
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Configuration for Filter protocol.
|
105
|
+
* If not specified - default values are applied.
|
106
|
+
*/
|
107
|
+
filter?: Partial<FilterProtocolOptions>;
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Options for the Store protocol.
|
111
|
+
* If not specified - default values are applied.
|
112
|
+
*/
|
113
|
+
store?: Partial<StoreProtocolOptions>;
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Options for the LightPush protocol.
|
117
|
+
* If not specified - default values are applied.
|
118
|
+
*/
|
119
|
+
lightPush?: Partial<LightPushProtocolOptions>;
|
109
120
|
};
|
110
121
|
|
111
122
|
export type Callback<T extends IDecodedMessage> = (
|
@@ -113,43 +124,27 @@ export type Callback<T extends IDecodedMessage> = (
|
|
113
124
|
) => void | Promise<void>;
|
114
125
|
|
115
126
|
export enum ProtocolError {
|
116
|
-
|
127
|
+
//
|
128
|
+
// GENERAL ERRORS SECTION
|
129
|
+
//
|
130
|
+
/**
|
131
|
+
* Could not determine the origin of the fault. Best to check connectivity and try again
|
132
|
+
* */
|
117
133
|
GENERIC_FAIL = "Generic error",
|
134
|
+
|
118
135
|
/**
|
119
|
-
*
|
120
|
-
*
|
136
|
+
* The remote peer rejected the message. Information provided by the remote peer
|
137
|
+
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
|
138
|
+
* or `DECODE_FAILED` can be used.
|
121
139
|
*/
|
122
|
-
|
140
|
+
REMOTE_PEER_REJECTED = "Remote peer rejected",
|
141
|
+
|
123
142
|
/**
|
124
143
|
* Failure to protobuf decode the message. May be due to a remote peer issue,
|
125
144
|
* ensuring that messages are sent via several peer enable mitigation of this error.
|
126
145
|
*/
|
127
146
|
DECODE_FAILED = "Failed to decode",
|
128
|
-
|
129
|
-
* The message payload is empty, making the message invalid. Ensure that a non-empty
|
130
|
-
* payload is set on the outgoing message.
|
131
|
-
*/
|
132
|
-
EMPTY_PAYLOAD = "Payload is empty",
|
133
|
-
/**
|
134
|
-
* The message size is above the maximum message size allowed on the Waku Network.
|
135
|
-
* Compressing the message or using an alternative strategy for large messages is recommended.
|
136
|
-
*/
|
137
|
-
SIZE_TOO_BIG = "Size is too big",
|
138
|
-
/**
|
139
|
-
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
140
|
-
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
141
|
-
*/
|
142
|
-
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
143
|
-
/**
|
144
|
-
* The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
|
145
|
-
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
146
|
-
*/
|
147
|
-
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
148
|
-
/**
|
149
|
-
* The topics passed in the decoders do not match each other, or don't exist at all.
|
150
|
-
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
151
|
-
*/
|
152
|
-
INVALID_DECODER_TOPICS = "Invalid decoder topics",
|
147
|
+
|
153
148
|
/**
|
154
149
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
155
150
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
@@ -157,47 +152,71 @@ export enum ProtocolError {
|
|
157
152
|
* on the connection manager before retrying.
|
158
153
|
*/
|
159
154
|
NO_PEER_AVAILABLE = "No peer available",
|
155
|
+
|
160
156
|
/**
|
161
157
|
* Failure to find a stream to the peer. This may be because the connection with the peer is not still alive.
|
162
158
|
* Mitigation can be: retrying after a given time period, or mitigation for `NO_PEER_AVAILABLE` can be used.
|
163
159
|
*/
|
164
160
|
NO_STREAM_AVAILABLE = "No stream available",
|
161
|
+
|
165
162
|
/**
|
166
163
|
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
|
167
164
|
* or `DECODE_FAILED` can be used.
|
168
165
|
*/
|
169
166
|
NO_RESPONSE = "No response received",
|
167
|
+
|
168
|
+
//
|
169
|
+
// SEND ERRORS SECTION
|
170
|
+
//
|
170
171
|
/**
|
171
|
-
*
|
172
|
-
*
|
173
|
-
* or `DECODE_FAILED` can be used.
|
172
|
+
* Failure to protobuf encode the message. This is not recoverable and needs
|
173
|
+
* further investigation.
|
174
174
|
*/
|
175
|
-
|
175
|
+
ENCODE_FAILED = "Failed to encode",
|
176
|
+
|
176
177
|
/**
|
177
|
-
* The
|
178
|
-
*
|
178
|
+
* The message payload is empty, making the message invalid. Ensure that a non-empty
|
179
|
+
* payload is set on the outgoing message.
|
179
180
|
*/
|
180
|
-
|
181
|
+
EMPTY_PAYLOAD = "Payload is empty",
|
182
|
+
|
181
183
|
/**
|
182
|
-
*
|
183
|
-
*
|
184
|
+
* The message size is above the maximum message size allowed on the Waku Network.
|
185
|
+
* Compressing the message or using an alternative strategy for large messages is recommended.
|
184
186
|
*/
|
185
|
-
|
187
|
+
SIZE_TOO_BIG = "Size is too big",
|
188
|
+
|
186
189
|
/**
|
187
|
-
*
|
188
|
-
*
|
190
|
+
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
191
|
+
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
189
192
|
*/
|
190
|
-
|
193
|
+
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
194
|
+
|
191
195
|
/**
|
192
|
-
*
|
193
|
-
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
|
196
|
+
* Fails when
|
194
197
|
*/
|
195
|
-
|
198
|
+
STREAM_ABORTED = "Stream aborted",
|
199
|
+
|
196
200
|
/**
|
197
201
|
* General proof generation error message.
|
198
202
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
|
199
203
|
*/
|
200
|
-
RLN_PROOF_GENERATION = "Proof generation failed"
|
204
|
+
RLN_PROOF_GENERATION = "Proof generation failed",
|
205
|
+
|
206
|
+
//
|
207
|
+
// RECEIVE ERRORS SECTION
|
208
|
+
//
|
209
|
+
/**
|
210
|
+
* The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
|
211
|
+
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
212
|
+
*/
|
213
|
+
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
214
|
+
|
215
|
+
/**
|
216
|
+
* The topics passed in the decoders do not match each other, or don't exist at all.
|
217
|
+
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
218
|
+
*/
|
219
|
+
INVALID_DECODER_TOPICS = "Invalid decoder topics"
|
201
220
|
}
|
202
221
|
|
203
222
|
export interface Failure {
|
package/src/sender.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
import type { IEncoder, IMessage } from "./message.js";
|
2
2
|
import { SDKProtocolResult } from "./protocols.js";
|
3
3
|
|
4
|
-
export type
|
4
|
+
export type ISendOptions = {
|
5
5
|
/**
|
6
6
|
* Enables retry of a message that was failed to be sent.
|
7
|
-
* @default
|
7
|
+
* @default true
|
8
8
|
*/
|
9
9
|
autoRetry?: boolean;
|
10
|
+
|
10
11
|
/**
|
11
12
|
* Sets number of attempts if `autoRetry` is enabled.
|
12
13
|
* @default 3
|
@@ -18,6 +19,6 @@ export interface ISender {
|
|
18
19
|
send: (
|
19
20
|
encoder: IEncoder,
|
20
21
|
message: IMessage,
|
21
|
-
sendOptions?:
|
22
|
+
sendOptions?: ISendOptions
|
22
23
|
) => Promise<SDKProtocolResult>;
|
23
24
|
}
|
package/src/store.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { IDecodedMessage, IDecoder } from "./message.js";
|
2
|
-
import type { IBaseProtocolCore
|
2
|
+
import type { IBaseProtocolCore } from "./protocols.js";
|
3
3
|
|
4
4
|
export type StoreCursor = Uint8Array;
|
5
5
|
|
@@ -78,7 +78,7 @@ export type QueryRequestParams = {
|
|
78
78
|
|
79
79
|
export type IStoreCore = IBaseProtocolCore;
|
80
80
|
|
81
|
-
export type IStore =
|
81
|
+
export type IStore = {
|
82
82
|
protocol: IBaseProtocolCore;
|
83
83
|
createCursor(message: IDecodedMessage): StoreCursor;
|
84
84
|
queryGenerator: <T extends IDecodedMessage>(
|
@@ -99,3 +99,7 @@ export type IStore = IBaseProtocolSDK & {
|
|
99
99
|
options?: Partial<QueryRequestParams>
|
100
100
|
) => Promise<void>;
|
101
101
|
};
|
102
|
+
|
103
|
+
export type StoreProtocolOptions = {
|
104
|
+
peer: string;
|
105
|
+
};
|
package/src/waku.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import type { PeerId, Stream } from "@libp2p/interface";
|
1
|
+
import type { Peer, PeerId, Stream } from "@libp2p/interface";
|
2
2
|
import type { MultiaddrInput } from "@multiformats/multiaddr";
|
3
3
|
|
4
|
-
import { IConnectionManager } from "./connection_manager.js";
|
4
|
+
import type { IConnectionManager } from "./connection_manager.js";
|
5
5
|
import type { IFilter } from "./filter.js";
|
6
|
-
import {
|
6
|
+
import type { IHealthIndicator } from "./health_indicator.js";
|
7
7
|
import type { Libp2p } from "./libp2p.js";
|
8
8
|
import type { ILightPush } from "./light_push.js";
|
9
|
-
import { Protocols } from "./protocols.js";
|
9
|
+
import type { Protocols } from "./protocols.js";
|
10
10
|
import type { IRelay } from "./relay.js";
|
11
11
|
import type { IStore } from "./store.js";
|
12
12
|
|
@@ -16,9 +16,8 @@ export interface IWaku {
|
|
16
16
|
store?: IStore;
|
17
17
|
filter?: IFilter;
|
18
18
|
lightPush?: ILightPush;
|
19
|
-
|
20
|
-
health: IHealthManager;
|
21
19
|
connectionManager: IConnectionManager;
|
20
|
+
health: IHealthIndicator;
|
22
21
|
|
23
22
|
/**
|
24
23
|
* Returns a unique identifier for a node on the network.
|
@@ -121,6 +120,11 @@ export interface IWaku {
|
|
121
120
|
* @returns {boolean} `true` if the node has working connection and `false` otherwise
|
122
121
|
*/
|
123
122
|
isConnected(): boolean;
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @returns {Peer[]} an array of all connected peers
|
126
|
+
*/
|
127
|
+
getConnectedPeers(): Promise<Peer[]>;
|
124
128
|
}
|
125
129
|
|
126
130
|
export interface LightNode extends IWaku {
|
package/dist/health_manager.d.ts
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
import { Protocols } from "./protocols.js";
|
2
|
-
export declare enum HealthStatus {
|
3
|
-
Unhealthy = "Unhealthy",
|
4
|
-
MinimallyHealthy = "MinimallyHealthy",
|
5
|
-
SufficientlyHealthy = "SufficientlyHealthy"
|
6
|
-
}
|
7
|
-
export interface IHealthManager {
|
8
|
-
getHealthStatus: () => HealthStatus;
|
9
|
-
getProtocolStatus: (protocol: Protocols) => ProtocolHealth | undefined;
|
10
|
-
updateProtocolHealth: (multicodec: string, connectedPeers: number) => void;
|
11
|
-
}
|
12
|
-
export type NodeHealth = {
|
13
|
-
overallStatus: HealthStatus;
|
14
|
-
protocolStatuses: ProtocolsHealthStatus;
|
15
|
-
};
|
16
|
-
export type ProtocolHealth = {
|
17
|
-
name: Protocols;
|
18
|
-
status: HealthStatus;
|
19
|
-
lastUpdate: Date;
|
20
|
-
};
|
21
|
-
export type ProtocolsHealthStatus = Map<Protocols, ProtocolHealth>;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"health_manager.js","sourceRoot":"","sources":["../src/health_manager.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,qDAAqC,CAAA;IACrC,2DAA2C,CAAA;AAC7C,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"keep_alive_manager.js","sourceRoot":"","sources":["../src/keep_alive_manager.ts"],"names":[],"mappings":""}
|
package/src/health_manager.ts
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
import { Protocols } from "./protocols.js";
|
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>;
|