@waku/core 0.0.34-1c0c5ee.0 → 0.0.34-2eccb11.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-Bp5a9PNG.js +152 -0
- package/bundle/{index-BIW3qNYx.js → index-G1eRBjeI.js} +118 -204
- package/bundle/index.js +1895 -178
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-CdmZMfkQ.js → version_0-DJZG2fB2.js} +283 -45
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -23
- package/dist/lib/base_protocol.js +3 -47
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +118 -0
- package/dist/lib/{connection_manager.js → connection_manager/connection_manager.js} +136 -36
- package/dist/lib/connection_manager/connection_manager.js.map +1 -0
- package/dist/lib/connection_manager/index.d.ts +1 -0
- package/dist/lib/connection_manager/index.js +2 -0
- package/dist/lib/connection_manager/index.js.map +1 -0
- package/dist/lib/{keep_alive_manager.d.ts → connection_manager/keep_alive_manager.d.ts} +4 -2
- package/dist/lib/{keep_alive_manager.js → connection_manager/keep_alive_manager.js} +2 -2
- package/dist/lib/connection_manager/keep_alive_manager.js.map +1 -0
- package/dist/lib/connection_manager/utils.d.ts +7 -0
- package/dist/lib/connection_manager/utils.js +22 -0
- package/dist/lib/connection_manager/utils.js.map +1 -0
- package/dist/lib/filter/filter.d.ts +18 -0
- package/dist/lib/filter/filter.js +209 -0
- package/dist/lib/filter/filter.js.map +1 -0
- package/dist/lib/filter/index.d.ts +1 -18
- package/dist/lib/filter/index.js +1 -208
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +1 -15
- package/dist/lib/light_push/index.js +1 -143
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +15 -0
- package/dist/lib/light_push/light_push.js +144 -0
- package/dist/lib/light_push/light_push.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +0 -2
- package/dist/lib/light_push/utils.js +9 -17
- package/dist/lib/light_push/utils.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +1 -3
- package/dist/lib/metadata/index.js +1 -118
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/metadata/metadata.d.ts +3 -0
- package/dist/lib/metadata/metadata.js +119 -0
- package/dist/lib/metadata/metadata.js.map +1 -0
- package/dist/lib/store/index.d.ts +1 -9
- package/dist/lib/store/index.js +1 -82
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/store/store.d.ts +9 -0
- package/dist/lib/store/store.js +83 -0
- package/dist/lib/store/store.js.map +1 -0
- package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
- package/dist/lib/stream_manager/stream_manager.js +16 -17
- package/dist/lib/stream_manager/stream_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -4
- package/src/lib/base_protocol.ts +3 -76
- package/src/lib/{connection_manager.ts → connection_manager/connection_manager.ts} +168 -63
- package/src/lib/connection_manager/index.ts +1 -0
- package/src/lib/{keep_alive_manager.ts → connection_manager/keep_alive_manager.ts} +7 -3
- package/src/lib/connection_manager/utils.ts +25 -0
- package/src/lib/filter/filter.ts +315 -0
- package/src/lib/filter/index.ts +1 -315
- package/src/lib/light_push/index.ts +1 -188
- package/src/lib/light_push/light_push.ts +188 -0
- package/src/lib/light_push/utils.ts +13 -21
- package/src/lib/metadata/index.ts +1 -182
- package/src/lib/metadata/metadata.ts +182 -0
- package/src/lib/store/index.ts +1 -136
- package/src/lib/store/store.ts +136 -0
- package/src/lib/stream_manager/stream_manager.ts +16 -18
- package/bundle/base_protocol-Dzv-QHPR.js +0 -275
- package/dist/lib/connection_manager.d.ts +0 -62
- package/dist/lib/connection_manager.js.map +0 -1
- package/dist/lib/filterPeers.d.ts +0 -13
- package/dist/lib/filterPeers.js +0 -38
- package/dist/lib/filterPeers.js.map +0 -1
- package/dist/lib/health_manager.d.ts +0 -14
- package/dist/lib/health_manager.js +0 -70
- package/dist/lib/health_manager.js.map +0 -1
- package/dist/lib/keep_alive_manager.js.map +0 -1
- package/src/lib/filterPeers.ts +0 -51
- package/src/lib/health_manager.ts +0 -90
@@ -0,0 +1,209 @@
|
|
1
|
+
import { ProtocolError } from "@waku/interfaces";
|
2
|
+
import { Logger } from "@waku/utils";
|
3
|
+
import all from "it-all";
|
4
|
+
import * as lp from "it-length-prefixed";
|
5
|
+
import { pipe } from "it-pipe";
|
6
|
+
import { BaseProtocol } from "../base_protocol.js";
|
7
|
+
import { FilterPushRpc, FilterSubscribeResponse, FilterSubscribeRpc } from "./filter_rpc.js";
|
8
|
+
const log = new Logger("filter:v2");
|
9
|
+
export const FilterCodecs = {
|
10
|
+
SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
|
11
|
+
PUSH: "/vac/waku/filter-push/2.0.0-beta1"
|
12
|
+
};
|
13
|
+
export class FilterCore extends BaseProtocol {
|
14
|
+
handleIncomingMessage;
|
15
|
+
pubsubTopics;
|
16
|
+
constructor(handleIncomingMessage, pubsubTopics, libp2p) {
|
17
|
+
super(FilterCodecs.SUBSCRIBE, libp2p.components, pubsubTopics);
|
18
|
+
this.handleIncomingMessage = handleIncomingMessage;
|
19
|
+
this.pubsubTopics = pubsubTopics;
|
20
|
+
libp2p
|
21
|
+
.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
22
|
+
maxInboundStreams: 100
|
23
|
+
})
|
24
|
+
.catch((e) => {
|
25
|
+
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
26
|
+
});
|
27
|
+
}
|
28
|
+
async subscribe(pubsubTopic, peerId, contentTopics) {
|
29
|
+
const stream = await this.getStream(peerId);
|
30
|
+
const request = FilterSubscribeRpc.createSubscribeRequest(pubsubTopic, contentTopics);
|
31
|
+
let res;
|
32
|
+
try {
|
33
|
+
res = await pipe([request.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
34
|
+
}
|
35
|
+
catch (error) {
|
36
|
+
log.error("Failed to send subscribe request", error);
|
37
|
+
return {
|
38
|
+
success: null,
|
39
|
+
failure: {
|
40
|
+
error: ProtocolError.GENERIC_FAIL,
|
41
|
+
peerId: peerId
|
42
|
+
}
|
43
|
+
};
|
44
|
+
}
|
45
|
+
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
46
|
+
if (statusCode < 200 || statusCode >= 300) {
|
47
|
+
log.error(`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
48
|
+
return {
|
49
|
+
failure: {
|
50
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
51
|
+
peerId: peerId
|
52
|
+
},
|
53
|
+
success: null
|
54
|
+
};
|
55
|
+
}
|
56
|
+
return {
|
57
|
+
failure: null,
|
58
|
+
success: peerId
|
59
|
+
};
|
60
|
+
}
|
61
|
+
async unsubscribe(pubsubTopic, peerId, contentTopics) {
|
62
|
+
let stream;
|
63
|
+
try {
|
64
|
+
stream = await this.getStream(peerId);
|
65
|
+
}
|
66
|
+
catch (error) {
|
67
|
+
log.error(`Failed to get a stream for remote peer${peerId.toString()}`, error);
|
68
|
+
return {
|
69
|
+
success: null,
|
70
|
+
failure: {
|
71
|
+
error: ProtocolError.NO_STREAM_AVAILABLE,
|
72
|
+
peerId: peerId
|
73
|
+
}
|
74
|
+
};
|
75
|
+
}
|
76
|
+
const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest(pubsubTopic, contentTopics);
|
77
|
+
try {
|
78
|
+
await pipe([unsubscribeRequest.encode()], lp.encode, stream.sink);
|
79
|
+
}
|
80
|
+
catch (error) {
|
81
|
+
log.error("Failed to send unsubscribe request", error);
|
82
|
+
return {
|
83
|
+
success: null,
|
84
|
+
failure: {
|
85
|
+
error: ProtocolError.GENERIC_FAIL,
|
86
|
+
peerId: peerId
|
87
|
+
}
|
88
|
+
};
|
89
|
+
}
|
90
|
+
return {
|
91
|
+
success: peerId,
|
92
|
+
failure: null
|
93
|
+
};
|
94
|
+
}
|
95
|
+
async unsubscribeAll(pubsubTopic, peerId) {
|
96
|
+
const stream = await this.getStream(peerId);
|
97
|
+
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(pubsubTopic);
|
98
|
+
const res = await pipe([request.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
99
|
+
if (!res || !res.length) {
|
100
|
+
return {
|
101
|
+
failure: {
|
102
|
+
error: ProtocolError.NO_RESPONSE,
|
103
|
+
peerId: peerId
|
104
|
+
},
|
105
|
+
success: null
|
106
|
+
};
|
107
|
+
}
|
108
|
+
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
109
|
+
if (statusCode < 200 || statusCode >= 300) {
|
110
|
+
log.error(`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
111
|
+
return {
|
112
|
+
failure: {
|
113
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
114
|
+
peerId: peerId
|
115
|
+
},
|
116
|
+
success: null
|
117
|
+
};
|
118
|
+
}
|
119
|
+
return {
|
120
|
+
failure: null,
|
121
|
+
success: peerId
|
122
|
+
};
|
123
|
+
}
|
124
|
+
async ping(peerId) {
|
125
|
+
let stream;
|
126
|
+
try {
|
127
|
+
stream = await this.getStream(peerId);
|
128
|
+
}
|
129
|
+
catch (error) {
|
130
|
+
log.error(`Failed to get a stream for remote peer${peerId.toString()}`, error);
|
131
|
+
return {
|
132
|
+
success: null,
|
133
|
+
failure: {
|
134
|
+
error: ProtocolError.NO_STREAM_AVAILABLE,
|
135
|
+
peerId: peerId
|
136
|
+
}
|
137
|
+
};
|
138
|
+
}
|
139
|
+
const request = FilterSubscribeRpc.createSubscriberPingRequest();
|
140
|
+
let res;
|
141
|
+
try {
|
142
|
+
res = await pipe([request.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
143
|
+
}
|
144
|
+
catch (error) {
|
145
|
+
log.error("Failed to send ping request", error);
|
146
|
+
return {
|
147
|
+
success: null,
|
148
|
+
failure: {
|
149
|
+
error: ProtocolError.GENERIC_FAIL,
|
150
|
+
peerId: peerId
|
151
|
+
}
|
152
|
+
};
|
153
|
+
}
|
154
|
+
if (!res || !res.length) {
|
155
|
+
return {
|
156
|
+
success: null,
|
157
|
+
failure: {
|
158
|
+
error: ProtocolError.NO_RESPONSE,
|
159
|
+
peerId: peerId
|
160
|
+
}
|
161
|
+
};
|
162
|
+
}
|
163
|
+
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
164
|
+
if (statusCode < 200 || statusCode >= 300) {
|
165
|
+
log.error(`Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
166
|
+
return {
|
167
|
+
success: null,
|
168
|
+
failure: {
|
169
|
+
error: ProtocolError.REMOTE_PEER_REJECTED,
|
170
|
+
peerId: peerId
|
171
|
+
}
|
172
|
+
};
|
173
|
+
}
|
174
|
+
return {
|
175
|
+
success: peerId,
|
176
|
+
failure: null
|
177
|
+
};
|
178
|
+
}
|
179
|
+
onRequest(streamData) {
|
180
|
+
const { connection, stream } = streamData;
|
181
|
+
const { remotePeer } = connection;
|
182
|
+
log.info(`Received message from ${remotePeer.toString()}`);
|
183
|
+
try {
|
184
|
+
pipe(stream, lp.decode, async (source) => {
|
185
|
+
for await (const bytes of source) {
|
186
|
+
const response = FilterPushRpc.decode(bytes.slice());
|
187
|
+
const { pubsubTopic, wakuMessage } = response;
|
188
|
+
if (!wakuMessage) {
|
189
|
+
log.error("Received empty message");
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
if (!pubsubTopic) {
|
193
|
+
log.error("Pubsub topic missing from push message");
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
await this.handleIncomingMessage(pubsubTopic, wakuMessage, connection.remotePeer.toString());
|
197
|
+
}
|
198
|
+
}).then(() => {
|
199
|
+
log.info("Receiving pipe closed.");
|
200
|
+
}, async (e) => {
|
201
|
+
log.error(`Error with receiving pipe on peer:${connection.remotePeer.toString()} -- stream:${stream.id} -- protocol:${stream.protocol}: `, e);
|
202
|
+
});
|
203
|
+
}
|
204
|
+
catch (e) {
|
205
|
+
log.error("Error decoding message", e);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
//# sourceMappingURL=filter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/lib/filter/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,aAAa,EAEd,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,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;AAEpC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,SAAS,EAAE,wCAAwC;IACnD,IAAI,EAAE,mCAAmC;CAC1C,CAAC;AAEF,MAAM,OAAO,UAAW,SAAQ,YAAY;IAEhC;IAKQ;IANlB,YACU,qBAIU,EACF,YAA2B,EAC3C,MAAc;QAEd,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QARvD,0BAAqB,GAArB,qBAAqB,CAIX;QACF,iBAAY,GAAZ,YAAY,CAAe;QAK3C,MAAM;aACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAA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AC,QAAQ,EAAE,CACjC,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC,IAAI,CACL,GAAG,EAAE;gBACH,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YACrC,CAAC,EACD,KAAK,EAAE,CAAC,EAAE,EAAE;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,18 +1 @@
|
|
1
|
-
|
2
|
-
import { type ContentTopic, type CoreProtocolResult, type IBaseProtocolCore, type Libp2p, type PubsubTopic } from "@waku/interfaces";
|
3
|
-
import { WakuMessage } from "@waku/proto";
|
4
|
-
import { BaseProtocol } from "../base_protocol.js";
|
5
|
-
export declare const FilterCodecs: {
|
6
|
-
SUBSCRIBE: string;
|
7
|
-
PUSH: string;
|
8
|
-
};
|
9
|
-
export declare class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
10
|
-
private handleIncomingMessage;
|
11
|
-
readonly pubsubTopics: PubsubTopic[];
|
12
|
-
constructor(handleIncomingMessage: (pubsubTopic: PubsubTopic, wakuMessage: WakuMessage, peerIdStr: string) => Promise<void>, pubsubTopics: PubsubTopic[], libp2p: Libp2p);
|
13
|
-
subscribe(pubsubTopic: PubsubTopic, peer: Peer, contentTopics: ContentTopic[]): Promise<CoreProtocolResult>;
|
14
|
-
unsubscribe(pubsubTopic: PubsubTopic, peer: Peer, contentTopics: ContentTopic[]): Promise<CoreProtocolResult>;
|
15
|
-
unsubscribeAll(pubsubTopic: PubsubTopic, peer: Peer): Promise<CoreProtocolResult>;
|
16
|
-
ping(peer: Peer): Promise<CoreProtocolResult>;
|
17
|
-
private onRequest;
|
18
|
-
}
|
1
|
+
export { FilterCodecs, FilterCore } from "./filter.js";
|
package/dist/lib/filter/index.js
CHANGED
@@ -1,209 +1,2 @@
|
|
1
|
-
|
2
|
-
import { Logger } from "@waku/utils";
|
3
|
-
import all from "it-all";
|
4
|
-
import * as lp from "it-length-prefixed";
|
5
|
-
import { pipe } from "it-pipe";
|
6
|
-
import { BaseProtocol } from "../base_protocol.js";
|
7
|
-
import { FilterPushRpc, FilterSubscribeResponse, FilterSubscribeRpc } from "./filter_rpc.js";
|
8
|
-
const log = new Logger("filter:v2");
|
9
|
-
export const FilterCodecs = {
|
10
|
-
SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
|
11
|
-
PUSH: "/vac/waku/filter-push/2.0.0-beta1"
|
12
|
-
};
|
13
|
-
export class FilterCore extends BaseProtocol {
|
14
|
-
handleIncomingMessage;
|
15
|
-
pubsubTopics;
|
16
|
-
constructor(handleIncomingMessage, pubsubTopics, libp2p) {
|
17
|
-
super(FilterCodecs.SUBSCRIBE, libp2p.components, log, pubsubTopics);
|
18
|
-
this.handleIncomingMessage = handleIncomingMessage;
|
19
|
-
this.pubsubTopics = pubsubTopics;
|
20
|
-
libp2p
|
21
|
-
.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
22
|
-
maxInboundStreams: 100
|
23
|
-
})
|
24
|
-
.catch((e) => {
|
25
|
-
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
26
|
-
});
|
27
|
-
}
|
28
|
-
async subscribe(pubsubTopic, peer, contentTopics) {
|
29
|
-
const stream = await this.getStream(peer);
|
30
|
-
const request = FilterSubscribeRpc.createSubscribeRequest(pubsubTopic, contentTopics);
|
31
|
-
let res;
|
32
|
-
try {
|
33
|
-
res = await pipe([request.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
34
|
-
}
|
35
|
-
catch (error) {
|
36
|
-
log.error("Failed to send subscribe request", error);
|
37
|
-
return {
|
38
|
-
success: null,
|
39
|
-
failure: {
|
40
|
-
error: ProtocolError.GENERIC_FAIL,
|
41
|
-
peerId: peer.id
|
42
|
-
}
|
43
|
-
};
|
44
|
-
}
|
45
|
-
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
46
|
-
if (statusCode < 200 || statusCode >= 300) {
|
47
|
-
log.error(`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
48
|
-
return {
|
49
|
-
failure: {
|
50
|
-
error: ProtocolError.REMOTE_PEER_REJECTED,
|
51
|
-
peerId: peer.id
|
52
|
-
},
|
53
|
-
success: null
|
54
|
-
};
|
55
|
-
}
|
56
|
-
return {
|
57
|
-
failure: null,
|
58
|
-
success: peer.id
|
59
|
-
};
|
60
|
-
}
|
61
|
-
async unsubscribe(pubsubTopic, peer, contentTopics) {
|
62
|
-
let stream;
|
63
|
-
try {
|
64
|
-
stream = await this.getStream(peer);
|
65
|
-
}
|
66
|
-
catch (error) {
|
67
|
-
log.error(`Failed to get a stream for remote peer${peer.id.toString()}`, error);
|
68
|
-
return {
|
69
|
-
success: null,
|
70
|
-
failure: {
|
71
|
-
error: ProtocolError.NO_STREAM_AVAILABLE,
|
72
|
-
peerId: peer.id
|
73
|
-
}
|
74
|
-
};
|
75
|
-
}
|
76
|
-
const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest(pubsubTopic, contentTopics);
|
77
|
-
try {
|
78
|
-
await pipe([unsubscribeRequest.encode()], lp.encode, stream.sink);
|
79
|
-
}
|
80
|
-
catch (error) {
|
81
|
-
log.error("Failed to send unsubscribe request", error);
|
82
|
-
return {
|
83
|
-
success: null,
|
84
|
-
failure: {
|
85
|
-
error: ProtocolError.GENERIC_FAIL,
|
86
|
-
peerId: peer.id
|
87
|
-
}
|
88
|
-
};
|
89
|
-
}
|
90
|
-
return {
|
91
|
-
success: peer.id,
|
92
|
-
failure: null
|
93
|
-
};
|
94
|
-
}
|
95
|
-
async unsubscribeAll(pubsubTopic, peer) {
|
96
|
-
const stream = await this.getStream(peer);
|
97
|
-
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(pubsubTopic);
|
98
|
-
const res = await pipe([request.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
99
|
-
if (!res || !res.length) {
|
100
|
-
return {
|
101
|
-
failure: {
|
102
|
-
error: ProtocolError.NO_RESPONSE,
|
103
|
-
peerId: peer.id
|
104
|
-
},
|
105
|
-
success: null
|
106
|
-
};
|
107
|
-
}
|
108
|
-
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
109
|
-
if (statusCode < 200 || statusCode >= 300) {
|
110
|
-
log.error(`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
111
|
-
return {
|
112
|
-
failure: {
|
113
|
-
error: ProtocolError.REMOTE_PEER_REJECTED,
|
114
|
-
peerId: peer.id
|
115
|
-
},
|
116
|
-
success: null
|
117
|
-
};
|
118
|
-
}
|
119
|
-
return {
|
120
|
-
failure: null,
|
121
|
-
success: peer.id
|
122
|
-
};
|
123
|
-
}
|
124
|
-
async ping(peer) {
|
125
|
-
let stream;
|
126
|
-
try {
|
127
|
-
stream = await this.getStream(peer);
|
128
|
-
}
|
129
|
-
catch (error) {
|
130
|
-
log.error(`Failed to get a stream for remote peer${peer.id.toString()}`, error);
|
131
|
-
return {
|
132
|
-
success: null,
|
133
|
-
failure: {
|
134
|
-
error: ProtocolError.NO_STREAM_AVAILABLE,
|
135
|
-
peerId: peer.id
|
136
|
-
}
|
137
|
-
};
|
138
|
-
}
|
139
|
-
const request = FilterSubscribeRpc.createSubscriberPingRequest();
|
140
|
-
let res;
|
141
|
-
try {
|
142
|
-
res = await pipe([request.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
143
|
-
}
|
144
|
-
catch (error) {
|
145
|
-
log.error("Failed to send ping request", error);
|
146
|
-
return {
|
147
|
-
success: null,
|
148
|
-
failure: {
|
149
|
-
error: ProtocolError.GENERIC_FAIL,
|
150
|
-
peerId: peer.id
|
151
|
-
}
|
152
|
-
};
|
153
|
-
}
|
154
|
-
if (!res || !res.length) {
|
155
|
-
return {
|
156
|
-
success: null,
|
157
|
-
failure: {
|
158
|
-
error: ProtocolError.NO_RESPONSE,
|
159
|
-
peerId: peer.id
|
160
|
-
}
|
161
|
-
};
|
162
|
-
}
|
163
|
-
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
164
|
-
if (statusCode < 200 || statusCode >= 300) {
|
165
|
-
log.error(`Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
166
|
-
return {
|
167
|
-
success: null,
|
168
|
-
failure: {
|
169
|
-
error: ProtocolError.REMOTE_PEER_REJECTED,
|
170
|
-
peerId: peer.id
|
171
|
-
}
|
172
|
-
};
|
173
|
-
}
|
174
|
-
return {
|
175
|
-
success: peer.id,
|
176
|
-
failure: null
|
177
|
-
};
|
178
|
-
}
|
179
|
-
onRequest(streamData) {
|
180
|
-
const { connection, stream } = streamData;
|
181
|
-
const { remotePeer } = connection;
|
182
|
-
log.info(`Received message from ${remotePeer.toString()}`);
|
183
|
-
try {
|
184
|
-
pipe(stream, lp.decode, async (source) => {
|
185
|
-
for await (const bytes of source) {
|
186
|
-
const response = FilterPushRpc.decode(bytes.slice());
|
187
|
-
const { pubsubTopic, wakuMessage } = response;
|
188
|
-
if (!wakuMessage) {
|
189
|
-
log.error("Received empty message");
|
190
|
-
return;
|
191
|
-
}
|
192
|
-
if (!pubsubTopic) {
|
193
|
-
log.error("Pubsub topic missing from push message");
|
194
|
-
return;
|
195
|
-
}
|
196
|
-
await this.handleIncomingMessage(pubsubTopic, wakuMessage, connection.remotePeer.toString());
|
197
|
-
}
|
198
|
-
}).then(() => {
|
199
|
-
log.info("Receiving pipe closed.");
|
200
|
-
}, async (e) => {
|
201
|
-
log.error(`Error with receiving pipe on peer:${connection.remotePeer.toString()} -- stream:${stream.id} -- protocol:${stream.protocol}: `, e);
|
202
|
-
});
|
203
|
-
}
|
204
|
-
catch (e) {
|
205
|
-
log.error("Error decoding message", e);
|
206
|
-
}
|
207
|
-
}
|
208
|
-
}
|
1
|
+
export { FilterCodecs, FilterCore } from "./filter.js";
|
209
2
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/filter/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/filter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
@@ -1,15 +1 @@
|
|
1
|
-
|
2
|
-
import { type CoreProtocolResult, type IBaseProtocolCore, type IEncoder, type IMessage, type Libp2p, PubsubTopic } from "@waku/interfaces";
|
3
|
-
import { PushResponse } from "@waku/proto";
|
4
|
-
import { BaseProtocol } from "../base_protocol.js";
|
5
|
-
export declare const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
6
|
-
export { PushResponse };
|
7
|
-
/**
|
8
|
-
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
9
|
-
*/
|
10
|
-
export declare class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
11
|
-
readonly pubsubTopics: PubsubTopic[];
|
12
|
-
constructor(pubsubTopics: PubsubTopic[], libp2p: Libp2p);
|
13
|
-
private preparePushMessage;
|
14
|
-
send(encoder: IEncoder, message: IMessage, peer: Peer): Promise<CoreProtocolResult>;
|
15
|
-
}
|
1
|
+
export { LightPushCore, LightPushCodec, PushResponse } from "./light_push.js";
|
@@ -1,144 +1,2 @@
|
|
1
|
-
|
2
|
-
import { PushResponse } from "@waku/proto";
|
3
|
-
import { isMessageSizeUnderCap } from "@waku/utils";
|
4
|
-
import { Logger } from "@waku/utils";
|
5
|
-
import all from "it-all";
|
6
|
-
import * as lp from "it-length-prefixed";
|
7
|
-
import { pipe } from "it-pipe";
|
8
|
-
import { Uint8ArrayList } from "uint8arraylist";
|
9
|
-
import { BaseProtocol } from "../base_protocol.js";
|
10
|
-
import { PushRpc } from "./push_rpc.js";
|
11
|
-
import { isRLNResponseError, matchRLNErrorMessage } from "./utils.js";
|
12
|
-
const log = new Logger("light-push");
|
13
|
-
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
14
|
-
export { PushResponse };
|
15
|
-
/**
|
16
|
-
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
17
|
-
*/
|
18
|
-
export class LightPushCore extends BaseProtocol {
|
19
|
-
pubsubTopics;
|
20
|
-
constructor(pubsubTopics, libp2p) {
|
21
|
-
super(LightPushCodec, libp2p.components, log, pubsubTopics);
|
22
|
-
this.pubsubTopics = pubsubTopics;
|
23
|
-
}
|
24
|
-
async preparePushMessage(encoder, message) {
|
25
|
-
try {
|
26
|
-
if (!message.payload || message.payload.length === 0) {
|
27
|
-
log.error("Failed to send waku light push: payload is empty");
|
28
|
-
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
29
|
-
}
|
30
|
-
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
31
|
-
log.error("Failed to send waku light push: message is bigger than 1MB");
|
32
|
-
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
33
|
-
}
|
34
|
-
const protoMessage = await encoder.toProtoObj(message);
|
35
|
-
if (!protoMessage) {
|
36
|
-
log.error("Failed to encode to protoMessage, aborting push");
|
37
|
-
return {
|
38
|
-
query: null,
|
39
|
-
error: ProtocolError.ENCODE_FAILED
|
40
|
-
};
|
41
|
-
}
|
42
|
-
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
43
|
-
return { query, error: null };
|
44
|
-
}
|
45
|
-
catch (error) {
|
46
|
-
log.error("Failed to prepare push message", error);
|
47
|
-
return {
|
48
|
-
query: null,
|
49
|
-
error: ProtocolError.GENERIC_FAIL
|
50
|
-
};
|
51
|
-
}
|
52
|
-
}
|
53
|
-
async send(encoder, message, peer) {
|
54
|
-
const { query, error: preparationError } = await this.preparePushMessage(encoder, message);
|
55
|
-
if (preparationError || !query) {
|
56
|
-
return {
|
57
|
-
success: null,
|
58
|
-
failure: {
|
59
|
-
error: preparationError,
|
60
|
-
peerId: peer.id
|
61
|
-
}
|
62
|
-
};
|
63
|
-
}
|
64
|
-
let stream;
|
65
|
-
try {
|
66
|
-
stream = await this.getStream(peer);
|
67
|
-
}
|
68
|
-
catch (error) {
|
69
|
-
log.error("Failed to get stream", error);
|
70
|
-
return {
|
71
|
-
success: null,
|
72
|
-
failure: {
|
73
|
-
error: ProtocolError.NO_STREAM_AVAILABLE,
|
74
|
-
peerId: peer.id
|
75
|
-
}
|
76
|
-
};
|
77
|
-
}
|
78
|
-
let res;
|
79
|
-
try {
|
80
|
-
res = await pipe([query.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
81
|
-
}
|
82
|
-
catch (err) {
|
83
|
-
log.error("Failed to send waku light push request", err);
|
84
|
-
return {
|
85
|
-
success: null,
|
86
|
-
failure: {
|
87
|
-
error: ProtocolError.GENERIC_FAIL,
|
88
|
-
peerId: peer.id
|
89
|
-
}
|
90
|
-
};
|
91
|
-
}
|
92
|
-
const bytes = new Uint8ArrayList();
|
93
|
-
res.forEach((chunk) => {
|
94
|
-
bytes.append(chunk);
|
95
|
-
});
|
96
|
-
let response;
|
97
|
-
try {
|
98
|
-
response = PushRpc.decode(bytes).response;
|
99
|
-
}
|
100
|
-
catch (err) {
|
101
|
-
log.error("Failed to decode push reply", err);
|
102
|
-
return {
|
103
|
-
success: null,
|
104
|
-
failure: {
|
105
|
-
error: ProtocolError.DECODE_FAILED,
|
106
|
-
peerId: peer.id
|
107
|
-
}
|
108
|
-
};
|
109
|
-
}
|
110
|
-
if (!response) {
|
111
|
-
log.error("Remote peer fault: No response in PushRPC");
|
112
|
-
return {
|
113
|
-
success: null,
|
114
|
-
failure: {
|
115
|
-
error: ProtocolError.NO_RESPONSE,
|
116
|
-
peerId: peer.id
|
117
|
-
}
|
118
|
-
};
|
119
|
-
}
|
120
|
-
if (isRLNResponseError(response.info)) {
|
121
|
-
const rlnErrorCase = matchRLNErrorMessage(response.info);
|
122
|
-
log.error("Remote peer rejected the message: ", rlnErrorCase);
|
123
|
-
return {
|
124
|
-
success: null,
|
125
|
-
failure: {
|
126
|
-
error: rlnErrorCase,
|
127
|
-
peerId: peer.id
|
128
|
-
}
|
129
|
-
};
|
130
|
-
}
|
131
|
-
if (!response.isSuccess) {
|
132
|
-
log.error("Remote peer rejected the message: ", response.info);
|
133
|
-
return {
|
134
|
-
success: null,
|
135
|
-
failure: {
|
136
|
-
error: ProtocolError.REMOTE_PEER_REJECTED,
|
137
|
-
peerId: peer.id
|
138
|
-
}
|
139
|
-
};
|
140
|
-
}
|
141
|
-
return { success: peer.id, failure: null };
|
142
|
-
}
|
143
|
-
}
|
1
|
+
export { LightPushCore, LightPushCodec, PushResponse } from "./light_push.js";
|
144
2
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { PeerId } from "@libp2p/interface";
|
2
|
+
import { type CoreProtocolResult, type IBaseProtocolCore, type IEncoder, type IMessage, type Libp2p, PubsubTopic } from "@waku/interfaces";
|
3
|
+
import { PushResponse } from "@waku/proto";
|
4
|
+
import { BaseProtocol } from "../base_protocol.js";
|
5
|
+
export declare const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
6
|
+
export { PushResponse };
|
7
|
+
/**
|
8
|
+
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
9
|
+
*/
|
10
|
+
export declare class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
11
|
+
readonly pubsubTopics: PubsubTopic[];
|
12
|
+
constructor(pubsubTopics: PubsubTopic[], libp2p: Libp2p);
|
13
|
+
private preparePushMessage;
|
14
|
+
send(encoder: IEncoder, message: IMessage, peerId: PeerId): Promise<CoreProtocolResult>;
|
15
|
+
}
|