@waku/interfaces 0.0.28-f599932.0 → 0.0.29-00f2e75.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/CHANGELOG.md +20 -0
- 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 +27 -12
- 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 +18 -3
- package/dist/protocols.d.ts +68 -79
- package/dist/protocols.js +40 -45
- package/dist/protocols.js.map +1 -1
- package/dist/relay.d.ts +1 -0
- package/dist/sender.d.ts +14 -2
- package/dist/store.d.ts +5 -2
- package/dist/waku.d.ts +110 -17
- package/package.json +1 -1
- package/src/connection_manager.ts +31 -8
- package/src/filter.ts +32 -22
- package/src/health_indicator.ts +24 -0
- package/src/index.ts +1 -2
- package/src/light_push.ts +22 -4
- package/src/protocols.ts +102 -83
- package/src/relay.ts +1 -0
- package/src/sender.ts +16 -2
- package/src/store.ts +6 -2
- package/src/waku.ts +113 -18
- 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/filter.ts
CHANGED
@@ -5,9 +5,7 @@ import type { ContentTopic, ThisOrThat } from "./misc.js";
|
|
5
5
|
import type {
|
6
6
|
Callback,
|
7
7
|
IBaseProtocolCore,
|
8
|
-
IBaseProtocolSDK,
|
9
8
|
ProtocolError,
|
10
|
-
ProtocolUseOptions,
|
11
9
|
SDKProtocolResult
|
12
10
|
} from "./protocols.js";
|
13
11
|
import type { IReceiver } from "./receiver.js";
|
@@ -17,19 +15,34 @@ export type SubscriptionCallback<T extends IDecodedMessage> = {
|
|
17
15
|
callback: Callback<T>;
|
18
16
|
};
|
19
17
|
|
20
|
-
export type
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
export type FilterProtocolOptions = {
|
19
|
+
/**
|
20
|
+
* Interval with which Filter subscription will attempt to send ping requests to subscribed peers.
|
21
|
+
*
|
22
|
+
* @default 60_000
|
23
|
+
*/
|
24
|
+
keepAliveIntervalMs: number;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Number of failed pings allowed to make to a remote peer before attempting to subscribe to a new one.
|
28
|
+
*
|
29
|
+
* @default 3
|
30
|
+
*/
|
31
|
+
pingsBeforePeerRenewed: number;
|
25
32
|
|
26
|
-
|
33
|
+
/**
|
34
|
+
* Enables js-waku to send probe LightPush message over subscribed pubsubTopics on created subscription.
|
35
|
+
* In case message won't be received back through Filter - js-waku will attempt to subscribe to another peer.
|
36
|
+
*
|
37
|
+
* @default false
|
38
|
+
*/
|
39
|
+
enableLightPushFilterCheck: boolean;
|
40
|
+
};
|
27
41
|
|
28
|
-
export interface
|
42
|
+
export interface ISubscription {
|
29
43
|
subscribe<T extends IDecodedMessage>(
|
30
44
|
decoders: IDecoder<T> | IDecoder<T>[],
|
31
|
-
callback: Callback<T
|
32
|
-
options?: SubscribeOptions
|
45
|
+
callback: Callback<T>
|
33
46
|
): Promise<SDKProtocolResult>;
|
34
47
|
|
35
48
|
unsubscribe(contentTopics: ContentTopic[]): Promise<SDKProtocolResult>;
|
@@ -39,20 +52,17 @@ export interface ISubscriptionSDK {
|
|
39
52
|
unsubscribeAll(): Promise<SDKProtocolResult>;
|
40
53
|
}
|
41
54
|
|
42
|
-
export type
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
subscribeOptions?: SubscribeOptions
|
49
|
-
): Promise<SubscribeResult>;
|
50
|
-
};
|
55
|
+
export type IFilter = IReceiver & { protocol: IBaseProtocolCore } & {
|
56
|
+
subscribe<T extends IDecodedMessage>(
|
57
|
+
decoders: IDecoder<T> | IDecoder<T>[],
|
58
|
+
callback: Callback<T>
|
59
|
+
): Promise<SubscribeResult>;
|
60
|
+
};
|
51
61
|
|
52
62
|
export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
|
53
63
|
|
54
64
|
type SubscriptionSuccess = {
|
55
|
-
subscription:
|
65
|
+
subscription: ISubscription;
|
56
66
|
error: null;
|
57
67
|
results: SDKProtocolResult;
|
58
68
|
};
|
@@ -65,7 +75,7 @@ type SubscriptionError = {
|
|
65
75
|
|
66
76
|
export type CreateSubscriptionResult = ThisOrThat<
|
67
77
|
"subscription",
|
68
|
-
|
78
|
+
ISubscription,
|
69
79
|
"error",
|
70
80
|
ProtocolError
|
71
81
|
>;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { TypedEventEmitter } from "@libp2p/interface";
|
2
|
+
|
3
|
+
import { Libp2p } from "./libp2p.js";
|
4
|
+
|
5
|
+
export enum HealthStatusChangeEvents {
|
6
|
+
StatusChange = "health:change"
|
7
|
+
}
|
8
|
+
|
9
|
+
export enum HealthStatus {
|
10
|
+
Unhealthy = "Unhealthy",
|
11
|
+
MinimallyHealthy = "MinimallyHealthy",
|
12
|
+
SufficientlyHealthy = "SufficientlyHealthy"
|
13
|
+
}
|
14
|
+
|
15
|
+
export type HealthIndicatorEvents = {
|
16
|
+
[HealthStatusChangeEvents.StatusChange]: CustomEvent<HealthStatus>;
|
17
|
+
};
|
18
|
+
|
19
|
+
export interface IHealthIndicator
|
20
|
+
extends TypedEventEmitter<HealthIndicatorEvents> {}
|
21
|
+
|
22
|
+
export type HealthIndicatorParams = {
|
23
|
+
libp2p: Libp2p;
|
24
|
+
};
|
package/src/index.ts
CHANGED
@@ -12,10 +12,9 @@ export * from "./sender.js";
|
|
12
12
|
export * from "./receiver.js";
|
13
13
|
export * from "./misc.js";
|
14
14
|
export * from "./libp2p.js";
|
15
|
-
export * from "./keep_alive_manager.js";
|
16
15
|
export * from "./dns_discovery.js";
|
17
16
|
export * from "./metadata.js";
|
18
17
|
export * from "./constants.js";
|
19
18
|
export * from "./local_storage.js";
|
20
|
-
export * from "./health_manager.js";
|
21
19
|
export * from "./sharding.js";
|
20
|
+
export * from "./health_indicator.js";
|
package/src/light_push.ts
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
-
import { IBaseProtocolCore
|
2
|
-
import type { ISender } from "./sender.js";
|
1
|
+
import { IBaseProtocolCore } from "./protocols.js";
|
2
|
+
import type { ISender, ISendOptions } from "./sender.js";
|
3
3
|
|
4
|
-
export type
|
5
|
-
|
4
|
+
export type LightPushProtocolOptions = ISendOptions & {
|
5
|
+
/**
|
6
|
+
* The interval in milliseconds to wait before retrying a failed push.
|
7
|
+
* @default 1000
|
8
|
+
*/
|
9
|
+
retryIntervalMs: number;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Number of peers to send message to.
|
13
|
+
*
|
14
|
+
* @default 1
|
15
|
+
*/
|
16
|
+
numPeersToUse?: number;
|
17
|
+
};
|
18
|
+
|
19
|
+
export type ILightPush = ISender & {
|
20
|
+
start: () => void;
|
21
|
+
stop: () => void;
|
22
|
+
protocol: IBaseProtocolCore;
|
23
|
+
};
|
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: (withOpenStreams?: boolean) => 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 3.
|
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/relay.ts
CHANGED
package/src/sender.ts
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
import type { IEncoder, IMessage } from "./message.js";
|
2
|
-
import {
|
2
|
+
import { SDKProtocolResult } from "./protocols.js";
|
3
|
+
|
4
|
+
export type ISendOptions = {
|
5
|
+
/**
|
6
|
+
* Enables retry of a message that was failed to be sent.
|
7
|
+
* @default true
|
8
|
+
*/
|
9
|
+
autoRetry?: boolean;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Sets number of attempts if `autoRetry` is enabled.
|
13
|
+
* @default 3
|
14
|
+
*/
|
15
|
+
maxAttempts?: number;
|
16
|
+
};
|
3
17
|
|
4
18
|
export interface ISender {
|
5
19
|
send: (
|
6
20
|
encoder: IEncoder,
|
7
21
|
message: IMessage,
|
8
|
-
sendOptions?:
|
22
|
+
sendOptions?: ISendOptions
|
9
23
|
) => Promise<SDKProtocolResult>;
|
10
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
|
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 IStoreSDK = 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,45 +1,140 @@
|
|
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";
|
5
|
-
import type {
|
6
|
-
import {
|
4
|
+
import type { IConnectionManager } from "./connection_manager.js";
|
5
|
+
import type { IFilter } from "./filter.js";
|
6
|
+
import type { IHealthIndicator } from "./health_indicator.js";
|
7
7
|
import type { Libp2p } from "./libp2p.js";
|
8
|
-
import type {
|
9
|
-
import { Protocols } from "./protocols.js";
|
8
|
+
import type { ILightPush } from "./light_push.js";
|
9
|
+
import type { Protocols } from "./protocols.js";
|
10
10
|
import type { IRelay } from "./relay.js";
|
11
|
-
import type {
|
11
|
+
import type { IStore } from "./store.js";
|
12
12
|
|
13
|
-
export interface
|
13
|
+
export interface IWaku {
|
14
14
|
libp2p: Libp2p;
|
15
15
|
relay?: IRelay;
|
16
|
-
store?:
|
17
|
-
filter?:
|
18
|
-
lightPush?:
|
19
|
-
|
16
|
+
store?: IStore;
|
17
|
+
filter?: IFilter;
|
18
|
+
lightPush?: ILightPush;
|
20
19
|
connectionManager: IConnectionManager;
|
20
|
+
health: IHealthIndicator;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Returns a unique identifier for a node on the network.
|
24
|
+
*
|
25
|
+
* @example
|
26
|
+
* ```typescript
|
27
|
+
* console.log(waku.peerId); // 12D3KooWNmk9yXHfHJ4rUduRqD1TCTHkNFMPF9WP2dqWpZDL4aUb
|
28
|
+
* ```
|
29
|
+
*/
|
30
|
+
peerId: PeerId;
|
21
31
|
|
32
|
+
/**
|
33
|
+
* Returns a list of supported protocols.
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
* ```typescript
|
37
|
+
* console.log(waku.protocols); // ['/ipfs/id/1.0.0', '/ipfs/ping/1.0.0', '/vac/waku/filter-push/2.0.0-beta1', '/vac/waku/metadata/1.0.0']
|
38
|
+
* ```
|
39
|
+
*/
|
40
|
+
protocols: string[];
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Dials to the provided peer
|
44
|
+
*
|
45
|
+
* @param {PeerId | MultiaddrInput} peer information to use for dialing
|
46
|
+
* @param {Protocols[]} [protocols] array of Waku protocols to be used for dialing. If no provided - will be derived from mounted protocols.
|
47
|
+
*
|
48
|
+
* @returns {Promise<Stream>} `Promise` that will resolve to a `Stream` to a dialed peer
|
49
|
+
*
|
50
|
+
* @example
|
51
|
+
* ```typescript
|
52
|
+
* await waku.dial(remotePeerId, [Protocols.LightPush]);
|
53
|
+
*
|
54
|
+
* waku.isConnected() === true;
|
55
|
+
* ```
|
56
|
+
*/
|
22
57
|
dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise<Stream>;
|
23
58
|
|
59
|
+
/**
|
60
|
+
* Starts all services and components related to functionality of Waku node.
|
61
|
+
*
|
62
|
+
* @returns {Promise<boolean>} `Promise` that will resolve when started.
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
* ```typescript
|
66
|
+
* await waku.start();
|
67
|
+
*
|
68
|
+
* waku.isStarted() === true;
|
69
|
+
* ```
|
70
|
+
*/
|
24
71
|
start(): Promise<void>;
|
25
72
|
|
73
|
+
/**
|
74
|
+
* Stops all recurring processes and services that are needed for functionality of Waku node.
|
75
|
+
*
|
76
|
+
* @returns {Promise<boolean>} `Promise` that resolves when stopped.
|
77
|
+
*
|
78
|
+
* @example
|
79
|
+
* ```typescript
|
80
|
+
* await waku.stop();
|
81
|
+
*
|
82
|
+
* waku.isStarted === false;
|
83
|
+
* ```
|
84
|
+
*/
|
26
85
|
stop(): Promise<void>;
|
27
86
|
|
87
|
+
/**
|
88
|
+
* Resolves when Waku successfully gains connection to a remote peers that fits provided requirements.
|
89
|
+
* Must be used after attempting to connect to nodes, using {@link IWaku.dial} or
|
90
|
+
* if was bootstrapped by using {@link IPeerExchange} or {@link DnsDiscoveryComponents}.
|
91
|
+
*
|
92
|
+
* @param {Protocols[]} [protocols] Protocols that need to be enabled by remote peers
|
93
|
+
* @param {number} [timeoutMs] Timeout value in milliseconds after which promise rejects
|
94
|
+
*
|
95
|
+
* @returns {Promise<void>} `Promise` that **resolves** if all desired protocols are fulfilled by
|
96
|
+
* at least one remote peer, **rejects** if the timeoutMs is reached
|
97
|
+
* @throws If passing a protocol that is not mounted or Waku node is not started
|
98
|
+
*
|
99
|
+
* @example
|
100
|
+
* ```typescript
|
101
|
+
* try {
|
102
|
+
* // let's wait for at least one LightPush node and timeout in 1 second
|
103
|
+
* await waku.waitForPeers([Protocols.LightPush], 1000);
|
104
|
+
* } catch(e) {
|
105
|
+
* waku.isConnected() === false;
|
106
|
+
* console.error("Failed to connect due to", e);
|
107
|
+
* }
|
108
|
+
*
|
109
|
+
* waku.isConnected() === true;
|
110
|
+
* ```
|
111
|
+
*/
|
112
|
+
waitForPeers(protocols?: Protocols[], timeoutMs?: number): Promise<void>;
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @returns {boolean} `true` if the node was started and `false` otherwise
|
116
|
+
*/
|
28
117
|
isStarted(): boolean;
|
29
118
|
|
119
|
+
/**
|
120
|
+
* @returns {boolean} `true` if the node has working connection and `false` otherwise
|
121
|
+
*/
|
30
122
|
isConnected(): boolean;
|
31
123
|
|
32
|
-
|
124
|
+
/**
|
125
|
+
* @returns {Peer[]} an array of all connected peers
|
126
|
+
*/
|
127
|
+
getConnectedPeers(): Promise<Peer[]>;
|
33
128
|
}
|
34
129
|
|
35
|
-
export interface LightNode extends
|
130
|
+
export interface LightNode extends IWaku {
|
36
131
|
relay: undefined;
|
37
|
-
store:
|
38
|
-
filter:
|
39
|
-
lightPush:
|
132
|
+
store: IStore;
|
133
|
+
filter: IFilter;
|
134
|
+
lightPush: ILightPush;
|
40
135
|
}
|
41
136
|
|
42
|
-
export interface RelayNode extends
|
137
|
+
export interface RelayNode extends IWaku {
|
43
138
|
relay: IRelay;
|
44
139
|
store: undefined;
|
45
140
|
filter: undefined;
|