@waku/core 0.0.20 → 0.0.21

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 (59) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/bundle/index.js +256 -302
  3. package/bundle/lib/base_protocol.js +11 -6
  4. package/bundle/lib/message/version_0.js +1 -1
  5. package/bundle/lib/predefined_bootstrap_nodes.js +6 -6
  6. package/bundle/{version_0-9c941081.js → version_0-86411fdf.js} +3 -3
  7. package/dist/index.d.ts +2 -4
  8. package/dist/index.js +2 -4
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/base_protocol.d.ts +9 -5
  11. package/dist/lib/base_protocol.js +11 -6
  12. package/dist/lib/base_protocol.js.map +1 -1
  13. package/dist/lib/connection_manager.d.ts +6 -4
  14. package/dist/lib/connection_manager.js +120 -42
  15. package/dist/lib/connection_manager.js.map +1 -1
  16. package/dist/lib/filter/filter_rpc.js.map +1 -0
  17. package/dist/lib/filter/index.d.ts +2 -0
  18. package/dist/lib/filter/{v2/index.js → index.js} +14 -19
  19. package/dist/lib/filter/index.js.map +1 -0
  20. package/dist/lib/keep_alive_manager.d.ts +2 -2
  21. package/dist/lib/keep_alive_manager.js +1 -1
  22. package/dist/lib/keep_alive_manager.js.map +1 -1
  23. package/dist/lib/light_push/index.d.ts +1 -2
  24. package/dist/lib/light_push/index.js +1 -3
  25. package/dist/lib/light_push/index.js.map +1 -1
  26. package/dist/lib/predefined_bootstrap_nodes.js +6 -6
  27. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  28. package/dist/lib/store/index.d.ts +1 -2
  29. package/dist/lib/store/index.js +1 -3
  30. package/dist/lib/store/index.js.map +1 -1
  31. package/dist/lib/wait_for_remote_peer.js +3 -3
  32. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  33. package/dist/lib/waku.d.ts +3 -4
  34. package/dist/lib/waku.js.map +1 -1
  35. package/package.json +9 -17
  36. package/src/index.ts +2 -5
  37. package/src/lib/base_protocol.ts +23 -9
  38. package/src/lib/connection_manager.ts +165 -65
  39. package/src/lib/filter/{v2/index.ts → index.ts} +19 -26
  40. package/src/lib/keep_alive_manager.ts +3 -3
  41. package/src/lib/light_push/index.ts +3 -3
  42. package/src/lib/predefined_bootstrap_nodes.ts +6 -6
  43. package/src/lib/store/index.ts +3 -3
  44. package/src/lib/wait_for_remote_peer.ts +7 -9
  45. package/src/lib/waku.ts +3 -4
  46. package/dist/lib/filter/v1/filter_rpc.d.ts +0 -23
  47. package/dist/lib/filter/v1/filter_rpc.js +0 -45
  48. package/dist/lib/filter/v1/filter_rpc.js.map +0 -1
  49. package/dist/lib/filter/v1/index.d.ts +0 -6
  50. package/dist/lib/filter/v1/index.js +0 -153
  51. package/dist/lib/filter/v1/index.js.map +0 -1
  52. package/dist/lib/filter/v2/filter_rpc.js.map +0 -1
  53. package/dist/lib/filter/v2/index.d.ts +0 -3
  54. package/dist/lib/filter/v2/index.js.map +0 -1
  55. package/src/lib/filter/v1/filter_rpc.ts +0 -53
  56. package/src/lib/filter/v1/index.ts +0 -248
  57. /package/dist/lib/filter/{v2/filter_rpc.d.ts → filter_rpc.d.ts} +0 -0
  58. /package/dist/lib/filter/{v2/filter_rpc.js → filter_rpc.js} +0 -0
  59. /package/src/lib/filter/{v2/filter_rpc.ts → filter_rpc.ts} +0 -0
