@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.
Files changed (71) hide show
  1. package/bundle/{base_protocol-C6HnrRx8.js → base_protocol-Dge5_tvU.js} +22 -25
  2. package/bundle/{index-DnW8ifxc.js → index-Gts2Ddu_.js} +41 -56
  3. package/bundle/index.js +291 -288
  4. package/bundle/lib/base_protocol.js +2 -2
  5. package/bundle/lib/message/version_0.js +2 -2
  6. package/bundle/{version_0-DQ9xsSLk.js → version_0-CNRKFufI.js} +154 -308
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +2 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/base_protocol.d.ts +3 -4
  12. package/dist/lib/base_protocol.js +4 -8
  13. package/dist/lib/base_protocol.js.map +1 -1
  14. package/dist/lib/connection_manager.d.ts +2 -2
  15. package/dist/lib/connection_manager.js +21 -23
  16. package/dist/lib/connection_manager.js.map +1 -1
  17. package/dist/lib/filter/filter_rpc.js.map +1 -1
  18. package/dist/lib/filter/index.d.ts +4 -3
  19. package/dist/lib/filter/index.js +33 -31
  20. package/dist/lib/filter/index.js.map +1 -1
  21. package/dist/lib/health_manager.d.ts +14 -0
  22. package/dist/lib/health_manager.js +70 -0
  23. package/dist/lib/health_manager.js.map +1 -0
  24. package/dist/lib/keep_alive_manager.d.ts +13 -7
  25. package/dist/lib/keep_alive_manager.js +9 -9
  26. package/dist/lib/keep_alive_manager.js.map +1 -1
  27. package/dist/lib/light_push/index.d.ts +3 -2
  28. package/dist/lib/light_push/index.js +4 -2
  29. package/dist/lib/light_push/index.js.map +1 -1
  30. package/dist/lib/light_push/push_rpc.js.map +1 -1
  31. package/dist/lib/message/version_0.js.map +1 -1
  32. package/dist/lib/metadata/index.d.ts +2 -2
  33. package/dist/lib/metadata/index.js +26 -26
  34. package/dist/lib/metadata/index.js.map +1 -1
  35. package/dist/lib/store/index.d.ts +5 -44
  36. package/dist/lib/store/index.js +39 -45
  37. package/dist/lib/store/index.js.map +1 -1
  38. package/dist/lib/store/rpc.d.ts +22 -0
  39. package/dist/lib/store/rpc.js +74 -0
  40. package/dist/lib/store/rpc.js.map +1 -0
  41. package/dist/lib/stream_manager/index.d.ts +1 -0
  42. package/dist/lib/stream_manager/index.js +2 -0
  43. package/dist/lib/stream_manager/index.js.map +1 -0
  44. package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
  45. package/dist/lib/stream_manager/stream_manager.js.map +1 -0
  46. package/dist/lib/stream_manager/utils.d.ts +2 -0
  47. package/dist/lib/stream_manager/utils.js +19 -0
  48. package/dist/lib/stream_manager/utils.js.map +1 -0
  49. package/package.json +1 -1
  50. package/src/index.ts +3 -3
  51. package/src/lib/base_protocol.ts +7 -10
  52. package/src/lib/connection_manager.ts +29 -30
  53. package/src/lib/filter/filter_rpc.ts +21 -19
  54. package/src/lib/filter/index.ts +50 -52
  55. package/src/lib/health_manager.ts +90 -0
  56. package/src/lib/keep_alive_manager.ts +27 -18
  57. package/src/lib/light_push/index.ts +7 -10
  58. package/src/lib/light_push/push_rpc.ts +5 -5
  59. package/src/lib/message/version_0.ts +17 -15
  60. package/src/lib/metadata/index.ts +43 -44
  61. package/src/lib/store/index.ts +54 -94
  62. package/src/lib/store/rpc.ts +92 -0
  63. package/src/lib/stream_manager/index.ts +1 -0
  64. package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
  65. package/src/lib/stream_manager/utils.ts +22 -0
  66. package/dist/lib/store/history_rpc.d.ts +0 -27
  67. package/dist/lib/store/history_rpc.js +0 -72
  68. package/dist/lib/store/history_rpc.js.map +0 -1
  69. package/dist/lib/stream_manager.js.map +0 -1
  70. package/src/lib/store/history_rpc.ts +0 -93
  71. /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -1,48 +1,9 @@
