@waku/core 0.0.39-9684e7b.0 → 0.0.39-c0ee9ec.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/index.js +497 -256
- package/bundle/lib/message/version_0.js +1 -1
- package/bundle/{version_0-DV1Db0r-.js → version_0-DQUncDnb.js} +3 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/connection_manager/connection_limiter.js +3 -3
- package/dist/lib/connection_manager/connection_limiter.js.map +1 -1
- package/dist/lib/connection_manager/network_monitor.js +1 -2
- package/dist/lib/connection_manager/network_monitor.js.map +1 -1
- package/dist/lib/filter/filter.d.ts +6 -6
- package/dist/lib/filter/filter.js +14 -14
- package/dist/lib/filter/filter.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +1 -1
- package/dist/lib/light_push/index.js +1 -1
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +8 -6
- package/dist/lib/light_push/light_push.js +40 -79
- package/dist/lib/light_push/light_push.js.map +1 -1
- package/dist/lib/light_push/protocol_handler.d.ts +27 -0
- package/dist/lib/light_push/protocol_handler.js +145 -0
- package/dist/lib/light_push/protocol_handler.js.map +1 -0
- package/dist/lib/light_push/push_rpc.d.ts +3 -3
- package/dist/lib/light_push/push_rpc.js +3 -3
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/light_push/push_rpc_v3.d.ts +73 -0
- package/dist/lib/light_push/push_rpc_v3.js +136 -0
- package/dist/lib/light_push/push_rpc_v3.js.map +1 -0
- package/dist/lib/metadata/metadata.js +1 -1
- package/dist/lib/metadata/metadata.js.map +1 -1
- package/dist/lib/store/store.d.ts +1 -1
- package/dist/lib/store/store.js +1 -1
- package/dist/lib/store/store.js.map +1 -1
- package/dist/lib/stream_manager/stream_manager.d.ts +1 -1
- package/dist/lib/stream_manager/stream_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/lib/connection_manager/connection_limiter.ts +3 -7
- package/src/lib/connection_manager/network_monitor.ts +2 -2
- package/src/lib/filter/filter.ts +19 -19
- package/src/lib/light_push/index.ts +5 -1
- package/src/lib/light_push/light_push.ts +59 -106
- package/src/lib/light_push/protocol_handler.ts +192 -0
- package/src/lib/light_push/push_rpc.ts +5 -5
- package/src/lib/light_push/push_rpc_v3.ts +162 -0
- package/src/lib/metadata/metadata.ts +1 -1
- package/src/lib/store/store.ts +1 -1
- package/src/lib/stream_manager/stream_manager.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PeerId } from "@libp2p/interface";
|
|
2
|
-
import { type ContentTopic, type
|
|
2
|
+
import { type ContentTopic, type FilterCoreResult, type Libp2p, type PubsubTopic } from "@waku/interfaces";
|
|
3
3
|
import { WakuMessage } from "@waku/proto";
|
|
4
4
|
export declare const FilterCodecs: {
|
|
5
5
|
SUBSCRIBE: string;
|
|
@@ -9,12 +9,12 @@ type IncomingMessageHandler = (pubsubTopic: PubsubTopic, wakuMessage: WakuMessag
|
|
|
9
9
|
export declare class FilterCore {
|
|
10
10
|
private handleIncomingMessage;
|
|
11
11
|
private streamManager;
|
|
12
|
-
readonly multicodec: string;
|
|
12
|
+
readonly multicodec: string[];
|
|
13
13
|
constructor(handleIncomingMessage: IncomingMessageHandler, libp2p: Libp2p);
|
|
14
|
-
subscribe(pubsubTopic: PubsubTopic, peerId: PeerId, contentTopics: ContentTopic[]): Promise<
|
|
15
|
-
unsubscribe(pubsubTopic: PubsubTopic, peerId: PeerId, contentTopics: ContentTopic[]): Promise<
|
|
16
|
-
unsubscribeAll(pubsubTopic: PubsubTopic, peerId: PeerId): Promise<
|
|
17
|
-
ping(peerId: PeerId): Promise<
|
|
14
|
+
subscribe(pubsubTopic: PubsubTopic, peerId: PeerId, contentTopics: ContentTopic[]): Promise<FilterCoreResult>;
|
|
15
|
+
unsubscribe(pubsubTopic: PubsubTopic, peerId: PeerId, contentTopics: ContentTopic[]): Promise<FilterCoreResult>;
|
|
16
|
+
unsubscribeAll(pubsubTopic: PubsubTopic, peerId: PeerId): Promise<FilterCoreResult>;
|
|
17
|
+
ping(peerId: PeerId): Promise<FilterCoreResult>;
|
|
18
18
|
private onRequest;
|
|
19
19
|
}
|
|
20
20
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterError } from "@waku/interfaces";
|
|
2
2
|
import { Logger } from "@waku/utils";
|
|
3
3
|
import all from "it-all";
|
|
4
4
|
import * as lp from "it-length-prefixed";
|
|
@@ -13,7 +13,7 @@ export const FilterCodecs = {
|
|
|
13
13
|
export class FilterCore {
|
|
14
14
|
handleIncomingMessage;
|
|
15
15
|
streamManager;
|
|
16
|
-
multicodec = FilterCodecs.SUBSCRIBE;
|
|
16
|
+
multicodec = [FilterCodecs.SUBSCRIBE];
|
|
17
17
|
constructor(handleIncomingMessage, libp2p) {
|
|
18
18
|
this.handleIncomingMessage = handleIncomingMessage;
|
|
19
19
|
this.streamManager = new StreamManager(FilterCodecs.SUBSCRIBE, libp2p.components);
|
|
@@ -31,7 +31,7 @@ export class FilterCore {
|
|
|
31
31
|
return {
|
|
32
32
|
success: null,
|
|
33
33
|
failure: {
|
|
34
|
-
error:
|
|
34
|
+
error: FilterError.NO_STREAM_AVAILABLE,
|
|
35
35
|
peerId: peerId
|
|
36
36
|
}
|
|
37
37
|
};
|
|
@@ -49,7 +49,7 @@ export class FilterCore {
|
|
|
49
49
|
return {
|
|
50
50
|
success: null,
|
|
51
51
|
failure: {
|
|
52
|
-
error:
|
|
52
|
+
error: FilterError.GENERIC_FAIL,
|
|
53
53
|
peerId: peerId
|
|
54
54
|
}
|
|
55
55
|
};
|
|
@@ -59,7 +59,7 @@ export class FilterCore {
|
|
|
59
59
|
log.error(`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
|
60
60
|
return {
|
|
61
61
|
failure: {
|
|
62
|
-
error:
|
|
62
|
+
error: FilterError.REMOTE_PEER_REJECTED,
|
|
63
63
|
peerId: peerId
|
|
64
64
|
},
|
|
65
65
|
success: null
|
|
@@ -77,7 +77,7 @@ export class FilterCore {
|
|
|
77
77
|
return {
|
|
78
78
|
success: null,
|
|
79
79
|
failure: {
|
|
80
|
-
error:
|
|
80
|
+
error: FilterError.NO_STREAM_AVAILABLE,
|
|
81
81
|
peerId: peerId
|
|
82
82
|
}
|
|
83
83
|
};
|
|
@@ -91,7 +91,7 @@ export class FilterCore {
|
|
|
91
91
|
return {
|
|
92
92
|
success: null,
|
|
93
93
|
failure: {
|
|
94
|
-
error:
|
|
94
|
+
error: FilterError.GENERIC_FAIL,
|
|
95
95
|
peerId: peerId
|
|
96
96
|
}
|
|
97
97
|
};
|
|
@@ -108,7 +108,7 @@ export class FilterCore {
|
|
|
108
108
|
return {
|
|
109
109
|
success: null,
|
|
110
110
|
failure: {
|
|
111
|
-
error:
|
|
111
|
+
error: FilterError.NO_STREAM_AVAILABLE,
|
|
112
112
|
peerId: peerId
|
|
113
113
|
}
|
|
114
114
|
};
|
|
@@ -118,7 +118,7 @@ export class FilterCore {
|
|
|
118
118
|
if (!res || !res.length) {
|
|
119
119
|
return {
|
|
120
120
|
failure: {
|
|
121
|
-
error:
|
|
121
|
+
error: FilterError.NO_RESPONSE,
|
|
122
122
|
peerId: peerId
|
|
123
123
|
},
|
|
124
124
|
success: null
|
|
@@ -129,7 +129,7 @@ export class FilterCore {
|
|
|
129
129
|
log.error(`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
|
130
130
|
return {
|
|
131
131
|
failure: {
|
|
132
|
-
error:
|
|
132
|
+
error: FilterError.REMOTE_PEER_REJECTED,
|
|
133
133
|
peerId: peerId
|
|
134
134
|
},
|
|
135
135
|
success: null
|
|
@@ -147,7 +147,7 @@ export class FilterCore {
|
|
|
147
147
|
return {
|
|
148
148
|
success: null,
|
|
149
149
|
failure: {
|
|
150
|
-
error:
|
|
150
|
+
error: FilterError.NO_STREAM_AVAILABLE,
|
|
151
151
|
peerId: peerId
|
|
152
152
|
}
|
|
153
153
|
};
|
|
@@ -162,7 +162,7 @@ export class FilterCore {
|
|
|
162
162
|
return {
|
|
163
163
|
success: null,
|
|
164
164
|
failure: {
|
|
165
|
-
error:
|
|
165
|
+
error: FilterError.GENERIC_FAIL,
|
|
166
166
|
peerId: peerId
|
|
167
167
|
}
|
|
168
168
|
};
|
|
@@ -171,7 +171,7 @@ export class FilterCore {
|
|
|
171
171
|
return {
|
|
172
172
|
success: null,
|
|
173
173
|
failure: {
|
|
174
|
-
error:
|
|
174
|
+
error: FilterError.NO_RESPONSE,
|
|
175
175
|
peerId: peerId
|
|
176
176
|
}
|
|
177
177
|
};
|
|
@@ -182,7 +182,7 @@ export class FilterCore {
|
|
|
182
182
|
return {
|
|
183
183
|
success: null,
|
|
184
184
|
failure: {
|
|
185
|
-
error:
|
|
185
|
+
error: FilterError.REMOTE_PEER_REJECTED,
|
|
186
186
|
peerId: peerId
|
|
187
187
|
}
|
|
188
188
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/lib/filter/filter.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/lib/filter/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,WAAW,EAGZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG/B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EACnB,MAAM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AE;gBACV,GAAG,CAAC,KAAK,CACP,qCAAqC,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,cAAc,MAAM,CAAC,EAAE,gBAAgB,MAAM,CAAC,QAAQ,IAAI,EAC/H,CAAC,CACF,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { LightPushCore, LightPushCodec,
|
|
1
|
+
export { LightPushCore, LightPushCodec, LightPushCodecV2 } from "./light_push.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { LightPushCore, LightPushCodec,
|
|
1
|
+
export { LightPushCore, LightPushCodec, LightPushCodecV2 } from "./light_push.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,gBAAgB,EACjB,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { PeerId } from "@libp2p/interface";
|
|
2
|
-
import { type
|
|
2
|
+
import { type IEncoder, type IMessage, type Libp2p, type LightPushCoreResult } from "@waku/interfaces";
|
|
3
3
|
import { PushResponse } from "@waku/proto";
|
|
4
|
-
export declare const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
|
5
4
|
export { PushResponse };
|
|
5
|
+
export declare const LightPushCodec: "/vac/waku/lightpush/3.0.0";
|
|
6
|
+
export declare const LightPushCodecV2: "/vac/waku/lightpush/2.0.0-beta1";
|
|
6
7
|
/**
|
|
7
8
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
|
8
9
|
*/
|
|
9
10
|
export declare class LightPushCore {
|
|
11
|
+
private libp2p;
|
|
10
12
|
private readonly streamManager;
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
send(encoder: IEncoder, message: IMessage, peerId: PeerId): Promise<
|
|
13
|
+
private readonly streamManagerV2;
|
|
14
|
+
readonly multicodec: ("/vac/waku/lightpush/2.0.0-beta1" | "/vac/waku/lightpush/3.0.0")[];
|
|
15
|
+
constructor(libp2p: Libp2p, legacy?: boolean);
|
|
16
|
+
send(encoder: IEncoder, message: IMessage, peerId: PeerId): Promise<LightPushCoreResult>;
|
|
15
17
|
}
|
|
@@ -1,141 +1,102 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LightPushError } from "@waku/interfaces";
|
|
2
2
|
import { PushResponse } from "@waku/proto";
|
|
3
|
-
import { isMessageSizeUnderCap } from "@waku/utils";
|
|
4
3
|
import { Logger } from "@waku/utils";
|
|
5
4
|
import all from "it-all";
|
|
6
5
|
import * as lp from "it-length-prefixed";
|
|
7
6
|
import { pipe } from "it-pipe";
|
|
8
7
|
import { Uint8ArrayList } from "uint8arraylist";
|
|
9
8
|
import { StreamManager } from "../stream_manager/index.js";
|
|
10
|
-
import {
|
|
11
|
-
import { isRLNResponseError } from "./utils.js";
|
|
9
|
+
import { CODECS, ProtocolHandler } from "./protocol_handler.js";
|
|
12
10
|
const log = new Logger("light-push");
|
|
13
|
-
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
|
14
11
|
export { PushResponse };
|
|
12
|
+
export const LightPushCodec = CODECS.v3;
|
|
13
|
+
export const LightPushCodecV2 = CODECS.v2;
|
|
15
14
|
/**
|
|
16
15
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
|
17
16
|
*/
|
|
18
17
|
export class LightPushCore {
|
|
18
|
+
libp2p;
|
|
19
19
|
streamManager;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
streamManagerV2;
|
|
21
|
+
multicodec = [CODECS.v3, CODECS.v2];
|
|
22
|
+
constructor(libp2p, legacy) {
|
|
23
|
+
this.libp2p = libp2p;
|
|
24
|
+
this.streamManagerV2 = new StreamManager(CODECS.v2, libp2p.components);
|
|
25
|
+
this.streamManager = legacy
|
|
26
|
+
? this.streamManagerV2
|
|
27
|
+
: new StreamManager(CODECS.v3, libp2p.components);
|
|
23
28
|
}
|
|
24
|
-
async
|
|
29
|
+
async send(encoder, message, peerId) {
|
|
30
|
+
let stream;
|
|
31
|
+
let protocol;
|
|
25
32
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
log.error("Failed to send waku light push: message is bigger than 1MB");
|
|
32
|
-
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
|
33
|
+
const peer = await this.libp2p.peerStore.get(peerId);
|
|
34
|
+
if (this.streamManager.multicodec === CODECS.v3 &&
|
|
35
|
+
peer.protocols.includes(CODECS.v3)) {
|
|
36
|
+
stream = await this.streamManager.getStream(peerId);
|
|
37
|
+
protocol = CODECS.v3;
|
|
33
38
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
query: null,
|
|
39
|
-
error: ProtocolError.ENCODE_FAILED
|
|
40
|
-
};
|
|
39
|
+
else {
|
|
40
|
+
stream = await this.streamManagerV2.getStream(peerId);
|
|
41
|
+
protocol = CODECS.v2;
|
|
41
42
|
}
|
|
42
|
-
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
|
43
|
-
return { query, error: null };
|
|
44
43
|
}
|
|
45
44
|
catch (error) {
|
|
46
|
-
log.error("Failed to
|
|
47
|
-
return {
|
|
48
|
-
query: null,
|
|
49
|
-
error: ProtocolError.GENERIC_FAIL
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async send(encoder, message, peerId) {
|
|
54
|
-
const { query, error: preparationError } = await this.preparePushMessage(encoder, message);
|
|
55
|
-
if (preparationError || !query) {
|
|
45
|
+
log.error("Failed to get stream", error);
|
|
56
46
|
return {
|
|
57
47
|
success: null,
|
|
58
48
|
failure: {
|
|
59
|
-
error:
|
|
49
|
+
error: LightPushError.GENERIC_FAIL,
|
|
60
50
|
peerId
|
|
61
51
|
}
|
|
62
52
|
};
|
|
63
53
|
}
|
|
64
|
-
const stream = await this.streamManager.getStream(peerId);
|
|
65
54
|
if (!stream) {
|
|
66
55
|
log.error(`Failed to get a stream for remote peer:${peerId.toString()}`);
|
|
67
56
|
return {
|
|
68
57
|
success: null,
|
|
69
58
|
failure: {
|
|
70
|
-
error:
|
|
59
|
+
error: LightPushError.NO_STREAM_AVAILABLE,
|
|
71
60
|
peerId: peerId
|
|
72
61
|
}
|
|
73
62
|
};
|
|
74
63
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
res = await pipe([query.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
// can fail only because of `stream` abortion
|
|
81
|
-
log.error("Failed to send waku light push request", err);
|
|
64
|
+
const { rpc, error: prepError } = await ProtocolHandler.preparePushMessage(encoder, message, protocol);
|
|
65
|
+
if (prepError || !rpc) {
|
|
82
66
|
return {
|
|
83
67
|
success: null,
|
|
84
68
|
failure: {
|
|
85
|
-
error:
|
|
86
|
-
peerId
|
|
69
|
+
error: prepError ?? LightPushError.GENERIC_FAIL,
|
|
70
|
+
peerId
|
|
87
71
|
}
|
|
88
72
|
};
|
|
89
73
|
}
|
|
90
|
-
|
|
91
|
-
res.forEach((chunk) => {
|
|
92
|
-
bytes.append(chunk);
|
|
93
|
-
});
|
|
94
|
-
let response;
|
|
74
|
+
let res;
|
|
95
75
|
try {
|
|
96
|
-
|
|
76
|
+
res = await pipe([rpc.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
|
97
77
|
}
|
|
98
78
|
catch (err) {
|
|
99
|
-
log.error("Failed to
|
|
100
|
-
return {
|
|
101
|
-
success: null,
|
|
102
|
-
failure: {
|
|
103
|
-
error: ProtocolError.DECODE_FAILED,
|
|
104
|
-
peerId: peerId
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
if (!response) {
|
|
109
|
-
log.error("Remote peer fault: No response in PushRPC");
|
|
110
|
-
return {
|
|
111
|
-
success: null,
|
|
112
|
-
failure: {
|
|
113
|
-
error: ProtocolError.NO_RESPONSE,
|
|
114
|
-
peerId: peerId
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (isRLNResponseError(response.info)) {
|
|
119
|
-
log.error("Remote peer fault: RLN generation");
|
|
79
|
+
log.error("Failed to send waku light push request", err);
|
|
120
80
|
return {
|
|
121
81
|
success: null,
|
|
122
82
|
failure: {
|
|
123
|
-
error:
|
|
83
|
+
error: LightPushError.STREAM_ABORTED,
|
|
124
84
|
peerId: peerId
|
|
125
85
|
}
|
|
126
86
|
};
|
|
127
87
|
}
|
|
128
|
-
|
|
129
|
-
|
|
88
|
+
const bytes = new Uint8ArrayList();
|
|
89
|
+
res.forEach((chunk) => bytes.append(chunk));
|
|
90
|
+
if (bytes.length === 0) {
|
|
130
91
|
return {
|
|
131
92
|
success: null,
|
|
132
93
|
failure: {
|
|
133
|
-
error:
|
|
94
|
+
error: LightPushError.NO_RESPONSE,
|
|
134
95
|
peerId: peerId
|
|
135
96
|
}
|
|
136
97
|
};
|
|
137
98
|
}
|
|
138
|
-
return
|
|
99
|
+
return ProtocolHandler.handleResponse(bytes, protocol, peerId);
|
|
139
100
|
}
|
|
140
101
|
}
|
|
141
102
|
//# sourceMappingURL=light_push.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"light_push.js","sourceRoot":"","sources":["../../../src/lib/light_push/light_push.ts"],"names":[],"mappings":"AACA,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@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PeerId } from "@libp2p/interface";
|
|
2
|
+
import type { IEncoder, IMessage, LightPushCoreResult } from "@waku/interfaces";
|
|
3
|
+
import { LightPushError } from "@waku/interfaces";
|
|
4
|
+
import { Uint8ArrayList } from "uint8arraylist";
|
|
5
|
+
import { PushRpcV2 } from "./push_rpc.js";
|
|
6
|
+
import { PushRpc } from "./push_rpc_v3.js";
|
|
7
|
+
export type VersionedPushRpc = ({
|
|
8
|
+
version: "v2";
|
|
9
|
+
} & PushRpcV2) | ({
|
|
10
|
+
version: "v3";
|
|
11
|
+
} & PushRpc);
|
|
12
|
+
export declare const CODECS: {
|
|
13
|
+
readonly v2: "/vac/waku/lightpush/2.0.0-beta1";
|
|
14
|
+
readonly v3: "/vac/waku/lightpush/3.0.0";
|
|
15
|
+
};
|
|
16
|
+
export declare class ProtocolHandler {
|
|
17
|
+
static preparePushMessage(encoder: IEncoder, message: IMessage, protocol: string): Promise<{
|
|
18
|
+
rpc: VersionedPushRpc | null;
|
|
19
|
+
error: LightPushError | null;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Decode and evaluate a LightPush response according to the protocol version
|
|
23
|
+
*/
|
|
24
|
+
static handleResponse(bytes: Uint8ArrayList, protocol: string, peerId: PeerId): LightPushCoreResult;
|
|
25
|
+
private static handleV3Response;
|
|
26
|
+
private static handleV2Response;
|
|
27
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { LightPushError, LightPushStatusCode } from "@waku/interfaces";
|
|
2
|
+
import { isMessageSizeUnderCap, Logger } from "@waku/utils";
|
|
3
|
+
import { PushRpcV2 } from "./push_rpc.js";
|
|
4
|
+
import { PushRpc } from "./push_rpc_v3.js";
|
|
5
|
+
import { isRLNResponseError } from "./utils.js";
|
|
6
|
+
export const CODECS = {
|
|
7
|
+
v2: "/vac/waku/lightpush/2.0.0-beta1",
|
|
8
|
+
v3: "/vac/waku/lightpush/3.0.0"
|
|
9
|
+
};
|
|
10
|
+
const log = new Logger("light-push:protocol-handler");
|
|
11
|
+
export class ProtocolHandler {
|
|
12
|
+
static async preparePushMessage(encoder, message, protocol) {
|
|
13
|
+
try {
|
|
14
|
+
if (!message.payload || message.payload.length === 0) {
|
|
15
|
+
log.error("Failed to send waku light push: payload is empty");
|
|
16
|
+
return { rpc: null, error: LightPushError.EMPTY_PAYLOAD };
|
|
17
|
+
}
|
|
18
|
+
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
|
19
|
+
log.error("Failed to send waku light push: message is bigger than 1MB");
|
|
20
|
+
return { rpc: null, error: LightPushError.SIZE_TOO_BIG };
|
|
21
|
+
}
|
|
22
|
+
const protoMessage = await encoder.toProtoObj(message);
|
|
23
|
+
if (!protoMessage) {
|
|
24
|
+
log.error("Failed to encode to protoMessage, aborting push");
|
|
25
|
+
return { rpc: null, error: LightPushError.ENCODE_FAILED };
|
|
26
|
+
}
|
|
27
|
+
// Select version implementation
|
|
28
|
+
if (protocol === CODECS.v3) {
|
|
29
|
+
log.info("Creating v3 RPC message");
|
|
30
|
+
return {
|
|
31
|
+
rpc: createV3Rpc(protoMessage, encoder.pubsubTopic),
|
|
32
|
+
error: null
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Default to v2
|
|
36
|
+
log.info("Creating v2 RPC message");
|
|
37
|
+
return {
|
|
38
|
+
rpc: createV2Rpc(protoMessage, encoder.pubsubTopic),
|
|
39
|
+
error: null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
log.error("Failed to prepare push message", err);
|
|
44
|
+
return { rpc: null, error: LightPushError.GENERIC_FAIL };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode and evaluate a LightPush response according to the protocol version
|
|
49
|
+
*/
|
|
50
|
+
static handleResponse(bytes, protocol, peerId) {
|
|
51
|
+
if (protocol === CODECS.v3) {
|
|
52
|
+
return ProtocolHandler.handleV3Response(bytes, peerId);
|
|
53
|
+
}
|
|
54
|
+
return ProtocolHandler.handleV2Response(bytes, peerId);
|
|
55
|
+
}
|
|
56
|
+
static handleV3Response(bytes, peerId) {
|
|
57
|
+
try {
|
|
58
|
+
const decodedRpcV3 = PushRpc.decodeResponse(bytes);
|
|
59
|
+
const statusCode = decodedRpcV3.statusCode;
|
|
60
|
+
const statusDesc = decodedRpcV3.statusDesc;
|
|
61
|
+
if (statusCode !== LightPushStatusCode.SUCCESS) {
|
|
62
|
+
const error = LightPushError.REMOTE_PEER_REJECTED;
|
|
63
|
+
log.error(`Remote peer rejected with v3 status code ${statusCode}: ${statusDesc}`);
|
|
64
|
+
return {
|
|
65
|
+
success: null,
|
|
66
|
+
failure: {
|
|
67
|
+
error,
|
|
68
|
+
peerId: peerId
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (decodedRpcV3.relayPeerCount !== undefined) {
|
|
73
|
+
log.info(`Message relayed to ${decodedRpcV3.relayPeerCount} peers`);
|
|
74
|
+
}
|
|
75
|
+
return { success: peerId, failure: null };
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return {
|
|
79
|
+
success: null,
|
|
80
|
+
failure: {
|
|
81
|
+
error: LightPushError.DECODE_FAILED,
|
|
82
|
+
peerId: peerId
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
static handleV2Response(bytes, peerId) {
|
|
88
|
+
let response;
|
|
89
|
+
try {
|
|
90
|
+
const decodedRpc = PushRpcV2.decode(bytes);
|
|
91
|
+
response = decodedRpc.response;
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
return {
|
|
95
|
+
success: null,
|
|
96
|
+
failure: {
|
|
97
|
+
error: LightPushError.DECODE_FAILED,
|
|
98
|
+
peerId: peerId
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (!response) {
|
|
103
|
+
return {
|
|
104
|
+
success: null,
|
|
105
|
+
failure: {
|
|
106
|
+
error: LightPushError.NO_RESPONSE,
|
|
107
|
+
peerId: peerId
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (isRLNResponseError(response.info)) {
|
|
112
|
+
log.error("Remote peer fault: RLN generation");
|
|
113
|
+
return {
|
|
114
|
+
success: null,
|
|
115
|
+
failure: {
|
|
116
|
+
error: LightPushError.RLN_PROOF_GENERATION,
|
|
117
|
+
peerId: peerId
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (!response.isSuccess) {
|
|
122
|
+
log.error("Remote peer rejected the message: ", response.info);
|
|
123
|
+
return {
|
|
124
|
+
success: null,
|
|
125
|
+
failure: {
|
|
126
|
+
error: LightPushError.REMOTE_PEER_REJECTED,
|
|
127
|
+
peerId: peerId
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { success: peerId, failure: null };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function createV2Rpc(message, pubsubTopic) {
|
|
135
|
+
const v2Rpc = PushRpcV2.createRequest(message, pubsubTopic);
|
|
136
|
+
return Object.assign(v2Rpc, { version: "v2" });
|
|
137
|
+
}
|
|
138
|
+
function createV3Rpc(message, pubsubTopic) {
|
|
139
|
+
if (!message.timestamp) {
|
|
140
|
+
message.timestamp = BigInt(Date.now()) * BigInt(1_000_000);
|
|
141
|
+
}
|
|
142
|
+
const v3Rpc = PushRpc.createRequest(message, pubsubTopic);
|
|
143
|
+
return Object.assign(v3Rpc, { version: "v3" });
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=protocol_handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol_handler.js","sourceRoot":"","sources":["../../../src/lib/light_push/protocol_handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAk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AAE,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { proto_lightpush as proto } from "@waku/proto";
|
|
2
2
|
import type { Uint8ArrayList } from "uint8arraylist";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class PushRpcV2 {
|
|
4
4
|
proto: proto.PushRpc;
|
|
5
5
|
constructor(proto: proto.PushRpc);
|
|
6
|
-
static createRequest(message: proto.WakuMessage, pubsubTopic: string):
|
|
7
|
-
static decode(bytes: Uint8ArrayList):
|
|
6
|
+
static createRequest(message: proto.WakuMessage, pubsubTopic: string): PushRpcV2;
|
|
7
|
+
static decode(bytes: Uint8ArrayList): PushRpcV2;
|
|
8
8
|
encode(): Uint8Array;
|
|
9
9
|
get query(): proto.PushRequest | undefined;
|
|
10
10
|
get response(): proto.PushResponse | undefined;
|