@@ -79,12 +79,17 @@ function selectConnection(connections) {
79
79
  */
80
80
  class BaseProtocol {
81
81
  multicodec;
82
- peerStore;
83
- getConnections;
84
- constructor(multicodec, peerStore, getConnections) {
82
+ components;
83
+ addLibp2pEventListener;
84
+ removeLibp2pEventListener;
85
+ constructor(multicodec, components) {
85
86
  this.multicodec = multicodec;
86
- this.peerStore = peerStore;
87
- this.getConnections = getConnections;
87
+ this.components = components;
88
+ this.addLibp2pEventListener = components.events.addEventListener.bind(components.events);
89
+ this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
90
+ }
91
+ get peerStore() {
92
+ return this.components.peerStore;
88
93
  }
89
94
  /**
90
95
  * Returns known peers from the address book (`libp2p.peerStore`) that support
@@ -99,7 +104,7 @@ class BaseProtocol {
99
104
  return peer;
100
105
  }
101
106
  async newStream(peer) {
102
- const connections = this.getConnections(peer.id);
107
+ const connections = this.components.connectionManager.getConnections(peer.id);
103
108
  const connection = selectConnection(connections);
104
109
  if (!connection) {
105
110
  throw new Error("Failed to get a connection to the peer");
@@ -1,2 +1,2 @@
1
- export { D as DecodedMessage, h as Decoder, E as Encoder, V as Version, g as createDecoder, c as createEncoder, m as proto } from '../../version_0-9c941081.js';
1
+ export { D as DecodedMessage, g as Decoder, E as Encoder, V as Version, f as createDecoder, c as createEncoder, m as proto } from '../../version_0-86411fdf.js';
2
2
  import '../../browser-bde977a3.js';
@@ -61,16 +61,16 @@ const fleets = {
61
61
  fleets: {
62
62
  "wakuv2.prod": {
63
63
  "waku-websocket": {
64
- "node-01.ac-cn-hongkong-c.wakuv2.prod": "/dns4/node-01.ac-cn-hongkong-c.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD",
65
- "node-01.do-ams3.wakuv2.prod": "/dns4/node-01.do-ams3.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmL5okWopX7NqZWBUKVqW8iUxCEmd5GMHLVPwCgzYzQv3e",
66
- "node-01.gc-us-central1-a.wakuv2.prod": "/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA",
64
+ "node-01.ac-cn-hongkong-c.wakuv2.prod": "/dns4/node-01.ac-cn-hongkong-c.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD",
65
+ "node-01.do-ams3.wakuv2.prod": "/dns4/node-01.do-ams3.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmL5okWopX7NqZWBUKVqW8iUxCEmd5GMHLVPwCgzYzQv3e",
66
+ "node-01.gc-us-central1-a.wakuv2.prod": "/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA",
67
67
  },
68
68
  },
69
69
  "wakuv2.test": {
70
70
  "waku-websocket": {
71
- "node-01.ac-cn-hongkong-c.wakuv2.test": "/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm",
72
- "node-01.do-ams3.wakuv2.test": "/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ",
73
- "node-01.gc-us-central1-a.wakuv2.test": "/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS",
71
+ "node-01.ac-cn-hongkong-c.wakuv2.test": "/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm",
72
+ "node-01.do-ams3.wakuv2.test": "/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ",
73
+ "node-01.gc-us-central1-a.wakuv2.test": "/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS",
74
74
  },
75
75
  },
76
76
  },
@@ -2898,7 +2898,7 @@ var MessagePush$1;
2898
2898
  return decodeMessage(buf, MessagePush.codec());
2899
2899
  };
2900
2900
  })(MessagePush$1 || (MessagePush$1 = {}));
2901
- var FilterRpc$1;
2901
+ var FilterRpc;
2902
2902
  (function (FilterRpc) {
2903
2903
  let _codec;
2904
2904
  FilterRpc.codec = () => {
@@ -2955,7 +2955,7 @@ var FilterRpc$1;
2955
2955
  FilterRpc.decode = (buf) => {
2956
2956
  return decodeMessage(buf, FilterRpc.codec());
2957
2957
  };
2958
- })(FilterRpc$1 || (FilterRpc$1 = {}));
2958
+ })(FilterRpc || (FilterRpc = {}));
2959
2959
  var RateLimitProof$3;
2960
2960
  (function (RateLimitProof) {
2961
2961
  let _codec;
@@ -4805,4 +4805,4 @@ var version_0 = /*#__PURE__*/Object.freeze({
4805
4805
  proto: message
4806
4806
  });
4807
4807
 
4808
- export { DecodedMessage as D, Encoder as E, FilterRpc$1 as F, HistoryRpc$1 as H, MessagePush as M, PushRpc$1 as P, Version as V, FilterSubscribeRequest as a, FilterSubscribeResponse$1 as b, createEncoder as c, PushResponse as d, PagingInfo as e, HistoryResponse as f, createDecoder as g, Decoder as h, message as m, version_0 as v };
4808
+ export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, HistoryRpc$1 as H, MessagePush as M, PushRpc$1 as P, Version as V, FilterSubscribeResponse$1 as a, PushResponse as b, createEncoder as c, PagingInfo as d, HistoryResponse as e, createDecoder as f, Decoder as g, message as m, version_0 as v };
package/dist/index.d.ts CHANGED
@@ -5,10 +5,8 @@ export type { Encoder, Decoder, DecodedMessage, } from "./lib/message/version_0.
5
5
  export * as message from "./lib/message/index.js";
6
6
  export * as waku from "./lib/waku.js";
7
7
  export { WakuNode, WakuOptions } from "./lib/waku.js";
8
- export * as waku_filter_v1 from "./lib/filter/v1/index.js";
9
- export { wakuFilter as wakuFilterV1 } from "./lib/filter/v1/index.js";
10
- export * as waku_filter_v2 from "./lib/filter/v2/index.js";
11
- export { wakuFilterV2 } from "./lib/filter/v2/index.js";
8
+ export * as waku_filter from "./lib/filter/index.js";
9
+ export { wakuFilter } from "./lib/filter/index.js";
12
10
  export * as waku_light_push from "./lib/light_push/index.js";
13
11
  export { wakuLightPush, LightPushCodec } from "./lib/light_push/index.js";
14
12
  export * as waku_store from "./lib/store/index.js";
package/dist/index.js CHANGED
@@ -4,10 +4,8 @@ export { createEncoder, createDecoder } from "./lib/message/version_0.js";
4
4
  export * as message from "./lib/message/index.js";
5
5
  export * as waku from "./lib/waku.js";
6
6
  export { WakuNode } from "./lib/waku.js";
7
- export * as waku_filter_v1 from "./lib/filter/v1/index.js";
8
- export { wakuFilter as wakuFilterV1 } from "./lib/filter/v1/index.js";
9
- export * as waku_filter_v2 from "./lib/filter/v2/index.js";
10
- export { wakuFilterV2 } from "./lib/filter/v2/index.js";
7
+ export * as waku_filter from "./lib/filter/index.js";
8
+ export { wakuFilter } from "./lib/filter/index.js";
11
9
  export * as waku_light_push from "./lib/light_push/index.js";
12
10
  export { wakuLightPush, LightPushCodec } from "./lib/light_push/index.js";
13
11
  export * as waku_store from "./lib/store/index.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAM1E,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAElD,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,cAAc,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,KAAK,cAAc,MAAM,0BA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AAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EACL,gBAAgB,GAEjB,MAAM,6BAA6B,CAAC"}
@@ -1,15 +1,19 @@
1
- import type { Connection, Stream } from "@libp2p/interface-connection";
1
+ import type { Stream } from "@libp2p/interface-connection";
2
+ import type { Libp2p } from "@libp2p/interface-libp2p";
2
3
  import type { PeerId } from "@libp2p/interface-peer-id";
3
4
  import { Peer, PeerStore } from "@libp2p/interface-peer-store";
5
+ import type { IBaseProtocol, Libp2pComponents } from "@waku/interfaces";
4
6
  /**
5
7
  * A class with predefined helpers, to be used as a base to implement Waku
6
8
  * Protocols.
7
9
  */
8
- export declare class BaseProtocol {
10
+ export declare class BaseProtocol implements IBaseProtocol {
9
11
  multicodec: string;
10
- peerStore: PeerStore;
11
- protected getConnections: (peerId?: PeerId) => Connection[];
12
- constructor(multicodec: string, peerStore: PeerStore, getConnections: (peerId?: PeerId) => Connection[]);
12
+ private components;
13
+ readonly addLibp2pEventListener: Libp2p["addEventListener"];
14
+ readonly removeLibp2pEventListener: Libp2p["removeEventListener"];
15
+ constructor(multicodec: string, components: Libp2pComponents);
16
+ get peerStore(): PeerStore;
13
17
  /**
14
18
  * Returns known peers from the address book (`libp2p.peerStore`) that support
15
19
  * the class protocol. Waku may or may not be currently connected to these
@@ -5,12 +5,17 @@ import { getPeersForProtocol, selectConnection, selectPeerForProtocol, } from "@
5
5
  */
6
6
  export class BaseProtocol {
7
7
  multicodec;
8
- peerStore;
9
- getConnections;
10
- constructor(multicodec, peerStore, getConnections) {
8
+ components;
9
+ addLibp2pEventListener;
10
+ removeLibp2pEventListener;
11
+ constructor(multicodec, components) {
11
12
  this.multicodec = multicodec;
12
- this.peerStore = peerStore;
13
- this.getConnections = getConnections;
13
+ this.components = components;
14
+ this.addLibp2pEventListener = components.events.addEventListener.bind(components.events);
15
+ this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
16
+ }
17
+ get peerStore() {
18
+ return this.components.peerStore;
14
19
  }
15
20
  /**
16
21
  * Returns known peers from the address book (`libp2p.peerStore`) that support
@@ -25,7 +30,7 @@ export class BaseProtocol {
25
30
  return peer;
26
31
  }
27
32
  async newStream(peer) {
28
- const connections = this.getConnections(peer.id);
33
+ const connections = this.components.connectionManager.getConnections(peer.id);
29
34
  const connection = selectConnection(connections);
30
35
  if (!connection) {
31
36
  throw new Error("Failed to get a connection to the peer");
@@ -1 +1 @@
1
- {"version":3,"file":"base_protocol.js","sourceRoot":"","sources":["../../src/lib/base_protocol.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B;;;GAGG;AACH,MAAM,OAAO,YAAY;IAEd;IACA;IACG;IAHZ,YACS,UAAkB,EAClB,SAAoB,EACjB,cAAiD;QAFpD,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAW;QACjB,mBAAc,GAAd,cAAc,CAAmC;IAC1D,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,CAAC;IAES,KAAK,CAAC,OAAO,CAAC,MAAe;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,qBAAqB,CAC1C,IAAI,CAAC,SAAS,EACd,CAAC,IAAI,CAAC,UAAU,CAAC,EACjB,MAAM,CACP,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IACS,KAAK,CAAC,SAAS,CAAC,IAAU;QAClC,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjD,MAAM,UAAU,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACjD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAC3D;QAED,OAA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AAM,UAAU,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACjD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAC3D;QAED,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -1,20 +1,22 @@
1
- import type { Libp2p } from "@libp2p/interface-libp2p";
2
1
  import type { PeerId } from "@libp2p/interface-peer-id";
3
- import type { ConnectionManagerOptions, IRelay } from "@waku/interfaces";
2
+ import { EventEmitter } from "@libp2p/interfaces/events";
3
+ import { ConnectionManagerOptions, IPeersByDiscoveryEvents, IRelay, PeersByDiscoveryResult } from "@waku/interfaces";
4
+ import { Libp2p } from "@waku/interfaces";
4
5
  import { KeepAliveOptions } from "./keep_alive_manager.js";
5
6
  export declare const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1;
6
7
  export declare const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
7
8
  export declare const DEFAULT_MAX_PARALLEL_DIALS = 3;
8
- export declare class ConnectionManager {
9
+ export declare class ConnectionManager extends EventEmitter<IPeersByDiscoveryEvents> {
9
10
  private static instances;
10
11
  private keepAliveManager;
11
12
  private options;
12
- private libp2pComponents;
13
+ private libp2p;
13
14
  private dialAttemptsForPeer;
14
15
  private dialErrorsForPeer;
15
16
  private currentActiveDialCount;
16
17
  private pendingPeerDialQueue;
17
18
  static create(peerId: string, libp2p: Libp2p, keepAliveOptions: KeepAliveOptions, relay?: IRelay, options?: ConnectionManagerOptions): ConnectionManager;
19
+ getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
18
20
  private constructor();
19
21
  private dialPeerStorePeers;
20
22
  private run;
@@ -1,3 +1,5 @@
1
+ import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
2
+ import { EPeersByDiscoveryEvents, } from "@waku/interfaces";
1
3
  import { Tags } from "@waku/interfaces";
2
4
  import debug from "debug";
3
5
  import { KeepAliveManager } from "./keep_alive_manager.js";
@@ -5,11 +7,11 @@ const log = debug("waku:connection-manager");
5
7
  export const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1;
6
8
  export const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
7
9
  export const DEFAULT_MAX_PARALLEL_DIALS = 3;
8
- class ConnectionManager {
10
+ class ConnectionManager extends EventEmitter {
9
11
  static instances = new Map();
10
12
  keepAliveManager;
11
13
  options;
12
- libp2pComponents;
14
+ libp2p;
13
15
  dialAttemptsForPeer = new Map();
14
16
  dialErrorsForPeer = new Map();
15
17
  currentActiveDialCount = 0;
@@ -22,8 +24,48 @@ class ConnectionManager {
22
24
  }
23
25
  return instance;
24
26
  }
25
- constructor(libp2pComponents, keepAliveOptions, relay, options) {
26
- this.libp2pComponents = libp2pComponents;
27
+ async getPeersByDiscovery() {
28
+ const peersDiscovered = await this.libp2p.peerStore.all();
29
+ const peersConnected = this.libp2p
30
+ .getConnections()
31
+ .map((conn) => conn.remotePeer);
32
+ const peersDiscoveredByBootstrap = [];
33
+ const peersDiscoveredByPeerExchange = [];
34
+ const peersConnectedByBootstrap = [];
35
+ const peersConnectedByPeerExchange = [];
36
+ for (const peer of peersDiscovered) {
37
+ const tags = await this.getTagNamesForPeer(peer.id);
38
+ if (tags.includes(Tags.BOOTSTRAP)) {
39
+ peersDiscoveredByBootstrap.push(peer);
40
+ }
41
+ else if (tags.includes(Tags.PEER_EXCHANGE)) {
42
+ peersDiscoveredByPeerExchange.push(peer);
43
+ }
44
+ }
45
+ for (const peerId of peersConnected) {
46
+ const peer = await this.libp2p.peerStore.get(peerId);
47
+ const tags = await this.getTagNamesForPeer(peerId);
48
+ if (tags.includes(Tags.BOOTSTRAP)) {
49
+ peersConnectedByBootstrap.push(peer);
50
+ }
51
+ else if (tags.includes(Tags.PEER_EXCHANGE)) {
52
+ peersConnectedByPeerExchange.push(peer);
53
+ }
54
+ }
55
+ return {
56
+ DISCOVERED: {
57
+ [Tags.BOOTSTRAP]: peersDiscoveredByBootstrap,
58
+ [Tags.PEER_EXCHANGE]: peersDiscoveredByPeerExchange,
59
+ },
60
+ CONNECTED: {
61
+ [Tags.BOOTSTRAP]: peersConnectedByBootstrap,
62
+ [Tags.PEER_EXCHANGE]: peersConnectedByPeerExchange,
63
+ },
64
+ };
65
+ }
66
+ constructor(libp2p, keepAliveOptions, relay, options) {
67
+ super();
68
+ this.libp2p = libp2p;
27
69
  this.options = {
28
70
  maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER,
29
71
  maxBootstrapPeersAllowed: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED,
@@ -37,15 +79,13 @@ class ConnectionManager {
37
79
  // libp2p emits `peer:discovery` events during its initialization
38
80
  // which means that before the ConnectionManager is initialized, some peers may have been discovered
39
81
  // we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
40
- this.dialPeerStorePeers();
82
+ this.dialPeerStorePeers().catch((error) => log(`Unexpected error while dialing peer store peers`, error));
41
83
  }
42
84
  async dialPeerStorePeers() {
43
- const peerInfos = await this.libp2pComponents.peerStore.all();
85
+ const peerInfos = await this.libp2p.peerStore.all();
44
86
  const dialPromises = [];
45
87
  for (const peerInfo of peerInfos) {
46
- if (this.libp2pComponents
47
- .getConnections()
48
- .find((c) => c.remotePeer === peerInfo.id))
88
+ if (this.libp2p.getConnections().find((c) => c.remotePeer === peerInfo.id))
49
89
  continue;
50
90
  dialPromises.push(this.attemptDial(peerInfo.id));
51
91
  }
@@ -64,9 +104,9 @@ class ConnectionManager {
64
104
  }
65
105
  stop() {
66
106
  this.keepAliveManager.stopAll();
67
- this.libp2pComponents.removeEventListener("peer:connect", this.onEventHandlers["peer:connect"]);
68
- this.libp2pComponents.removeEventListener("peer:disconnect", this.onEventHandlers["peer:disconnect"]);
69
- this.libp2pComponents.removeEventListener("peer:discovery", this.onEventHandlers["peer:discovery"]);
107
+ this.libp2p.removeEventListener("peer:connect", this.onEventHandlers["peer:connect"]);
108
+ this.libp2p.removeEventListener("peer:disconnect", this.onEventHandlers["peer:disconnect"]);
109
+ this.libp2p.removeEventListener("peer:discovery", this.onEventHandlers["peer:discovery"]);
70
110
  }
71
111
  async dialPeer(peerId) {
72
112
  this.currentActiveDialCount += 1;
@@ -74,11 +114,11 @@ class ConnectionManager {
74
114
  while (dialAttempt <= this.options.maxDialAttemptsForPeer) {
75
115
  try {
76
116
  log(`Dialing peer ${peerId.toString()}`);
77
- await this.libp2pComponents.dial(peerId);
117
+ await this.libp2p.dial(peerId);
78
118
  const tags = await this.getTagNamesForPeer(peerId);
79
119
  // add tag to connection describing discovery mechanism
80
120
  // don't add duplicate tags
81
- this.libp2pComponents
121
+ this.libp2p
82
122
  .getConnections(peerId)
83
123
  .forEach((conn) => (conn.tags = Array.from(new Set([...conn.tags, ...tags]))));
84
124
  this.dialAttemptsForPeer.delete(peerId.toString());
@@ -99,7 +139,7 @@ class ConnectionManager {
99
139
  log(`Deleting undialable peer ${peerId.toString()} from peer store. Error: ${JSON.stringify(this.dialErrorsForPeer.get(peerId.toString()).errors[0])}
100
140
  }`);
101
141
  this.dialErrorsForPeer.delete(peerId.toString());
102
- return await this.libp2pComponents.peerStore.delete(peerId);
142
+ return await this.libp2p.peerStore.delete(peerId);
103
143
  }
104
144
  catch (error) {
105
145
  throw `Error deleting undialable peer ${peerId.toString()} from peer store - ${error}`;
@@ -111,14 +151,15 @@ class ConnectionManager {
111
151
  }
112
152
  async dropConnection(peerId) {
113
153
  try {
114
- await this.libp2pComponents.hangUp(peerId);
154
+ this.keepAliveManager.stop(peerId);
155
+ await this.libp2p.hangUp(peerId);
115
156
  log(`Dropped connection with peer ${peerId.toString()}`);
116
157
  }
117
158
  catch (error) {
118
159
  log(`Error dropping connection with peer ${peerId.toString()} - ${error}`);
119
160
  }
120
161
  }
121
- async processDialQueue() {
162
+ processDialQueue() {
122
163
  if (this.pendingPeerDialQueue.length > 0 &&
123
164
  this.currentActiveDialCount < this.options.maxParallelDials) {
124
165
  const peerId = this.pendingPeerDialQueue.shift();
@@ -130,10 +171,10 @@ class ConnectionManager {
130
171
  }
131
172
  }
132
173
  startPeerDiscoveryListener() {
133
- this.libp2pComponents.peerStore.addEventListener("peer", this.onEventHandlers["peer:discovery"]);
174
+ this.libp2p.addEventListener("peer:discovery", this.onEventHandlers["peer:discovery"]);
134
175
  }
135
176
  startPeerConnectionListener() {
136
- this.libp2pComponents.addEventListener("peer:connect", this.onEventHandlers["peer:connect"]);
177
+ this.libp2p.addEventListener("peer:connect", this.onEventHandlers["peer:connect"]);
137
178
  }
138
179
  startPeerDisconnectionListener() {
139
180
  // TODO: ensure that these following issues are updated and confirmed
@@ -148,7 +189,7 @@ class ConnectionManager {
148
189
  * >this event will **only** be triggered when the last connection is closed.
149
190
  * @see https://github.com/libp2p/js-libp2p/blob/bad9e8c0ff58d60a78314077720c82ae331cc55b/doc/API.md?plain=1#L2100
150
191
  */
151
- this.libp2pComponents.addEventListener("peer:disconnect", this.onEventHandlers["peer:disconnect"]);
192
+ this.libp2p.addEventListener("peer:disconnect", this.onEventHandlers["peer:disconnect"]);
152
193
  }
153
194
  async attemptDial(peerId) {
154
195
  if (this.currentActiveDialCount >= this.options.maxParallelDials) {
@@ -162,27 +203,57 @@ class ConnectionManager {
162
203
  });
163
204
  }
164
205
  onEventHandlers = {
165
- "peer:discovery": async (evt) => {
166
- const { id: peerId } = evt.detail;
167
- this.attemptDial(peerId).catch((err) => log(`Error dialing peer ${peerId.toString()} : ${err}`));
206
+ "peer:discovery": (evt) => {
207
+ void (async () => {
208
+ const { id: peerId } = evt.detail;
209
+ const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(Tags.BOOTSTRAP);
210
+ if (isBootstrap) {
211
+ this.dispatchEvent(new CustomEvent(EPeersByDiscoveryEvents.PEER_DISCOVERY_BOOTSTRAP, {
212
+ detail: peerId,
213
+ }));
214
+ }
215
+ else {
216
+ this.dispatchEvent(new CustomEvent(EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE, {
217
+ detail: peerId,
218
+ }));
219
+ }
220
+ try {
221
+ await this.attemptDial(peerId);
222
+ }
223
+ catch (error) {
224
+ log(`Error dialing peer ${peerId.toString()} : ${error}`);
225
+ }
226
+ })();
168
227
  },
169
- "peer:connect": async (evt) => {
170
- const { remotePeer: peerId } = evt.detail;
171
- this.keepAliveManager.start(peerId, this.libp2pComponents.ping.bind(this));
172
- const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(Tags.BOOTSTRAP);
173
- if (isBootstrap) {
174
- const bootstrapConnections = this.libp2pComponents
175
- .getConnections()
176
- .filter((conn) => conn.tags.includes(Tags.BOOTSTRAP));
177
- // If we have too many bootstrap connections, drop one
178
- if (bootstrapConnections.length > this.options.maxBootstrapPeersAllowed) {
179
- await this.dropConnection(peerId);
228
+ "peer:connect": (evt) => {
229
+ void (async () => {
230
+ const peerId = evt.detail;
231
+ this.keepAliveManager.start(peerId, this.libp2p.services.ping);
232
+ const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(Tags.BOOTSTRAP);
233
+ if (isBootstrap) {
234
+ const bootstrapConnections = this.libp2p
235
+ .getConnections()
236
+ .filter((conn) => conn.tags.includes(Tags.BOOTSTRAP));
237
+ // If we have too many bootstrap connections, drop one
238
+ if (bootstrapConnections.length > this.options.maxBootstrapPeersAllowed) {
239
+ await this.dropConnection(peerId);
240
+ }
241
+ else {
242
+ this.dispatchEvent(new CustomEvent(EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP, {
243
+ detail: peerId,
244
+ }));
245
+ }
180
246
  }
181
- }
247
+ else {
248
+ this.dispatchEvent(new CustomEvent(EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE, {
249
+ detail: peerId,
250
+ }));
251
+ }
252
+ })();
182
253
  },
183
254
  "peer:disconnect": () => {
184
255
  return (evt) => {
185
- this.keepAliveManager.stop(evt.detail.remotePeer);
256
+ this.keepAliveManager.stop(evt.detail);
186
257
  };
187
258
  },
188
259
  };
@@ -192,15 +263,16 @@ class ConnectionManager {
192
263
  * 2. If the peer is not a bootstrap peer
193
264
  */
194
265
  async shouldDialPeer(peerId) {
195
- const isConnected = this.libp2pComponents.getConnections(peerId).length > 0;
266
+ const isConnected = this.libp2p.getConnections(peerId).length > 0;
196
267
  if (isConnected)
197
268
  return false;
198
- const isBootstrap = (await this.getTagNamesForPeer(peerId)).some((tagName) => tagName === Tags.BOOTSTRAP);
269
+ const tagNames = await this.getTagNamesForPeer(peerId);
270
+ const isBootstrap = tagNames.some((tagName) => tagName === Tags.BOOTSTRAP);
199
271
  if (isBootstrap) {
200
- const currentBootstrapConnections = this.libp2pComponents
272
+ const currentBootstrapConnections = this.libp2p
201
273
  .getConnections()
202
274
  .filter((conn) => {
203
- conn.tags.find((name) => name === Tags.BOOTSTRAP);
275
+ return conn.tags.find((name) => name === Tags.BOOTSTRAP);
204
276
  }).length;
205
277
  if (currentBootstrapConnections < this.options.maxBootstrapPeersAllowed)
206
278
  return true;
@@ -214,8 +286,14 @@ class ConnectionManager {
214
286
  * Fetches the tag names for a given peer
215
287
  */
216
288
  async getTagNamesForPeer(peerId) {
217
- const tags = (await this.libp2pComponents.peerStore.getTags(peerId)).map((tag) => tag.name);
218
- return tags;
289
+ try {
290
+ const peer = await this.libp2p.peerStore.get(peerId);
291
+ return Array.from(peer.tags.keys());
292
+ }
293
+ catch (error) {
294
+ log(`Failed to get peer ${peerId}, error: ${error}`);
295
+ return [];
296
+ }
219
297
  }
220
298
  }
221
299
  export { ConnectionManager };
@@ -1 +1 @@
1
- {"version":3,"file":"connection_manager.js","sourceRoot":"","sources":["../../src/lib/connection_manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAoB,MAAM,yBAAyB,CAAC;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CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ import type { IFilter, Libp2p, ProtocolCreateOptions } from "@waku/interfaces";
2
+ export declare function wakuFilter(init?: Partial<ProtocolCreateOptions>): (libp2p: Libp2p) => IFilter;
@@ -3,11 +3,11 @@ import debug from "debug";
3
3
  import all from "it-all";
4
4
  import * as lp from "it-length-prefixed";
5
5
  import { pipe } from "it-pipe";
6
- import { BaseProtocol } from "../../base_protocol.js";
7
- import { DefaultPubSubTopic } from "../../constants.js";
6
+ import { BaseProtocol } from "../base_protocol.js";
7
+ import { DefaultPubSubTopic } from "../constants.js";
8
8
  import { FilterPushRpc, FilterSubscribeResponse, FilterSubscribeRpc, } from "./filter_rpc.js";
9
9
  const log = debug("waku:filter:v2");
10
- const FilterV2Codecs = {
10
+ const FilterCodecs = {
11
11
  SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
12
12
  PUSH: "/vac/waku/filter-push/2.0.0-beta1",
13
13
  };
@@ -114,8 +114,7 @@ class Subscription {
114
114
  await pushMessage(subscriptionCallback, this.pubSubTopic, message);
115
115
  }
116
116
  }
117
- class FilterV2 extends BaseProtocol {
118
- libp2p;
117
+ class Filter extends BaseProtocol {
119
118
  options;
120
119
  activeSubscriptions = new Map();
121
120
  getActiveSubscription(pubSubTopic, peerIdStr) {
@@ -126,12 +125,9 @@ class FilterV2 extends BaseProtocol {
126
125
  return subscription;
127
126
  }
128
127
  constructor(libp2p, options) {
129
- super(FilterV2Codecs.SUBSCRIBE, libp2p.peerStore, libp2p.getConnections.bind(libp2p));
130
- this.libp2p = libp2p;
131
- this.libp2p
132
- .handle(FilterV2Codecs.PUSH, this.onRequest.bind(this))
133
- .catch((e) => {
134
- log("Failed to register ", FilterV2Codecs.PUSH, e);
128
+ super(FilterCodecs.SUBSCRIBE, libp2p.components);
129
+ libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
130
+ log("Failed to register ", FilterCodecs.PUSH, e);
135
131
  });
136
132
  this.activeSubscriptions = new Map();
137
133
  this.options = options ?? {};
@@ -163,7 +159,7 @@ class FilterV2 extends BaseProtocol {
163
159
  */
164
160
  async subscribe(decoders, callback, opts) {
165
161
  const subscription = await this.createSubscription(undefined, opts?.peerId);
166
- subscription.subscribe(decoders, callback);
162
+ await subscription.subscribe(decoders, callback);
167
163
  const contentTopics = Array.from(groupByContentTopic(Array.isArray(decoders) ? decoders : [decoders]).keys());
168
164
  return async () => {
169
165
  await subscription.unsubscribe(contentTopics);
@@ -203,8 +199,8 @@ class FilterV2 extends BaseProtocol {
203
199
  }
204
200
  }
205
201
  }
206
- export function wakuFilterV2(init = {}) {
207
- return (libp2p) => new FilterV2(libp2p, init);
202
+ export function wakuFilter(init = {}) {
203
+ return (libp2p) => new Filter(libp2p, init);
208
204
  }
209
205
  async function pushMessage(subscriptionCallback, pubSubTopic, message) {
210
206
  const { decoders, callback } = subscriptionCallback;
@@ -217,19 +213,18 @@ async function pushMessage(subscriptionCallback, pubSubTopic, message) {
217
213
  // We don't want to wait for decoding failure, just attempt to decode
218
214
  // all messages and do the call back on the one that works
219
215
  // noinspection ES6MissingAwait
220
- decoders.forEach(async (dec) => {
216
+ for (const dec of decoders) {
221
217
  if (didDecodeMsg)
222
- return;
218
+ break;
223
219
  const decoded = await dec.fromProtoObj(pubSubTopic, message);
224
- // const decoded = await dec.fromProtoObj(pubSubTopic, message);
225
220
  if (!decoded) {
226
221
  log("Not able to decode message");
227
- return;
222
+ continue;
228
223
  }
229
224
  // This is just to prevent more decoding attempt
230
225
  // TODO: Could be better if we were to abort promises
231
226
  didDecodeMsg = Boolean(decoded);
232
227
  await callback(decoded);
233
- });
228
+ }
234
229
  }
235
230
  //# sourceMappingURL=index.js.map