@waku/core 0.0.31-ce62600.0 → 0.0.31-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/bundle/{base_protocol-C6HnrRx8.js → base_protocol-Dge5_tvU.js} +22 -25
- package/bundle/{index-DnW8ifxc.js → index-Gts2Ddu_.js} +41 -56
- package/bundle/index.js +291 -288
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-DQ9xsSLk.js → version_0-CNRKFufI.js} +154 -308
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -4
- package/dist/lib/base_protocol.js +4 -8
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +2 -2
- package/dist/lib/connection_manager.js +21 -23
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -1
- package/dist/lib/filter/index.d.ts +4 -3
- package/dist/lib/filter/index.js +33 -31
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/health_manager.d.ts +14 -0
- package/dist/lib/health_manager.js +70 -0
- package/dist/lib/health_manager.js.map +1 -0
- package/dist/lib/keep_alive_manager.d.ts +13 -7
- package/dist/lib/keep_alive_manager.js +9 -9
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +3 -2
- package/dist/lib/light_push/index.js +4 -2
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +2 -2
- package/dist/lib/metadata/index.js +26 -26
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/store/index.d.ts +5 -44
- package/dist/lib/store/index.js +39 -45
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/store/rpc.d.ts +22 -0
- package/dist/lib/store/rpc.js +74 -0
- package/dist/lib/store/rpc.js.map +1 -0
- package/dist/lib/stream_manager/index.d.ts +1 -0
- package/dist/lib/stream_manager/index.js +2 -0
- package/dist/lib/stream_manager/index.js.map +1 -0
- package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
- package/dist/lib/stream_manager/stream_manager.js.map +1 -0
- package/dist/lib/stream_manager/utils.d.ts +2 -0
- package/dist/lib/stream_manager/utils.js +19 -0
- package/dist/lib/stream_manager/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +3 -3
- package/src/lib/base_protocol.ts +7 -10
- package/src/lib/connection_manager.ts +29 -30
- package/src/lib/filter/filter_rpc.ts +21 -19
- package/src/lib/filter/index.ts +50 -52
- package/src/lib/health_manager.ts +90 -0
- package/src/lib/keep_alive_manager.ts +27 -18
- package/src/lib/light_push/index.ts +7 -10
- package/src/lib/light_push/push_rpc.ts +5 -5
- package/src/lib/message/version_0.ts +17 -15
- package/src/lib/metadata/index.ts +43 -44
- package/src/lib/store/index.ts +54 -94
- package/src/lib/store/rpc.ts +92 -0
- package/src/lib/stream_manager/index.ts +1 -0
- package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
- package/src/lib/stream_manager/utils.ts +22 -0
- package/dist/lib/store/history_rpc.d.ts +0 -27
- package/dist/lib/store/history_rpc.js +0 -72
- package/dist/lib/store/history_rpc.js.map +0 -1
- package/dist/lib/stream_manager.js.map +0 -1
- package/src/lib/store/history_rpc.ts +0 -93
- /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -8,16 +8,16 @@ import { v4 as uuid } from "uuid";
|
|
8
8
|
export class FilterPushRpc {
|
9
9
|
public constructor(public proto: proto.MessagePush) {}
|
10
10
|
|
11
|
-
static decode(bytes: Uint8Array): FilterPushRpc {
|
11
|
+
public static decode(bytes: Uint8Array): FilterPushRpc {
|
12
12
|
const res = proto.MessagePush.decode(bytes);
|
13
13
|
return new FilterPushRpc(res);
|
14
14
|
}
|
15
15
|
|
16
|
-
encode(): Uint8Array {
|
16
|
+
public encode(): Uint8Array {
|
17
17
|
return proto.MessagePush.encode(this.proto);
|
18
18
|
}
|
19
19
|
|
20
|
-
get wakuMessage(): WakuMessage | undefined {
|
20
|
+
public get wakuMessage(): WakuMessage | undefined {
|
21
21
|
return this.proto.wakuMessage;
|
22
22
|
}
|
23
23
|
|
@@ -25,7 +25,7 @@ export class FilterPushRpc {
|
|
25
25
|
* Get the pubsub topic from the FilterPushRpc object.
|
26
26
|
* @returns string
|
27
27
|
*/
|
28
|
-
get pubsubTopic(): string | undefined {
|
28
|
+
public get pubsubTopic(): string | undefined {
|
29
29
|
return this.proto.pubsubTopic;
|
30
30
|
}
|
31
31
|
}
|
@@ -33,7 +33,7 @@ export class FilterPushRpc {
|
|
33
33
|
export class FilterSubscribeRpc {
|
34
34
|
public constructor(public proto: proto.FilterSubscribeRequest) {}
|
35
35
|
|
36
|
-
static createSubscribeRequest(
|
36
|
+
public static createSubscribeRequest(
|
37
37
|
pubsubTopic: string,
|
38
38
|
contentTopics: string[]
|
39
39
|
): FilterSubscribeRpc {
|
@@ -46,7 +46,7 @@ export class FilterSubscribeRpc {
|
|
46
46
|
});
|
47
47
|
}
|
48
48
|
|
49
|
-
static createUnsubscribeRequest(
|
49
|
+
public static createUnsubscribeRequest(
|
50
50
|
pubsubTopic: string,
|
51
51
|
contentTopics: string[]
|
52
52
|
): FilterSubscribeRpc {
|
@@ -59,7 +59,9 @@ export class FilterSubscribeRpc {
|
|
59
59
|
});
|
60
60
|
}
|
61
61
|
|
62
|
-
static createUnsubscribeAllRequest(
|
62
|
+
public static createUnsubscribeAllRequest(
|
63
|
+
pubsubTopic: string
|
64
|
+
): FilterSubscribeRpc {
|
63
65
|
return new FilterSubscribeRpc({
|
64
66
|
requestId: uuid(),
|
65
67
|
filterSubscribeType:
|
@@ -69,7 +71,7 @@ export class FilterSubscribeRpc {
|
|
69
71
|
});
|
70
72
|
}
|
71
73
|
|
72
|
-
static createSubscriberPingRequest(): FilterSubscribeRpc {
|
74
|
+
public static createSubscriberPingRequest(): FilterSubscribeRpc {
|
73
75
|
return new FilterSubscribeRpc({
|
74
76
|
requestId: uuid(),
|
75
77
|
filterSubscribeType:
|
@@ -79,28 +81,28 @@ export class FilterSubscribeRpc {
|
|
79
81
|
});
|
80
82
|
}
|
81
83
|
|
82
|
-
static decode(bytes: Uint8Array): FilterSubscribeRpc {
|
84
|
+
public static decode(bytes: Uint8Array): FilterSubscribeRpc {
|
83
85
|
const res = proto.FilterSubscribeRequest.decode(bytes);
|
84
86
|
return new FilterSubscribeRpc(res);
|
85
87
|
}
|
86
88
|
|
87
|
-
encode(): Uint8Array {
|
89
|
+
public encode(): Uint8Array {
|
88
90
|
return proto.FilterSubscribeRequest.encode(this.proto);
|
89
91
|
}
|
90
92
|
|
91
|
-
get filterSubscribeType(): proto.FilterSubscribeRequest.FilterSubscribeType {
|
93
|
+
public get filterSubscribeType(): proto.FilterSubscribeRequest.FilterSubscribeType {
|
92
94
|
return this.proto.filterSubscribeType;
|
93
95
|
}
|
94
96
|
|
95
|
-
get requestId(): string {
|
97
|
+
public get requestId(): string {
|
96
98
|
return this.proto.requestId;
|
97
99
|
}
|
98
100
|
|
99
|
-
get pubsubTopic(): string | undefined {
|
101
|
+
public get pubsubTopic(): string | undefined {
|
100
102
|
return this.proto.pubsubTopic;
|
101
103
|
}
|
102
104
|
|
103
|
-
get contentTopics(): string[] {
|
105
|
+
public get contentTopics(): string[] {
|
104
106
|
return this.proto.contentTopics;
|
105
107
|
}
|
106
108
|
}
|
@@ -108,24 +110,24 @@ export class FilterSubscribeRpc {
|
|
108
110
|
export class FilterSubscribeResponse {
|
109
111
|
public constructor(public proto: proto.FilterSubscribeResponse) {}
|
110
112
|
|
111
|
-
static decode(bytes: Uint8Array): FilterSubscribeResponse {
|
113
|
+
public static decode(bytes: Uint8Array): FilterSubscribeResponse {
|
112
114
|
const res = proto.FilterSubscribeResponse.decode(bytes);
|
113
115
|
return new FilterSubscribeResponse(res);
|
114
116
|
}
|
115
117
|
|
116
|
-
encode(): Uint8Array {
|
118
|
+
public encode(): Uint8Array {
|
117
119
|
return proto.FilterSubscribeResponse.encode(this.proto);
|
118
120
|
}
|
119
121
|
|
120
|
-
get statusCode(): number {
|
122
|
+
public get statusCode(): number {
|
121
123
|
return this.proto.statusCode;
|
122
124
|
}
|
123
125
|
|
124
|
-
get statusDesc(): string | undefined {
|
126
|
+
public get statusDesc(): string | undefined {
|
125
127
|
return this.proto.statusDesc;
|
126
128
|
}
|
127
129
|
|
128
|
-
get requestId(): string {
|
130
|
+
public get requestId(): string {
|
129
131
|
return this.proto.requestId;
|
130
132
|
}
|
131
133
|
}
|
package/src/lib/filter/index.ts
CHANGED
@@ -5,7 +5,6 @@ import {
|
|
5
5
|
type CoreProtocolResult,
|
6
6
|
type IBaseProtocolCore,
|
7
7
|
type Libp2p,
|
8
|
-
type ProtocolCreateOptions,
|
9
8
|
ProtocolError,
|
10
9
|
type PubsubTopic
|
11
10
|
} from "@waku/interfaces";
|
@@ -32,21 +31,16 @@ export const FilterCodecs = {
|
|
32
31
|
};
|
33
32
|
|
34
33
|
export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
35
|
-
constructor(
|
34
|
+
public constructor(
|
36
35
|
private handleIncomingMessage: (
|
37
36
|
pubsubTopic: PubsubTopic,
|
38
|
-
wakuMessage: WakuMessage
|
37
|
+
wakuMessage: WakuMessage,
|
38
|
+
peerIdStr: string
|
39
39
|
) => Promise<void>,
|
40
|
-
|
41
|
-
|
40
|
+
public readonly pubsubTopics: PubsubTopic[],
|
41
|
+
libp2p: Libp2p
|
42
42
|
) {
|
43
|
-
super(
|
44
|
-
FilterCodecs.SUBSCRIBE,
|
45
|
-
libp2p.components,
|
46
|
-
log,
|
47
|
-
options!.pubsubTopics!,
|
48
|
-
options
|
49
|
-
);
|
43
|
+
super(FilterCodecs.SUBSCRIBE, libp2p.components, log, pubsubTopics);
|
50
44
|
|
51
45
|
libp2p
|
52
46
|
.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
@@ -57,43 +51,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
57
51
|
});
|
58
52
|
}
|
59
53
|
|
60
|
-
|
61
|
-
const { connection, stream } = streamData;
|
62
|
-
const { remotePeer } = connection;
|
63
|
-
log.info(`Received message from ${remotePeer.toString()}`);
|
64
|
-
try {
|
65
|
-
pipe(stream, lp.decode, async (source) => {
|
66
|
-
for await (const bytes of source) {
|
67
|
-
const response = FilterPushRpc.decode(bytes.slice());
|
68
|
-
|
69
|
-
const { pubsubTopic, wakuMessage } = response;
|
70
|
-
|
71
|
-
if (!wakuMessage) {
|
72
|
-
log.error("Received empty message");
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
|
76
|
-
if (!pubsubTopic) {
|
77
|
-
log.error("Pubsub topic missing from push message");
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
|
81
|
-
await this.handleIncomingMessage(pubsubTopic, wakuMessage);
|
82
|
-
}
|
83
|
-
}).then(
|
84
|
-
() => {
|
85
|
-
log.info("Receiving pipe closed.");
|
86
|
-
},
|
87
|
-
(e) => {
|
88
|
-
log.error("Error with receiving pipe", e);
|
89
|
-
}
|
90
|
-
);
|
91
|
-
} catch (e) {
|
92
|
-
log.error("Error decoding message", e);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
async subscribe(
|
54
|
+
public async subscribe(
|
97
55
|
pubsubTopic: PubsubTopic,
|
98
56
|
peer: Peer,
|
99
57
|
contentTopics: ContentTopic[]
|
@@ -147,7 +105,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
147
105
|
};
|
148
106
|
}
|
149
107
|
|
150
|
-
async unsubscribe(
|
108
|
+
public async unsubscribe(
|
151
109
|
pubsubTopic: PubsubTopic,
|
152
110
|
peer: Peer,
|
153
111
|
contentTopics: ContentTopic[]
|
@@ -193,7 +151,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
193
151
|
};
|
194
152
|
}
|
195
153
|
|
196
|
-
async unsubscribeAll(
|
154
|
+
public async unsubscribeAll(
|
197
155
|
pubsubTopic: PubsubTopic,
|
198
156
|
peer: Peer
|
199
157
|
): Promise<CoreProtocolResult> {
|
@@ -241,7 +199,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
241
199
|
};
|
242
200
|
}
|
243
201
|
|
244
|
-
async ping(peer: Peer): Promise<CoreProtocolResult> {
|
202
|
+
public async ping(peer: Peer): Promise<CoreProtocolResult> {
|
245
203
|
let stream: Stream | undefined;
|
246
204
|
try {
|
247
205
|
stream = await this.getStream(peer);
|
@@ -311,4 +269,44 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
311
269
|
failure: null
|
312
270
|
};
|
313
271
|
}
|
272
|
+
|
273
|
+
private onRequest(streamData: IncomingStreamData): void {
|
274
|
+
const { connection, stream } = streamData;
|
275
|
+
const { remotePeer } = connection;
|
276
|
+
log.info(`Received message from ${remotePeer.toString()}`);
|
277
|
+
try {
|
278
|
+
pipe(stream, lp.decode, async (source) => {
|
279
|
+
for await (const bytes of source) {
|
280
|
+
const response = FilterPushRpc.decode(bytes.slice());
|
281
|
+
|
282
|
+
const { pubsubTopic, wakuMessage } = response;
|
283
|
+
|
284
|
+
if (!wakuMessage) {
|
285
|
+
log.error("Received empty message");
|
286
|
+
return;
|
287
|
+
}
|
288
|
+
|
289
|
+
if (!pubsubTopic) {
|
290
|
+
log.error("Pubsub topic missing from push message");
|
291
|
+
return;
|
292
|
+
}
|
293
|
+
|
294
|
+
await this.handleIncomingMessage(
|
295
|
+
pubsubTopic,
|
296
|
+
wakuMessage,
|
297
|
+
connection.remotePeer.toString()
|
298
|
+
);
|
299
|
+
}
|
300
|
+
}).then(
|
301
|
+
() => {
|
302
|
+
log.info("Receiving pipe closed.");
|
303
|
+
},
|
304
|
+
(e) => {
|
305
|
+
log.error("Error with receiving pipe", e);
|
306
|
+
}
|
307
|
+
);
|
308
|
+
} catch (e) {
|
309
|
+
log.error("Error decoding message", e);
|
310
|
+
}
|
311
|
+
}
|
314
312
|
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import {
|
2
|
+
HealthStatus,
|
3
|
+
type IHealthManager,
|
4
|
+
NodeHealth,
|
5
|
+
type ProtocolHealth,
|
6
|
+
Protocols
|
7
|
+
} from "@waku/interfaces";
|
8
|
+
|
9
|
+
class HealthManager implements IHealthManager {
|
10
|
+
public static instance: HealthManager;
|
11
|
+
private readonly health: NodeHealth;
|
12
|
+
|
13
|
+
private constructor() {
|
14
|
+
this.health = {
|
15
|
+
overallStatus: HealthStatus.Unhealthy,
|
16
|
+
protocolStatuses: new Map()
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
public static getInstance(): HealthManager {
|
21
|
+
if (!HealthManager.instance) {
|
22
|
+
HealthManager.instance = new HealthManager();
|
23
|
+
}
|
24
|
+
return HealthManager.instance;
|
25
|
+
}
|
26
|
+
|
27
|
+
public getHealthStatus(): HealthStatus {
|
28
|
+
return this.health.overallStatus;
|
29
|
+
}
|
30
|
+
|
31
|
+
public getProtocolStatus(protocol: Protocols): ProtocolHealth | undefined {
|
32
|
+
return this.health.protocolStatuses.get(protocol);
|
33
|
+
}
|
34
|
+
|
35
|
+
public updateProtocolHealth(
|
36
|
+
multicodec: string,
|
37
|
+
connectedPeers: number
|
38
|
+
): void {
|
39
|
+
const protocol = this.getNameFromMulticodec(multicodec);
|
40
|
+
|
41
|
+
let status: HealthStatus = HealthStatus.Unhealthy;
|
42
|
+
if (connectedPeers == 1) {
|
43
|
+
status = HealthStatus.MinimallyHealthy;
|
44
|
+
} else if (connectedPeers >= 2) {
|
45
|
+
status = HealthStatus.SufficientlyHealthy;
|
46
|
+
}
|
47
|
+
|
48
|
+
this.health.protocolStatuses.set(protocol, {
|
49
|
+
name: protocol,
|
50
|
+
status: status,
|
51
|
+
lastUpdate: new Date()
|
52
|
+
});
|
53
|
+
|
54
|
+
this.updateOverallHealth();
|
55
|
+
}
|
56
|
+
|
57
|
+
private getNameFromMulticodec(multicodec: string): Protocols {
|
58
|
+
let name: Protocols;
|
59
|
+
if (multicodec.includes("filter")) {
|
60
|
+
name = Protocols.Filter;
|
61
|
+
} else if (multicodec.includes("lightpush")) {
|
62
|
+
name = Protocols.LightPush;
|
63
|
+
} else if (multicodec.includes("store")) {
|
64
|
+
name = Protocols.Store;
|
65
|
+
} else {
|
66
|
+
throw new Error(`Unknown protocol: ${multicodec}`);
|
67
|
+
}
|
68
|
+
return name;
|
69
|
+
}
|
70
|
+
|
71
|
+
private updateOverallHealth(): void {
|
72
|
+
const relevantProtocols = [Protocols.LightPush, Protocols.Filter];
|
73
|
+
const statuses = relevantProtocols.map(
|
74
|
+
(p) => this.getProtocolStatus(p)?.status
|
75
|
+
);
|
76
|
+
|
77
|
+
if (statuses.some((status) => status === HealthStatus.Unhealthy)) {
|
78
|
+
this.health.overallStatus = HealthStatus.Unhealthy;
|
79
|
+
} else if (
|
80
|
+
statuses.some((status) => status === HealthStatus.MinimallyHealthy)
|
81
|
+
) {
|
82
|
+
this.health.overallStatus = HealthStatus.MinimallyHealthy;
|
83
|
+
} else {
|
84
|
+
this.health.overallStatus = HealthStatus.SufficientlyHealthy;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
export const getHealthManager = (): HealthManager =>
|
90
|
+
HealthManager.getInstance();
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import type { PeerId
|
2
|
-
import type {
|
3
|
-
import type { IRelay, PeerIdStr } from "@waku/interfaces";
|
1
|
+
import type { PeerId } from "@libp2p/interface";
|
2
|
+
import type { IRelay, Libp2p, PeerIdStr } from "@waku/interfaces";
|
4
3
|
import type { KeepAliveOptions } from "@waku/interfaces";
|
5
4
|
import { Logger, pubsubTopicToSingleShardInfo } from "@waku/utils";
|
6
5
|
import { utf8ToBytes } from "@waku/utils/bytes";
|
@@ -10,24 +9,34 @@ import { createEncoder } from "./message/version_0.js";
|
|
10
9
|
export const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
11
10
|
const log = new Logger("keep-alive");
|
12
11
|
|
12
|
+
type CreateKeepAliveManagerOptions = {
|
13
|
+
options: KeepAliveOptions;
|
14
|
+
libp2p: Libp2p;
|
15
|
+
relay?: IRelay;
|
16
|
+
};
|
17
|
+
|
13
18
|
export class KeepAliveManager {
|
14
|
-
private
|
15
|
-
private
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
private readonly relay?: IRelay;
|
20
|
+
private readonly libp2p: Libp2p;
|
21
|
+
|
22
|
+
private readonly options: KeepAliveOptions;
|
23
|
+
|
24
|
+
private pingKeepAliveTimers: Map<string, ReturnType<typeof setInterval>> =
|
25
|
+
new Map();
|
26
|
+
private relayKeepAliveTimers: Map<PeerId, ReturnType<typeof setInterval>[]> =
|
27
|
+
new Map();
|
28
|
+
|
29
|
+
public constructor({
|
30
|
+
options,
|
31
|
+
relay,
|
32
|
+
libp2p
|
33
|
+
}: CreateKeepAliveManagerOptions) {
|
22
34
|
this.options = options;
|
23
35
|
this.relay = relay;
|
36
|
+
this.libp2p = libp2p;
|
24
37
|
}
|
25
38
|
|
26
|
-
public start(
|
27
|
-
peerId: PeerId,
|
28
|
-
libp2pPing: PingService,
|
29
|
-
peerStore: PeerStore
|
30
|
-
): void {
|
39
|
+
public start(peerId: PeerId): void {
|
31
40
|
// Just in case a timer already exists for this peer
|
32
41
|
this.stop(peerId);
|
33
42
|
|
@@ -46,7 +55,7 @@ export class KeepAliveManager {
|
|
46
55
|
// ping the peer for keep alive
|
47
56
|
// also update the peer store with the latency
|
48
57
|
try {
|
49
|
-
ping = await
|
58
|
+
ping = await this.libp2p.services.ping.ping(peerId);
|
50
59
|
log.info(`Ping succeeded (${peerIdStr})`, ping);
|
51
60
|
} catch (error) {
|
52
61
|
log.error(`Ping failed for peer (${peerIdStr}).
|
@@ -56,7 +65,7 @@ export class KeepAliveManager {
|
|
56
65
|
}
|
57
66
|
|
58
67
|
try {
|
59
|
-
await peerStore.merge(peerId, {
|
68
|
+
await this.libp2p.peerStore.merge(peerId, {
|
60
69
|
metadata: {
|
61
70
|
ping: utf8ToBytes(ping.toString())
|
62
71
|
}
|
@@ -5,8 +5,8 @@ import {
|
|
5
5
|
type IEncoder,
|
6
6
|
type IMessage,
|
7
7
|
type Libp2p,
|
8
|
-
type ProtocolCreateOptions,
|
9
8
|
ProtocolError,
|
9
|
+
PubsubTopic,
|
10
10
|
type ThisOrThat
|
11
11
|
} from "@waku/interfaces";
|
12
12
|
import { PushResponse } from "@waku/proto";
|
@@ -32,14 +32,11 @@ type PreparePushMessageResult = ThisOrThat<"query", PushRpc>;
|
|
32
32
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
33
33
|
*/
|
34
34
|
export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
35
|
-
constructor(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
options!.pubsubTopics!,
|
41
|
-
options
|
42
|
-
);
|
35
|
+
public constructor(
|
36
|
+
public readonly pubsubTopics: PubsubTopic[],
|
37
|
+
libp2p: Libp2p
|
38
|
+
) {
|
39
|
+
super(LightPushCodec, libp2p.components, log, pubsubTopics);
|
43
40
|
}
|
44
41
|
|
45
42
|
private async preparePushMessage(
|
@@ -78,7 +75,7 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|
78
75
|
}
|
79
76
|
}
|
80
77
|
|
81
|
-
async send(
|
78
|
+
public async send(
|
82
79
|
encoder: IEncoder,
|
83
80
|
message: IMessage,
|
84
81
|
peer: Peer
|
@@ -5,7 +5,7 @@ import { v4 as uuid } from "uuid";
|
|
5
5
|
export class PushRpc {
|
6
6
|
public constructor(public proto: proto.PushRpc) {}
|
7
7
|
|
8
|
-
static createRequest(
|
8
|
+
public static createRequest(
|
9
9
|
message: proto.WakuMessage,
|
10
10
|
pubsubTopic: string
|
11
11
|
): PushRpc {
|
@@ -19,20 +19,20 @@ export class PushRpc {
|
|
19
19
|
});
|
20
20
|
}
|
21
21
|
|
22
|
-
static decode(bytes: Uint8ArrayList): PushRpc {
|
22
|
+
public static decode(bytes: Uint8ArrayList): PushRpc {
|
23
23
|
const res = proto.PushRpc.decode(bytes);
|
24
24
|
return new PushRpc(res);
|
25
25
|
}
|
26
26
|
|
27
|
-
encode(): Uint8Array {
|
27
|
+
public encode(): Uint8Array {
|
28
28
|
return proto.PushRpc.encode(this.proto);
|
29
29
|
}
|
30
30
|
|
31
|
-
get query(): proto.PushRequest | undefined {
|
31
|
+
public get query(): proto.PushRequest | undefined {
|
32
32
|
return this.proto.request;
|
33
33
|
}
|
34
34
|
|
35
|
-
get response(): proto.PushResponse | undefined {
|
35
|
+
public get response(): proto.PushResponse | undefined {
|
36
36
|
return this.proto.response;
|
37
37
|
}
|
38
38
|
}
|
@@ -20,28 +20,28 @@ export const Version = 0;
|
|
20
20
|
export { proto };
|
21
21
|
|
22
22
|
export class DecodedMessage implements IDecodedMessage {
|
23
|
-
constructor(
|
23
|
+
public constructor(
|
24
24
|
public pubsubTopic: string,
|
25
25
|
protected proto: proto.WakuMessage
|
26
26
|
) {}
|
27
27
|
|
28
|
-
get ephemeral(): boolean {
|
28
|
+
public get ephemeral(): boolean {
|
29
29
|
return Boolean(this.proto.ephemeral);
|
30
30
|
}
|
31
31
|
|
32
|
-
get payload(): Uint8Array {
|
32
|
+
public get payload(): Uint8Array {
|
33
33
|
return this.proto.payload;
|
34
34
|
}
|
35
35
|
|
36
|
-
get contentTopic(): string {
|
36
|
+
public get contentTopic(): string {
|
37
37
|
return this.proto.contentTopic;
|
38
38
|
}
|
39
39
|
|
40
|
-
get _rawTimestamp(): bigint | undefined {
|
40
|
+
public get _rawTimestamp(): bigint | undefined {
|
41
41
|
return this.proto.timestamp;
|
42
42
|
}
|
43
43
|
|
44
|
-
get timestamp(): Date | undefined {
|
44
|
+
public get timestamp(): Date | undefined {
|
45
45
|
// In the case we receive a value that is bigger than JS's max number,
|
46
46
|
// we catch the error and return undefined.
|
47
47
|
try {
|
@@ -56,23 +56,23 @@ export class DecodedMessage implements IDecodedMessage {
|
|
56
56
|
}
|
57
57
|
}
|
58
58
|
|
59
|
-
get meta(): Uint8Array | undefined {
|
59
|
+
public get meta(): Uint8Array | undefined {
|
60
60
|
return this.proto.meta;
|
61
61
|
}
|
62
62
|
|
63
|
-
get version(): number {
|
63
|
+
public get version(): number {
|
64
64
|
// https://rfc.vac.dev/spec/14/
|
65
65
|
// > If omitted, the value SHOULD be interpreted as version 0.
|
66
66
|
return this.proto.version ?? 0;
|
67
67
|
}
|
68
68
|
|
69
|
-
get rateLimitProof(): IRateLimitProof | undefined {
|
69
|
+
public get rateLimitProof(): IRateLimitProof | undefined {
|
70
70
|
return this.proto.rateLimitProof;
|
71
71
|
}
|
72
72
|
}
|
73
73
|
|
74
74
|
export class Encoder implements IEncoder {
|
75
|
-
constructor(
|
75
|
+
public constructor(
|
76
76
|
public contentTopic: string,
|
77
77
|
public ephemeral: boolean = false,
|
78
78
|
public pubsubTopic: PubsubTopic,
|
@@ -83,11 +83,11 @@ export class Encoder implements IEncoder {
|
|
83
83
|
}
|
84
84
|
}
|
85
85
|
|
86
|
-
async toWire(message: IMessage): Promise<Uint8Array> {
|
86
|
+
public async toWire(message: IMessage): Promise<Uint8Array> {
|
87
87
|
return proto.WakuMessage.encode(await this.toProtoObj(message));
|
88
88
|
}
|
89
89
|
|
90
|
-
async toProtoObj(message: IMessage): Promise<IProtoMessage> {
|
90
|
+
public async toProtoObj(message: IMessage): Promise<IProtoMessage> {
|
91
91
|
const timestamp = message.timestamp ?? new Date();
|
92
92
|
|
93
93
|
const protoMessage = {
|
@@ -133,7 +133,7 @@ export function createEncoder({
|
|
133
133
|
}
|
134
134
|
|
135
135
|
export class Decoder implements IDecoder<DecodedMessage> {
|
136
|
-
constructor(
|
136
|
+
public constructor(
|
137
137
|
public pubsubTopic: PubsubTopic,
|
138
138
|
public contentTopic: string
|
139
139
|
) {
|
@@ -142,7 +142,9 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|
142
142
|
}
|
143
143
|
}
|
144
144
|
|
145
|
-
fromWireToProtoObj(
|
145
|
+
public fromWireToProtoObj(
|
146
|
+
bytes: Uint8Array
|
147
|
+
): Promise<IProtoMessage | undefined> {
|
146
148
|
const protoMessage = proto.WakuMessage.decode(bytes);
|
147
149
|
return Promise.resolve({
|
148
150
|
payload: protoMessage.payload,
|
@@ -155,7 +157,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|
155
157
|
});
|
156
158
|
}
|
157
159
|
|
158
|
-
async fromProtoObj(
|
160
|
+
public async fromProtoObj(
|
159
161
|
pubsubTopic: string,
|
160
162
|
proto: IProtoMessage
|
161
163
|
): Promise<DecodedMessage | undefined> {
|