@waku/core 0.0.34-c43cec2.0 → 0.0.34-caeafce.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-DxFKDXX2.js → base_protocol-Bp5a9PNG.js} +19 -20
- package/bundle/{index-yLOEQnIE.js → index-G1eRBjeI.js} +115 -84
- package/bundle/index.js +1828 -153
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-Che4t3mN.js → version_0-DJZG2fB2.js} +163 -42
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +2 -2
- package/dist/lib/base_protocol.js +2 -2
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +56 -3
- package/dist/lib/connection_manager/connection_manager.js +96 -13
- package/dist/lib/connection_manager/connection_manager.js.map +1 -1
- 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 -144
- 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 +0 -2
- package/src/lib/base_protocol.ts +3 -3
- package/src/lib/connection_manager/connection_manager.ts +114 -20
- package/src/lib/filter/filter.ts +315 -0
- package/src/lib/filter/index.ts +1 -315
- package/src/lib/light_push/index.ts +1 -189
- 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/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/src/lib/health_manager.ts +0 -90
@@ -1,119 +1,2 @@
|
|
1
|
-
|
2
|
-
import { proto_metadata } from "@waku/proto";
|
3
|
-
import { encodeRelayShard, Logger, pubsubTopicsToShardInfo } from "@waku/utils";
|
4
|
-
import all from "it-all";
|
5
|
-
import * as lp from "it-length-prefixed";
|
6
|
-
import { pipe } from "it-pipe";
|
7
|
-
import { Uint8ArrayList } from "uint8arraylist";
|
8
|
-
import { BaseProtocol } from "../base_protocol.js";
|
9
|
-
const log = new Logger("metadata");
|
10
|
-
export const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
11
|
-
class Metadata extends BaseProtocol {
|
12
|
-
pubsubTopics;
|
13
|
-
libp2pComponents;
|
14
|
-
handshakesConfirmed = new Map();
|
15
|
-
constructor(pubsubTopics, libp2p) {
|
16
|
-
super(MetadataCodec, libp2p.components, pubsubTopics);
|
17
|
-
this.pubsubTopics = pubsubTopics;
|
18
|
-
this.libp2pComponents = libp2p;
|
19
|
-
void libp2p.registrar.handle(MetadataCodec, (streamData) => {
|
20
|
-
void this.onRequest(streamData);
|
21
|
-
});
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* Make a metadata query to a peer
|
25
|
-
*/
|
26
|
-
async query(peerId) {
|
27
|
-
const request = proto_metadata.WakuMetadataRequest.encode(pubsubTopicsToShardInfo(this.pubsubTopics));
|
28
|
-
const peer = await this.libp2pComponents.peerStore.get(peerId);
|
29
|
-
if (!peer) {
|
30
|
-
return {
|
31
|
-
shardInfo: null,
|
32
|
-
error: ProtocolError.NO_PEER_AVAILABLE
|
33
|
-
};
|
34
|
-
}
|
35
|
-
let stream;
|
36
|
-
try {
|
37
|
-
stream = await this.getStream(peer);
|
38
|
-
}
|
39
|
-
catch (error) {
|
40
|
-
log.error("Failed to get stream", error);
|
41
|
-
return {
|
42
|
-
shardInfo: null,
|
43
|
-
error: ProtocolError.NO_STREAM_AVAILABLE
|
44
|
-
};
|
45
|
-
}
|
46
|
-
const encodedResponse = await pipe([request], lp.encode, stream, lp.decode, async (source) => await all(source));
|
47
|
-
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
48
|
-
if (error) {
|
49
|
-
return {
|
50
|
-
shardInfo: null,
|
51
|
-
error
|
52
|
-
};
|
53
|
-
}
|
54
|
-
await this.savePeerShardInfo(peerId, shardInfo);
|
55
|
-
return {
|
56
|
-
shardInfo,
|
57
|
-
error: null
|
58
|
-
};
|
59
|
-
}
|
60
|
-
async confirmOrAttemptHandshake(peerId) {
|
61
|
-
const shardInfo = this.handshakesConfirmed.get(peerId.toString());
|
62
|
-
if (shardInfo) {
|
63
|
-
return {
|
64
|
-
shardInfo,
|
65
|
-
error: null
|
66
|
-
};
|
67
|
-
}
|
68
|
-
return await this.query(peerId);
|
69
|
-
}
|
70
|
-
/**
|
71
|
-
* Handle an incoming metadata request
|
72
|
-
*/
|
73
|
-
async onRequest(streamData) {
|
74
|
-
try {
|
75
|
-
const { stream, connection } = streamData;
|
76
|
-
const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(pubsubTopicsToShardInfo(this.pubsubTopics));
|
77
|
-
const encodedResponse = await pipe([encodedShardInfo], lp.encode, stream, lp.decode, async (source) => await all(source));
|
78
|
-
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
79
|
-
if (error) {
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
83
|
-
}
|
84
|
-
catch (error) {
|
85
|
-
log.error("Error handling metadata request", error);
|
86
|
-
}
|
87
|
-
}
|
88
|
-
decodeMetadataResponse(encodedResponse) {
|
89
|
-
const bytes = new Uint8ArrayList();
|
90
|
-
encodedResponse.forEach((chunk) => {
|
91
|
-
bytes.append(chunk);
|
92
|
-
});
|
93
|
-
const response = proto_metadata.WakuMetadataResponse.decode(bytes);
|
94
|
-
if (!response) {
|
95
|
-
log.error("Error decoding metadata response");
|
96
|
-
return {
|
97
|
-
shardInfo: null,
|
98
|
-
error: ProtocolError.DECODE_FAILED
|
99
|
-
};
|
100
|
-
}
|
101
|
-
return {
|
102
|
-
shardInfo: response,
|
103
|
-
error: null
|
104
|
-
};
|
105
|
-
}
|
106
|
-
async savePeerShardInfo(peerId, shardInfo) {
|
107
|
-
// add or update the shardInfo to peer store
|
108
|
-
await this.libp2pComponents.peerStore.merge(peerId, {
|
109
|
-
metadata: {
|
110
|
-
shardInfo: encodeRelayShard(shardInfo)
|
111
|
-
}
|
112
|
-
});
|
113
|
-
this.handshakesConfirmed.set(peerId.toString(), shardInfo);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
export function wakuMetadata(pubsubTopics) {
|
117
|
-
return (components) => new Metadata(pubsubTopics, components);
|
118
|
-
}
|
1
|
+
export { wakuMetadata, MetadataCodec } from "./metadata.js";
|
119
2
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/metadata/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
import { ProtocolError } from "@waku/interfaces";
|
2
|
+
import { proto_metadata } from "@waku/proto";
|
3
|
+
import { encodeRelayShard, Logger, pubsubTopicsToShardInfo } from "@waku/utils";
|
4
|
+
import all from "it-all";
|
5
|
+
import * as lp from "it-length-prefixed";
|
6
|
+
import { pipe } from "it-pipe";
|
7
|
+
import { Uint8ArrayList } from "uint8arraylist";
|
8
|
+
import { BaseProtocol } from "../base_protocol.js";
|
9
|
+
const log = new Logger("metadata");
|
10
|
+
export const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
11
|
+
class Metadata extends BaseProtocol {
|
12
|
+
pubsubTopics;
|
13
|
+
libp2pComponents;
|
14
|
+
handshakesConfirmed = new Map();
|
15
|
+
constructor(pubsubTopics, libp2p) {
|
16
|
+
super(MetadataCodec, libp2p.components, pubsubTopics);
|
17
|
+
this.pubsubTopics = pubsubTopics;
|
18
|
+
this.libp2pComponents = libp2p;
|
19
|
+
void libp2p.registrar.handle(MetadataCodec, (streamData) => {
|
20
|
+
void this.onRequest(streamData);
|
21
|
+
});
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Make a metadata query to a peer
|
25
|
+
*/
|
26
|
+
async query(peerId) {
|
27
|
+
const request = proto_metadata.WakuMetadataRequest.encode(pubsubTopicsToShardInfo(this.pubsubTopics));
|
28
|
+
const peer = await this.libp2pComponents.peerStore.get(peerId);
|
29
|
+
if (!peer) {
|
30
|
+
return {
|
31
|
+
shardInfo: null,
|
32
|
+
error: ProtocolError.NO_PEER_AVAILABLE
|
33
|
+
};
|
34
|
+
}
|
35
|
+
let stream;
|
36
|
+
try {
|
37
|
+
stream = await this.getStream(peerId);
|
38
|
+
}
|
39
|
+
catch (error) {
|
40
|
+
log.error("Failed to get stream", error);
|
41
|
+
return {
|
42
|
+
shardInfo: null,
|
43
|
+
error: ProtocolError.NO_STREAM_AVAILABLE
|
44
|
+
};
|
45
|
+
}
|
46
|
+
const encodedResponse = await pipe([request], lp.encode, stream, lp.decode, async (source) => await all(source));
|
47
|
+
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
48
|
+
if (error) {
|
49
|
+
return {
|
50
|
+
shardInfo: null,
|
51
|
+
error
|
52
|
+
};
|
53
|
+
}
|
54
|
+
await this.savePeerShardInfo(peerId, shardInfo);
|
55
|
+
return {
|
56
|
+
shardInfo,
|
57
|
+
error: null
|
58
|
+
};
|
59
|
+
}
|
60
|
+
async confirmOrAttemptHandshake(peerId) {
|
61
|
+
const shardInfo = this.handshakesConfirmed.get(peerId.toString());
|
62
|
+
if (shardInfo) {
|
63
|
+
return {
|
64
|
+
shardInfo,
|
65
|
+
error: null
|
66
|
+
};
|
67
|
+
}
|
68
|
+
return await this.query(peerId);
|
69
|
+
}
|
70
|
+
/**
|
71
|
+
* Handle an incoming metadata request
|
72
|
+
*/
|
73
|
+
async onRequest(streamData) {
|
74
|
+
try {
|
75
|
+
const { stream, connection } = streamData;
|
76
|
+
const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(pubsubTopicsToShardInfo(this.pubsubTopics));
|
77
|
+
const encodedResponse = await pipe([encodedShardInfo], lp.encode, stream, lp.decode, async (source) => await all(source));
|
78
|
+
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
79
|
+
if (error) {
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
83
|
+
}
|
84
|
+
catch (error) {
|
85
|
+
log.error("Error handling metadata request", error);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
decodeMetadataResponse(encodedResponse) {
|
89
|
+
const bytes = new Uint8ArrayList();
|
90
|
+
encodedResponse.forEach((chunk) => {
|
91
|
+
bytes.append(chunk);
|
92
|
+
});
|
93
|
+
const response = proto_metadata.WakuMetadataResponse.decode(bytes);
|
94
|
+
if (!response) {
|
95
|
+
log.error("Error decoding metadata response");
|
96
|
+
return {
|
97
|
+
shardInfo: null,
|
98
|
+
error: ProtocolError.DECODE_FAILED
|
99
|
+
};
|
100
|
+
}
|
101
|
+
return {
|
102
|
+
shardInfo: response,
|
103
|
+
error: null
|
104
|
+
};
|
105
|
+
}
|
106
|
+
async savePeerShardInfo(peerId, shardInfo) {
|
107
|
+
// add or update the shardInfo to peer store
|
108
|
+
await this.libp2pComponents.peerStore.merge(peerId, {
|
109
|
+
metadata: {
|
110
|
+
shardInfo: encodeRelayShard(shardInfo)
|
111
|
+
}
|
112
|
+
});
|
113
|
+
this.handshakesConfirmed.set(peerId.toString(), shardInfo);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
export function wakuMetadata(pubsubTopics) {
|
117
|
+
return (components) => new Metadata(pubsubTopics, components);
|
118
|
+
}
|
119
|
+
//# sourceMappingURL=metadata.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/lib/metadata/metadata.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,aAAa,EAGd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAq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,CAAC,CAAC;QAEH,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAC1B,YAA2B;IAE3B,OAAO,CAAC,UAA4B,EAAE,EAAE,CACtC,IAAI,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC"}
|
@@ -1,9 +1 @@
|
|
1
|
-
|
2
|
-
import { IDecodedMessage, IDecoder, IStoreCore, Libp2p, PubsubTopic, QueryRequestParams } from "@waku/interfaces";
|
3
|
-
import { BaseProtocol } from "../base_protocol.js";
|
4
|
-
export declare const StoreCodec = "/vac/waku/store-query/3.0.0";
|
5
|
-
export declare class StoreCore extends BaseProtocol implements IStoreCore {
|
6
|
-
readonly pubsubTopics: PubsubTopic[];
|
7
|
-
constructor(pubsubTopics: PubsubTopic[], libp2p: Libp2p);
|
8
|
-
queryPerPage<T extends IDecodedMessage>(queryOpts: QueryRequestParams, decoders: Map<string, IDecoder<T>>, peer: Peer): AsyncGenerator<Promise<T | undefined>[]>;
|
9
|
-
}
|
1
|
+
export { StoreCore, StoreCodec } from "./store.js";
|
package/dist/lib/store/index.js
CHANGED
@@ -1,83 +1,2 @@
|
|
1
|
-
|
2
|
-
import all from "it-all";
|
3
|
-
import * as lp from "it-length-prefixed";
|
4
|
-
import { pipe } from "it-pipe";
|
5
|
-
import { Uint8ArrayList } from "uint8arraylist";
|
6
|
-
import { BaseProtocol } from "../base_protocol.js";
|
7
|
-
import { toProtoMessage } from "../to_proto_message.js";
|
8
|
-
import { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, StoreQueryRequest, StoreQueryResponse } from "./rpc.js";
|
9
|
-
const log = new Logger("store");
|
10
|
-
export const StoreCodec = "/vac/waku/store-query/3.0.0";
|
11
|
-
export class StoreCore extends BaseProtocol {
|
12
|
-
pubsubTopics;
|
13
|
-
constructor(pubsubTopics, libp2p) {
|
14
|
-
super(StoreCodec, libp2p.components, pubsubTopics);
|
15
|
-
this.pubsubTopics = pubsubTopics;
|
16
|
-
}
|
17
|
-
async *queryPerPage(queryOpts, decoders, peer) {
|
18
|
-
if (queryOpts.contentTopics.toString() !==
|
19
|
-
Array.from(decoders.keys()).toString()) {
|
20
|
-
throw new Error("Internal error, the decoders should match the query's content topics");
|
21
|
-
}
|
22
|
-
let currentCursor = queryOpts.paginationCursor;
|
23
|
-
while (true) {
|
24
|
-
const storeQueryRequest = StoreQueryRequest.create({
|
25
|
-
...queryOpts,
|
26
|
-
paginationCursor: currentCursor
|
27
|
-
});
|
28
|
-
let stream;
|
29
|
-
try {
|
30
|
-
stream = await this.getStream(peer);
|
31
|
-
}
|
32
|
-
catch (e) {
|
33
|
-
log.error("Failed to get stream", e);
|
34
|
-
break;
|
35
|
-
}
|
36
|
-
const res = await pipe([storeQueryRequest.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
37
|
-
const bytes = new Uint8ArrayList();
|
38
|
-
res.forEach((chunk) => {
|
39
|
-
bytes.append(chunk);
|
40
|
-
});
|
41
|
-
const storeQueryResponse = StoreQueryResponse.decode(bytes);
|
42
|
-
if (!storeQueryResponse.statusCode ||
|
43
|
-
storeQueryResponse.statusCode >= 300) {
|
44
|
-
const errorMessage = `Store query failed with status code: ${storeQueryResponse.statusCode}, description: ${storeQueryResponse.statusDesc}`;
|
45
|
-
log.error(errorMessage);
|
46
|
-
throw new Error(errorMessage);
|
47
|
-
}
|
48
|
-
if (!storeQueryResponse.messages || !storeQueryResponse.messages.length) {
|
49
|
-
log.warn("Stopping pagination due to empty messages in response");
|
50
|
-
break;
|
51
|
-
}
|
52
|
-
log.info(`${storeQueryResponse.messages.length} messages retrieved from store`);
|
53
|
-
const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
|
54
|
-
if (!protoMsg.message) {
|
55
|
-
return Promise.resolve(undefined);
|
56
|
-
}
|
57
|
-
const contentTopic = protoMsg.message.contentTopic;
|
58
|
-
if (contentTopic) {
|
59
|
-
const decoder = decoders.get(contentTopic);
|
60
|
-
if (decoder) {
|
61
|
-
return decoder.fromProtoObj(protoMsg.pubsubTopic || "", toProtoMessage(protoMsg.message));
|
62
|
-
}
|
63
|
-
}
|
64
|
-
return Promise.resolve(undefined);
|
65
|
-
});
|
66
|
-
yield decodedMessages;
|
67
|
-
if (queryOpts.paginationForward) {
|
68
|
-
currentCursor =
|
69
|
-
storeQueryResponse.messages[storeQueryResponse.messages.length - 1]
|
70
|
-
.messageHash;
|
71
|
-
}
|
72
|
-
else {
|
73
|
-
currentCursor = storeQueryResponse.messages[0].messageHash;
|
74
|
-
}
|
75
|
-
if (storeQueryResponse.messages.length > MAX_PAGE_SIZE &&
|
76
|
-
storeQueryResponse.messages.length <
|
77
|
-
(queryOpts.paginationLimit || DEFAULT_PAGE_SIZE)) {
|
78
|
-
break;
|
79
|
-
}
|
80
|
-
}
|
81
|
-
}
|
82
|
-
}
|
1
|
+
export { StoreCore, StoreCodec } from "./store.js";
|
83
2
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/store/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { PeerId } from "@libp2p/interface";
|
2
|
+
import { IDecodedMessage, IDecoder, IStoreCore, Libp2p, PubsubTopic, QueryRequestParams } from "@waku/interfaces";
|
3
|
+
import { BaseProtocol } from "../base_protocol.js";
|
4
|
+
export declare const StoreCodec = "/vac/waku/store-query/3.0.0";
|
5
|
+
export declare class StoreCore extends BaseProtocol implements IStoreCore {
|
6
|
+
readonly pubsubTopics: PubsubTopic[];
|
7
|
+
constructor(pubsubTopics: PubsubTopic[], libp2p: Libp2p);
|
8
|
+
queryPerPage<T extends IDecodedMessage>(queryOpts: QueryRequestParams, decoders: Map<string, IDecoder<T>>, peerId: PeerId): AsyncGenerator<Promise<T | undefined>[]>;
|
9
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { Logger } from "@waku/utils";
|
2
|
+
import all from "it-all";
|
3
|
+
import * as lp from "it-length-prefixed";
|
4
|
+
import { pipe } from "it-pipe";
|
5
|
+
import { Uint8ArrayList } from "uint8arraylist";
|
6
|
+
import { BaseProtocol } from "../base_protocol.js";
|
7
|
+
import { toProtoMessage } from "../to_proto_message.js";
|
8
|
+
import { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, StoreQueryRequest, StoreQueryResponse } from "./rpc.js";
|
9
|
+
const log = new Logger("store");
|
10
|
+
export const StoreCodec = "/vac/waku/store-query/3.0.0";
|
11
|
+
export class StoreCore extends BaseProtocol {
|
12
|
+
pubsubTopics;
|
13
|
+
constructor(pubsubTopics, libp2p) {
|
14
|
+
super(StoreCodec, libp2p.components, pubsubTopics);
|
15
|
+
this.pubsubTopics = pubsubTopics;
|
16
|
+
}
|
17
|
+
async *queryPerPage(queryOpts, decoders, peerId) {
|
18
|
+
if (queryOpts.contentTopics.toString() !==
|
19
|
+
Array.from(decoders.keys()).toString()) {
|
20
|
+
throw new Error("Internal error, the decoders should match the query's content topics");
|
21
|
+
}
|
22
|
+
let currentCursor = queryOpts.paginationCursor;
|
23
|
+
while (true) {
|
24
|
+
const storeQueryRequest = StoreQueryRequest.create({
|
25
|
+
...queryOpts,
|
26
|
+
paginationCursor: currentCursor
|
27
|
+
});
|
28
|
+
let stream;
|
29
|
+
try {
|
30
|
+
stream = await this.getStream(peerId);
|
31
|
+
}
|
32
|
+
catch (e) {
|
33
|
+
log.error("Failed to get stream", e);
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
const res = await pipe([storeQueryRequest.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
|
37
|
+
const bytes = new Uint8ArrayList();
|
38
|
+
res.forEach((chunk) => {
|
39
|
+
bytes.append(chunk);
|
40
|
+
});
|
41
|
+
const storeQueryResponse = StoreQueryResponse.decode(bytes);
|
42
|
+
if (!storeQueryResponse.statusCode ||
|
43
|
+
storeQueryResponse.statusCode >= 300) {
|
44
|
+
const errorMessage = `Store query failed with status code: ${storeQueryResponse.statusCode}, description: ${storeQueryResponse.statusDesc}`;
|
45
|
+
log.error(errorMessage);
|
46
|
+
throw new Error(errorMessage);
|
47
|
+
}
|
48
|
+
if (!storeQueryResponse.messages || !storeQueryResponse.messages.length) {
|
49
|
+
log.warn("Stopping pagination due to empty messages in response");
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
log.info(`${storeQueryResponse.messages.length} messages retrieved from store`);
|
53
|
+
const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
|
54
|
+
if (!protoMsg.message) {
|
55
|
+
return Promise.resolve(undefined);
|
56
|
+
}
|
57
|
+
const contentTopic = protoMsg.message.contentTopic;
|
58
|
+
if (contentTopic) {
|
59
|
+
const decoder = decoders.get(contentTopic);
|
60
|
+
if (decoder) {
|
61
|
+
return decoder.fromProtoObj(protoMsg.pubsubTopic || "", toProtoMessage(protoMsg.message));
|
62
|
+
}
|
63
|
+
}
|
64
|
+
return Promise.resolve(undefined);
|
65
|
+
});
|
66
|
+
yield decodedMessages;
|
67
|
+
if (queryOpts.paginationForward) {
|
68
|
+
currentCursor =
|
69
|
+
storeQueryResponse.messages[storeQueryResponse.messages.length - 1]
|
70
|
+
.messageHash;
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
currentCursor = storeQueryResponse.messages[0].messageHash;
|
74
|
+
}
|
75
|
+
if (storeQueryResponse.messages.length > MAX_PAGE_SIZE &&
|
76
|
+
storeQueryResponse.messages.length <
|
77
|
+
(queryOpts.paginationLimit || DEFAULT_PAGE_SIZE)) {
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
//#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C;IACH,CAAC;CACF"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { PeerId, Stream } from "@libp2p/interface";
|
2
2
|
import type { Libp2p } from "@waku/interfaces";
|
3
3
|
export declare class StreamManager {
|
4
4
|
private multicodec;
|
@@ -8,7 +8,7 @@ export declare class StreamManager {
|
|
8
8
|
private ongoingCreation;
|
9
9
|
private streamPool;
|
10
10
|
constructor(multicodec: string, getConnections: Libp2p["getConnections"], addEventListener: Libp2p["addEventListener"]);
|
11
|
-
getStream(
|
11
|
+
getStream(peerId: PeerId): Promise<Stream>;
|
12
12
|
private createStream;
|
13
13
|
private createStreamWithLock;
|
14
14
|
private handlePeerUpdateStreamPool;
|
@@ -15,36 +15,36 @@ export class StreamManager {
|
|
15
15
|
this.log = new Logger(`stream-manager:${multicodec}`);
|
16
16
|
this.addEventListener("peer:update", this.handlePeerUpdateStreamPool);
|
17
17
|
}
|
18
|
-
async getStream(
|
19
|
-
const
|
20
|
-
const scheduledStream = this.streamPool.get(
|
18
|
+
async getStream(peerId) {
|
19
|
+
const peerIdStr = peerId.toString();
|
20
|
+
const scheduledStream = this.streamPool.get(peerIdStr);
|
21
21
|
if (scheduledStream) {
|
22
|
-
this.streamPool.delete(
|
22
|
+
this.streamPool.delete(peerIdStr);
|
23
23
|
await scheduledStream;
|
24
24
|
}
|
25
|
-
let stream = this.getOpenStreamForCodec(
|
25
|
+
let stream = this.getOpenStreamForCodec(peerId);
|
26
26
|
if (stream) {
|
27
|
-
this.log.info(`Found existing stream peerId=${
|
28
|
-
this.lockStream(
|
27
|
+
this.log.info(`Found existing stream peerId=${peerIdStr} multicodec=${this.multicodec}`);
|
28
|
+
this.lockStream(peerIdStr, stream);
|
29
29
|
return stream;
|
30
30
|
}
|
31
|
-
stream = await this.createStream(
|
32
|
-
this.lockStream(
|
31
|
+
stream = await this.createStream(peerId);
|
32
|
+
this.lockStream(peerIdStr, stream);
|
33
33
|
return stream;
|
34
34
|
}
|
35
|
-
async createStream(
|
36
|
-
const connections = this.getConnections(
|
35
|
+
async createStream(peerId, retries = 0) {
|
36
|
+
const connections = this.getConnections(peerId);
|
37
37
|
const connection = selectOpenConnection(connections);
|
38
38
|
if (!connection) {
|
39
|
-
throw new Error(`Failed to get a connection to the peer peerId=${
|
39
|
+
throw new Error(`Failed to get a connection to the peer peerId=${peerId.toString()} multicodec=${this.multicodec}`);
|
40
40
|
}
|
41
41
|
let lastError;
|
42
42
|
let stream;
|
43
43
|
for (let i = 0; i < retries + 1; i++) {
|
44
44
|
try {
|
45
|
-
this.log.info(`Attempting to create a stream for peerId=${
|
45
|
+
this.log.info(`Attempting to create a stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`);
|
46
46
|
stream = await connection.newStream(this.multicodec);
|
47
|
-
this.log.info(`Created stream for peerId=${
|
47
|
+
this.log.info(`Created stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`);
|
48
48
|
break;
|
49
49
|
}
|
50
50
|
catch (error) {
|
@@ -52,8 +52,7 @@ export class StreamManager {
|
|
52
52
|
}
|
53
53
|
}
|
54
54
|
if (!stream) {
|
55
|
-
throw new Error(`Failed to create a new stream for ${
|
56
|
-
lastError);
|
55
|
+
throw new Error(`Failed to create a new stream for ${peerId.toString()} -- ` + lastError);
|
57
56
|
}
|
58
57
|
return stream;
|
59
58
|
}
|
@@ -65,7 +64,7 @@ export class StreamManager {
|
|
65
64
|
}
|
66
65
|
try {
|
67
66
|
this.ongoingCreation.add(peerId);
|
68
|
-
await this.createStream(peer);
|
67
|
+
await this.createStream(peer.id);
|
69
68
|
}
|
70
69
|
catch (error) {
|
71
70
|
this.log.error(`Failed to createStreamWithLock:`, error);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stream_manager.js","sourceRoot":"","sources":["../../../src/lib/stream_manager/stream_manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,oBAAoB,EAAE,MAAM,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,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CACpC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,UAAU,CACtC,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QAED,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAC7D,MAAM,CAAC,WAAW,IAAI,EAAE,CACzB,CAAC;QACF,IAAI,gBAAgB,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YACpD,OAAO;QACT,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,UAAU,CAAC,MAAc,EAAE,MAAc;QAC/C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,6BAA6B,MAAM,cAAc,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;IAC1C,CAAC;IAEO,cAAc,CAAC,MAAc;QACnC,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@waku/core","version":"0.0.34-
|
1
|
+
{"name":"@waku/core","version":"0.0.34-caeafce.0","description":"TypeScript implementation of the Waku v2 protocol","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./lib/message/version_0":{"types":"./dist/lib/message/version_0.d.ts","import":"./dist/lib/message/version_0.js"},"./lib/base_protocol":{"types":"./dist/lib/base_protocol.d.ts","import":"./dist/lib/base_protocol.js"}},"typesVersions":{"*":{"lib/*":["dist/lib/*"],"constants/*":["dist/constants/*"]}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/core#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralised","communication","web3","ethereum","dapps"],"scripts":{"build":"run-s build:**","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint src *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"NODE_ENV=test karma start karma.conf.cjs","watch:build":"tsc -p tsconfig.json -w","watch:test":"mocha --watch","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=20"},"dependencies":{"@waku/enr":"0.0.28-caeafce.0","@waku/interfaces":"0.0.29-caeafce.0","@libp2p/ping":"2.0.1","@waku/proto":"0.0.9-caeafce.0","@waku/utils":"0.0.22-caeafce.0","debug":"^4.3.4","it-all":"^3.0.4","it-length-prefixed":"^9.0.4","it-pipe":"^3.0.1","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@libp2p/peer-id":"^5.0.1","@libp2p/interface":"^2.1.3","@multiformats/multiaddr":"^12.0.0","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/debug":"^4.1.12","@types/mocha":"^10.0.6","@types/uuid":"^9.0.8","@waku/build-utils":"*","chai":"^4.3.10","sinon":"^18.0.0","cspell":"^8.6.1","fast-check":"^3.19.0","ignore-loader":"^0.1.2","isomorphic-fetch":"^3.0.0","mocha":"^10.3.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^4.12.0"},"peerDependencies":{"@multiformats/multiaddr":"^12.0.0","libp2p":"2.1.8"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true},"libp2p":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
|
package/src/index.ts
CHANGED
@@ -17,8 +17,6 @@ export { StoreCore, StoreCodec } from "./lib/store/index.js";
|
|
17
17
|
|
18
18
|
export { ConnectionManager } from "./lib/connection_manager/index.js";
|
19
19
|
|
20
|
-
export { getHealthManager } from "./lib/health_manager.js";
|
21
|
-
|
22
20
|
export { StreamManager } from "./lib/stream_manager/index.js";
|
23
21
|
|
24
22
|
export { MetadataCodec, wakuMetadata } from "./lib/metadata/index.js";
|
package/src/lib/base_protocol.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Libp2p } from "@libp2p/interface";
|
2
|
-
import type {
|
2
|
+
import type { PeerId, Stream } from "@libp2p/interface";
|
3
3
|
import type {
|
4
4
|
IBaseProtocolCore,
|
5
5
|
Libp2pComponents,
|
@@ -38,7 +38,7 @@ export class BaseProtocol implements IBaseProtocolCore {
|
|
38
38
|
);
|
39
39
|
}
|
40
40
|
|
41
|
-
protected async getStream(
|
42
|
-
return this.streamManager.getStream(
|
41
|
+
protected async getStream(peerId: PeerId): Promise<Stream> {
|
42
|
+
return this.streamManager.getStream(peerId);
|
43
43
|
}
|
44
44
|
}
|