1
1
  import type { Peer } from "@libp2p/interface";
2
- import { Cursor, IDecodedMessage, IDecoder, IStoreCore, Libp2p, ProtocolCreateOptions } from "@waku/interfaces";
2
+ import { IDecodedMessage, IDecoder, IStoreCore, Libp2p, PubsubTopic, QueryRequestParams } from "@waku/interfaces";
3
3
  import { BaseProtocol } from "../base_protocol.js";
4
- import { PageDirection, Params } from "./history_rpc.js";
5
- export declare const StoreCodec = "/vac/waku/store/2.0.0-beta4";
6
- export { PageDirection, Params };
7
- export interface TimeFilter {
8
- startTime: Date;
9
- endTime: Date;
10
- }
11
- export interface QueryOptions {
12
- /**
13
- * The direction in which pages are retrieved:
14
- * - { @link PageDirection.BACKWARD }: Most recent page first.
15
- * - { @link PageDirection.FORWARD }: Oldest page first.
16
- *
17
- * Note: This does not affect the ordering of messages with the page
18
- * (the oldest message is always first).
19
- *
20
- * @default { @link PageDirection.BACKWARD }
21
- */
22
- pageDirection?: PageDirection;
23
- /**
24
- * The number of message per page.
25
- *
26
- * @default { @link DefaultPageSize }
27
- */
28
- pageSize?: number;
29
- /**
30
- * Retrieve messages with a timestamp within the provided values.
31
- */
32
- timeFilter?: TimeFilter;
33
- /**
34
- * Cursor as an index to start a query from.
35
- * The cursor index will be exclusive (i.e. the message at the cursor index will not be included in the result).
36
- * If undefined, the query will start from the beginning or end of the history, depending on the page direction.
37
- */
38
- cursor?: Cursor;
39
- }
40
- /**
41
- * Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/).
42
- *
43
- * The Waku Store protocol can be used to retrieved historical messages.
44
- */
4
+ export declare const StoreCodec = "/vac/waku/store-query/3.0.0";
45
5
  export declare class StoreCore extends BaseProtocol implements IStoreCore {
46
- constructor(libp2p: Libp2p, options?: ProtocolCreateOptions);
47
- queryPerPage<T extends IDecodedMessage>(queryOpts: Params, decoders: Map<string, IDecoder<T>>, peer: Peer): AsyncGenerator<Promise<T | undefined>[]>;
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>[]>;
48
9
  }
@@ -1,4 +1,3 @@
1
- import { proto_store as proto } from "@waku/proto";
2
1
  import { Logger } from "@waku/utils";
3
2
  import all from "it-all";
4
3
  import * as lp from "it-length-prefixed";
@@ -6,29 +5,26 @@ import { pipe } from "it-pipe";
6
5
  import { Uint8ArrayList } from "uint8arraylist";
7
6
  import { BaseProtocol } from "../base_protocol.js";
8
7
  import { toProtoMessage } from "../to_proto_message.js";
9
- import { HistoryRpc, PageDirection } from "./history_rpc.js";
10
- var HistoryError = proto.HistoryResponse.HistoryError;
8
+ import { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, StoreQueryRequest, StoreQueryResponse } from "./rpc.js";
11
9
  const log = new Logger("store");
12
- export const StoreCodec = "/vac/waku/store/2.0.0-beta4";
13
- export { PageDirection };
14
- /**
15
- * Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/).
16
- *
17
- * The Waku Store protocol can be used to retrieved historical messages.
18
- */
10
+ export const StoreCodec = "/vac/waku/store-query/3.0.0";
19
11
  export class StoreCore extends BaseProtocol {
20
- constructor(libp2p, options) {
21
- super(StoreCodec, libp2p.components, log, options.pubsubTopics, options);
12
+ pubsubTopics;
13
+ constructor(pubsubTopics, libp2p) {
14
+ super(StoreCodec, libp2p.components, log, pubsubTopics);
15
+ this.pubsubTopics = pubsubTopics;
22
16
  }
23
17
  async *queryPerPage(queryOpts, decoders, peer) {
24
18
  if (queryOpts.contentTopics.toString() !==
25
19
  Array.from(decoders.keys()).toString()) {
26
20
  throw new Error("Internal error, the decoders should match the query's content topics");
27
21
  }
28
- let currentCursor = queryOpts.cursor;
22
+ let currentCursor = queryOpts.paginationCursor;
29
23
  while (true) {
30
- queryOpts.cursor = currentCursor;
31
- const historyRpcQuery = HistoryRpc.createQuery(queryOpts);
24
+ const storeQueryRequest = StoreQueryRequest.create({
25
+ ...queryOpts,
26
+ paginationCursor: currentCursor
27
+ });
32
28
  let stream;
33
29
  try {
34
30
  stream = await this.getStream(peer);
@@ -37,50 +33,48 @@ export class StoreCore extends BaseProtocol {
37
33
  log.error("Failed to get stream", e);
38
34
  break;
39
35
  }
40
- const res = await pipe([historyRpcQuery.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
36
+ const res = await pipe([storeQueryRequest.encode()], lp.encode, stream, lp.decode, async (source) => await all(source));
41
37
  const bytes = new Uint8ArrayList();
42
38
  res.forEach((chunk) => {
43
39
  bytes.append(chunk);
44
40
  });
45
- const reply = historyRpcQuery.decode(bytes);
46
- if (!reply.response) {
47
- log.warn("Stopping pagination due to store `response` field missing");
48
- break;
49
- }
50
- const response = reply.response;
51
- if (response.error && response.error !== HistoryError.NONE) {
52
- throw "History response contains an Error: " + response.error;
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);
53
47
  }
54
- if (!response.messages || !response.messages.length) {
55
- log.warn("Stopping pagination due to store `response.messages` field missing or empty");
48
+ if (!storeQueryResponse.messages || !storeQueryResponse.messages.length) {
49
+ log.warn("Stopping pagination due to empty messages in response");
56
50
  break;
57
51
  }
58
- log.error(`${response.messages.length} messages retrieved from store`);
59
- yield response.messages.map((protoMsg) => {
60
- const contentTopic = protoMsg.contentTopic;
61
- if (typeof contentTopic !== "undefined") {
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) {
62
59
  const decoder = decoders.get(contentTopic);
63
60
  if (decoder) {
64
- return decoder.fromProtoObj(queryOpts.pubsubTopic, toProtoMessage(protoMsg));
61
+ return decoder.fromProtoObj(protoMsg.pubsubTopic || "", toProtoMessage(protoMsg.message));
65
62
  }
66
63
  }
67
64
  return Promise.resolve(undefined);
68
65
  });
69
- const nextCursor = response.pagingInfo?.cursor;
70
- if (typeof nextCursor === "undefined") {
71
- // If the server does not return cursor then there is an issue,
72
- // Need to abort, or we end up in an infinite loop
73
- log.warn("Stopping pagination due to `response.pagingInfo.cursor` missing from store response");
74
- break;
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;
75
74
  }
76
- currentCursor = nextCursor;
77
- const responsePageSize = response.pagingInfo?.pageSize;
78
- const queryPageSize = historyRpcQuery.query?.pagingInfo?.pageSize;
79
- if (
80
- // Response page size smaller than query, meaning this is the last page
81
- responsePageSize &&
82
- queryPageSize &&
83
- responsePageSize < queryPageSize) {
75
+ if (storeQueryResponse.messages.length > MAX_PAGE_SIZE &&
76
+ storeQueryResponse.messages.length <
77
+ (queryOpts.paginationLimit || DEFAULT_PAGE_SIZE)) {
84
78
  break;
85
79
  }
86
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/store/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACnD,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;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,M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AG,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;oBAC3C,IAAI,OAAO,EAAE,CAAC;wBACZ,OAAO,OAAO,CAAC,YAAY,CACzB,QAAQ,CAAC,WAAW,IAAI,EAAE,EAC1B,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CACjC,CAAC;oBACJ,CAAC;gBACH,CAAC;gBACD,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;YAEH,MAAM,eAAe,CAAC;YAEtB,IAAI,SAAS,CAAC,iBAAiB,EAAE,CAAC;gBAChC,aAAa;oBACX,kBAAkB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;yBAChE,WAAW,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACN,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAC7D,CAAC;YAED,IACE,kBAAkB,CAAC,QAAQ,CAAC,MAAM,GAAG,aAAa;gBAClD,kBAAkB,CAAC,QAAQ,CAAC,MAAM;oBAChC,CAAC,SAAS,CAAC,eAAe,IAAI,iBAAiB,CAAC,EAClD,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { QueryRequestParams } from "@waku/interfaces";
2
+ import { proto_store as proto } from "@waku/proto";
3
+ import type { Uint8ArrayList } from "uint8arraylist";
4
+ export declare const DEFAULT_PAGE_SIZE = 20;
5
+ export declare const MAX_PAGE_SIZE = 100;
6
+ export declare class StoreQueryRequest {
7
+ proto: proto.StoreQueryRequest;
8
+ constructor(proto: proto.StoreQueryRequest);
9
+ static create(params: QueryRequestParams): StoreQueryRequest;
10
+ static decode(bytes: Uint8ArrayList): StoreQueryRequest;
11
+ encode(): Uint8Array;
12
+ }
13
+ export declare class StoreQueryResponse {
14
+ proto: proto.StoreQueryResponse;
15
+ constructor(proto: proto.StoreQueryResponse);
16
+ static decode(bytes: Uint8ArrayList): StoreQueryResponse;
17
+ encode(): Uint8Array;
18
+ get statusCode(): number | undefined;
19
+ get statusDesc(): string | undefined;
20
+ get messages(): proto.WakuMessageKeyValue[];
21
+ get paginationCursor(): Uint8Array | undefined;
22
+ }
@@ -0,0 +1,74 @@
1
+ import { proto_store as proto } from "@waku/proto";
2
+ import { v4 as uuid } from "uuid";
3
+ // https://github.com/waku-org/nwaku/blob/7205f95cff9f49ca0bb762e8fd0bf56a6a7f3b3b/waku/waku_store/common.nim#L12
4
+ export const DEFAULT_PAGE_SIZE = 20;
5
+ export const MAX_PAGE_SIZE = 100;
6
+ const ONE_MILLION = 1_000000;
7
+ export class StoreQueryRequest {
8
+ proto;
9
+ constructor(proto) {
10
+ this.proto = proto;
11
+ }
12
+ static create(params) {
13
+ const request = new StoreQueryRequest({
14
+ ...params,
15
+ requestId: uuid(),
16
+ timeStart: params.timeStart
17
+ ? BigInt(params.timeStart.getTime() * ONE_MILLION)
18
+ : undefined,
19
+ timeEnd: params.timeEnd
20
+ ? BigInt(params.timeEnd.getTime() * ONE_MILLION)
21
+ : undefined,
22
+ messageHashes: params.messageHashes || [],
23
+ paginationLimit: params.paginationLimit
24
+ ? BigInt(params.paginationLimit)
25
+ : undefined
26
+ });
27
+ // Validate request parameters based on RFC
28
+ if ((params.pubsubTopic && !params.contentTopics) ||
29
+ (!params.pubsubTopic && params.contentTopics)) {
30
+ throw new Error("Both pubsubTopic and contentTopics must be set or unset");
31
+ }
32
+ if (params.messageHashes &&
33
+ (params.pubsubTopic ||
34
+ params.contentTopics ||
35
+ params.timeStart ||
36
+ params.timeEnd)) {
37
+ throw new Error("Message hash lookup queries cannot include content filter criteria");
38
+ }
39
+ return request;
40
+ }
41
+ static decode(bytes) {
42
+ const res = proto.StoreQueryRequest.decode(bytes);
43
+ return new StoreQueryRequest(res);
44
+ }
45
+ encode() {
46
+ return proto.StoreQueryRequest.encode(this.proto);
47
+ }
48
+ }
49
+ export class StoreQueryResponse {
50
+ proto;
51
+ constructor(proto) {
52
+ this.proto = proto;
53
+ }
54
+ static decode(bytes) {
55
+ const res = proto.StoreQueryResponse.decode(bytes);
56
+ return new StoreQueryResponse(res);
57
+ }
58
+ encode() {
59
+ return proto.StoreQueryResponse.encode(this.proto);
60
+ }
61
+ get statusCode() {
62
+ return this.proto.statusCode;
63
+ }
64
+ get statusDesc() {
65
+ return this.proto.statusDesc;
66
+ }
67
+ get messages() {
68
+ return this.proto.messages;
69
+ }
70
+ get paginationCursor() {
71
+ return this.proto.paginationCursor;
72
+ }
73
+ }
74
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/lib/store/rpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,iHAAiH;AACjH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,MAAM,OAAO,iBAAiB;IACF;IAA1B,YAA0B,KAA8B;QAA9B,UAAK,GAAL,KAAK,CAAyB;IAAG,CAAC;IAErD,MAAM,CAAC,MAAM,CAAC,MAA0B;QAC7C,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC;YACpC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,EAAE;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;gBACzB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC;gBAClD,CAAC,CAAC,SAAS;YACb,OAAO,EAAE,MAAM,CAAC,OAAO;gBACrB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAA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AO,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,IAAW,gBAAgB;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export { StreamManager } from "./stream_manager.js";
@@ -0,0 +1,2 @@
1
+ export { StreamManager } from "./stream_manager.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/stream_manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Logger } from "@waku/utils";
2
- import { selectConnection } from "@waku/utils/libp2p";
2
+ import { selectConnection } from "./utils.js";
3
3
  const CONNECTION_TIMEOUT = 5_000;
4
4
  const RETRY_BACKOFF_BASE = 1_000;
5
5
  const MAX_RETRIES = 3;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream_manager.js","sourceRoot":"","sources":["../../../src/lib/stream_manager/stream_manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,WAA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,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IACxE,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ import type { Connection } from "@libp2p/interface";
2
+ export declare function selectConnection(connections: Connection[]): Connection | undefined;
@@ -0,0 +1,19 @@
1
+ export function selectConnection(connections) {
2
+ if (!connections.length)
3
+ return;
4
+ if (connections.length === 1)
5
+ return connections[0];
6
+ let latestConnection;
7
+ connections.forEach((connection) => {
8
+ if (connection.status === "open") {
9
+ if (!latestConnection) {
10
+ latestConnection = connection;
11
+ }
12
+ else if (connection.timeline.open > latestConnection.timeline.open) {
13
+ latestConnection = connection;
14
+ }
15
+ }
16
+ });
17
+ return latestConnection;
18
+ }
19
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/stream_manager/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAC9B,WAAyB;IAEzB,IAAI,CAAC,WAAW,CAAC,MAAM;QAAE,OAAO;IAChC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IAEpD,IAAI,gBAAwC,CAAC;IAE7C,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACjC,IAAI,UAAU,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,gBAAgB,GAAG,UAAU,CAAC;YAChC,CAAC;iBAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACrE,gBAAgB,GAAG,UAAU,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@waku/core","version":"0.0.31-ce62600.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":">=18"},"dependencies":{"@libp2p/ping":"^1.0.12","@waku/enr":"0.0.25-ce62600.0","@waku/interfaces":"0.0.26-ce62600.0","@waku/proto":"0.0.8-ce62600.0","@waku/utils":"0.0.19-ce62600.0","debug":"^4.3.4","it-all":"^3.0.4","it-length-prefixed":"^9.0.4","it-pipe":"^3.0.1","p-event":"^6.0.1","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@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","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":"^1.1.2","@waku/enr":"0.0.25-ce62600.0","@waku/interfaces":"0.0.26-ce62600.0","@waku/proto":"0.0.8-ce62600.0","@waku/utils":"0.0.19-ce62600.0"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true},"@waku/interfaces":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
1
+ {"name":"@waku/core","version":"0.0.31-f387f59.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":{"@libp2p/ping":"^1.1.2","@waku/enr":"0.0.25-f387f59.0","@waku/interfaces":"0.0.26-f387f59.0","@waku/proto":"0.0.8-f387f59.0","@waku/utils":"0.0.19-f387f59.0","debug":"^4.3.4","it-all":"^3.0.4","it-length-prefixed":"^9.0.4","it-pipe":"^3.0.1","p-event":"^6.0.1","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@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","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":"^1.8.1","@waku/enr":"0.0.25-f387f59.0","@waku/interfaces":"0.0.26-f387f59.0","@waku/proto":"0.0.8-f387f59.0","@waku/utils":"0.0.19-f387f59.0"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true},"@waku/interfaces":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
package/src/index.ts CHANGED
@@ -15,13 +15,13 @@ export { LightPushCodec, LightPushCore } from "./lib/light_push/index.js";
15
15
  export * as waku_store from "./lib/store/index.js";
16
16
  export { StoreCore } from "./lib/store/index.js";
17
17
 
18
- export { PageDirection } from "./lib/store/index.js";
19
-
20
18
  export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js";
21
19
 
22
20
  export { ConnectionManager } from "./lib/connection_manager.js";
23
21
 
22
+ export { getHealthManager } from "./lib/health_manager.js";
23
+
24
24
  export { KeepAliveManager } from "./lib/keep_alive_manager.js";
25
- export { StreamManager } from "./lib/stream_manager.js";
25
+ export { StreamManager } from "./lib/stream_manager/index.js";
26
26
 
27
27
  export { MetadataCodec, wakuMetadata } from "./lib/metadata/index.js";
@@ -3,10 +3,9 @@ import type { Peer, PeerStore, Stream } from "@libp2p/interface";
3
3
  import type {
4
4
  IBaseProtocolCore,
5
5
  Libp2pComponents,
6
- ProtocolCreateOptions,
7
6
  PubsubTopic
8
7
  } from "@waku/interfaces";
9
- import { ensureShardingConfigured, Logger } from "@waku/utils";
8
+ import { Logger, pubsubTopicsToShardInfo } from "@waku/utils";
10
9
  import {
11
10
  getConnectedPeersForProtocolAndShard,
12
11
  getPeersForProtocol,
@@ -14,7 +13,7 @@ import {
14
13
  } from "@waku/utils/libp2p";
15
14
 
16
15
  import { filterPeersByDiscovery } from "./filterPeers.js";
17
- import { StreamManager } from "./stream_manager.js";
16
+ import { StreamManager } from "./stream_manager/index.js";
18
17
 
19
18
  /**
20
19
  * A class with predefined helpers, to be used as a base to implement Waku
@@ -25,12 +24,11 @@ export class BaseProtocol implements IBaseProtocolCore {
25
24
  public readonly removeLibp2pEventListener: Libp2p["removeEventListener"];
26
25
  protected streamManager: StreamManager;
27
26
 
28
- constructor(
27
+ protected constructor(
29
28
  public multicodec: string,
30
29
  private components: Libp2pComponents,
31
30
  private log: Logger,
32
- public readonly pubsubTopics: PubsubTopic[],
33
- private options?: ProtocolCreateOptions
31
+ public readonly pubsubTopics: PubsubTopic[]
34
32
  ) {
35
33
  this.addLibp2pEventListener = components.events.addEventListener.bind(
36
34
  components.events
@@ -47,6 +45,7 @@ export class BaseProtocol implements IBaseProtocolCore {
47
45
  this.addLibp2pEventListener
48
46
  );
49
47
  }
48
+
50
49
  protected async getStream(peer: Peer): Promise<Stream> {
51
50
  return this.streamManager.getStream(peer);
52
51
  }
@@ -81,7 +80,7 @@ export class BaseProtocol implements IBaseProtocolCore {
81
80
 
82
81
  * @returns A list of peers that support the protocol sorted by latency.
83
82
  */
84
- async getPeers(
83
+ public async getPeers(
85
84
  {
86
85
  numPeers,
87
86
  maxBootstrapPeers
@@ -99,9 +98,7 @@ export class BaseProtocol implements IBaseProtocolCore {
99
98
  this.components.connectionManager.getConnections(),
100
99
  this.peerStore,
101
100
  [this.multicodec],
102
- this.options?.shardInfo
103
- ? ensureShardingConfigured(this.options.shardInfo).shardInfo
104
- : undefined
101
+ pubsubTopicsToShardInfo(this.pubsubTopics)
105
102
  );
106
103
 
107
104
  // Filter the peers based on discovery & number of peers requested
@@ -89,7 +89,7 @@ export class ConnectionManager
89
89
  return instance;
90
90
  }
91
91
 
92
- stop(): void {
92
+ public stop(): void {
93
93
  this.keepAliveManager.stopAll();
94
94
  this.libp2p.removeEventListener(
95
95
  "peer:connect",
@@ -105,7 +105,7 @@ export class ConnectionManager
105
105
  );
106
106
  }
107
107
 
108
- async dropConnection(peerId: PeerId): Promise<void> {
108
+ public async dropConnection(peerId: PeerId): Promise<void> {
109
109
  try {
110
110
  this.keepAliveManager.stop(peerId);
111
111
  await this.libp2p.hangUp(peerId);
@@ -173,7 +173,7 @@ export class ConnectionManager
173
173
  private constructor(
174
174
  libp2p: Libp2p,
175
175
  keepAliveOptions: KeepAliveOptions,
176
- private configuredPubsubTopics: PubsubTopic[],
176
+ public readonly configuredPubsubTopics: PubsubTopic[],
177
177
  relay?: IRelay,
178
178
  options?: Partial<ConnectionManagerOptions>
179
179
  ) {
@@ -187,7 +187,11 @@ export class ConnectionManager
187
187
  ...options
188
188
  };
189
189
 
190
- this.keepAliveManager = new KeepAliveManager(keepAliveOptions, relay);
190
+ this.keepAliveManager = new KeepAliveManager({
191
+ relay,
192
+ libp2p,
193
+ options: keepAliveOptions
194
+ });
191
195
 
192
196
  this.run()
193
197
  .then(() => log.info(`Connection Manager is now running`))
@@ -250,6 +254,7 @@ export class ConnectionManager
250
254
  this.dialAttemptsForPeer.set(peerId.toString(), -1);
251
255
 
252
256
  // Dialing succeeded, break the loop
257
+ this.keepAliveManager.start(peerId);
253
258
  break;
254
259
  } catch (error) {
255
260
  if (error instanceof AggregateError) {
@@ -356,7 +361,7 @@ export class ConnectionManager
356
361
  );
357
362
  }
358
363
 
359
- private async attemptDial(peerId: PeerId): Promise<void> {
364
+ public async attemptDial(peerId: PeerId): Promise<void> {
360
365
  if (!(await this.shouldDialPeer(peerId))) return;
361
366
 
362
367
  if (this.currentActiveParallelDialCount >= this.options.maxParallelDials) {
@@ -364,9 +369,7 @@ export class ConnectionManager
364
369
  return;
365
370
  }
366
371
 
367
- this.dialPeer(peerId).catch((err) => {
368
- log.error(`Error dialing peer ${peerId.toString()} : ${err}`);
369
- });
372
+ await this.dialPeer(peerId);
370
373
  }
371
374
 
372
375
  private onEventHandlers = {
@@ -389,11 +392,7 @@ export class ConnectionManager
389
392
 
390
393
  const peerId = evt.detail;
391
394
 
392
- this.keepAliveManager.start(
393
- peerId,
394
- this.libp2p.services.ping,
395
- this.libp2p.peerStore
396
- );
395
+ this.keepAliveManager.start(peerId);
397
396
 
398
397
  const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
399
398
  Tags.BOOTSTRAP
@@ -449,38 +448,40 @@ export class ConnectionManager
449
448
  * @returns true if the peer should be dialed, false otherwise
450
449
  */
451
450
  private async shouldDialPeer(peerId: PeerId): Promise<boolean> {
452
- // if we're already connected to the peer, don't dial
453
451
  const isConnected = this.libp2p.getConnections(peerId).length > 0;
454
452
  if (isConnected) {
455
453
  log.warn(`Already connected to peer ${peerId.toString()}. Not dialing.`);
456
454
  return false;
457
455
  }
458
456
 
459
- // if the peer is not part of any of the configured pubsub topics, don't dial
460
- if (!(await this.isPeerTopicConfigured(peerId))) {
457
+ const isSameShard = await this.isPeerTopicConfigured(peerId);
458
+ if (!isSameShard) {
461
459
  const shardInfo = await this.getPeerShardInfo(
462
460
  peerId,
463
461
  this.libp2p.peerStore
464
462
  );
463
+
465
464
  log.warn(
466
465
  `Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
467
466
  this.configuredPubsubTopics
468
467
  }).
469
468
  Not dialing.`
470
469
  );
470
+
471
471
  return false;
472
472
  }
473
473
 
474
- // if the peer is not dialable based on bootstrap status, don't dial
475
- if (!(await this.isPeerDialableBasedOnBootstrapStatus(peerId))) {
474
+ const isPreferredBasedOnBootstrap =
475
+ await this.isPeerDialableBasedOnBootstrapStatus(peerId);
476
+ if (!isPreferredBasedOnBootstrap) {
476
477
  log.warn(
477
478
  `Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`
478
479
  );
479
480
  return false;
480
481
  }
481
482
 
482
- // If the peer is already already has an active dial attempt, or has been dialed before, don't dial it
483
- if (this.dialAttemptsForPeer.has(peerId.toString())) {
483
+ const hasBeenDialed = this.dialAttemptsForPeer.has(peerId.toString());
484
+ if (hasBeenDialed) {
484
485
  log.warn(
485
486
  `Peer ${peerId.toString()} has already been attempted dial before, or already has a dial attempt in progress, skipping dial`
486
487
  );
@@ -502,19 +503,17 @@ export class ConnectionManager
502
503
 
503
504
  const isBootstrap = tagNames.some((tagName) => tagName === Tags.BOOTSTRAP);
504
505
 
505
- if (isBootstrap) {
506
- const currentBootstrapConnections = this.libp2p
507
- .getConnections()
508
- .filter((conn) => {
509
- return conn.tags.find((name) => name === Tags.BOOTSTRAP);
510
- }).length;
511
- if (currentBootstrapConnections < this.options.maxBootstrapPeersAllowed)
512
- return true;
513
- } else {
506
+ if (!isBootstrap) {
514
507
  return true;
515
508
  }
516
509
 
517
- return false;
510
+ const currentBootstrapConnections = this.libp2p
511
+ .getConnections()
512
+ .filter((conn) => {
513
+ return conn.tags.find((name) => name === Tags.BOOTSTRAP);
514
+ }).length;
515
+
516
+ return currentBootstrapConnections < this.options.maxBootstrapPeersAllowed;
518
517
  }
519
518
 
520
519
  private async dispatchDiscoveryEvent(peerId: PeerId): Promise<void> {