@waku/core 0.0.31-ce62600.0 → 0.0.31

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 (76) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/bundle/{base_protocol-C6HnrRx8.js → base_protocol-C47QkJ2o.js} +22 -25
  3. package/bundle/{index-DnW8ifxc.js → index-tdQNdKHx.js} +62 -57
  4. package/bundle/index.js +381 -315
  5. package/bundle/lib/base_protocol.js +2 -2
  6. package/bundle/lib/message/version_0.js +2 -2
  7. package/bundle/{version_0-DQ9xsSLk.js → version_0-BrbNEwD-.js} +154 -308
  8. package/dist/.tsbuildinfo +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +2 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/lib/base_protocol.d.ts +3 -4
  13. package/dist/lib/base_protocol.js +4 -8
  14. package/dist/lib/base_protocol.js.map +1 -1
  15. package/dist/lib/connection_manager.d.ts +9 -6
  16. package/dist/lib/connection_manager.js +70 -45
  17. package/dist/lib/connection_manager.js.map +1 -1
  18. package/dist/lib/filter/filter_rpc.js.map +1 -1
  19. package/dist/lib/filter/index.d.ts +4 -3
  20. package/dist/lib/filter/index.js +37 -35
  21. package/dist/lib/filter/index.js.map +1 -1
  22. package/dist/lib/health_manager.d.ts +14 -0
  23. package/dist/lib/health_manager.js +70 -0
  24. package/dist/lib/health_manager.js.map +1 -0
  25. package/dist/lib/keep_alive_manager.d.ts +13 -7
  26. package/dist/lib/keep_alive_manager.js +9 -9
  27. package/dist/lib/keep_alive_manager.js.map +1 -1
  28. package/dist/lib/light_push/index.d.ts +3 -2
  29. package/dist/lib/light_push/index.js +17 -3
  30. package/dist/lib/light_push/index.js.map +1 -1
  31. package/dist/lib/light_push/push_rpc.js.map +1 -1
  32. package/dist/lib/light_push/utils.d.ts +3 -0
  33. package/dist/lib/light_push/utils.js +26 -0
  34. package/dist/lib/light_push/utils.js.map +1 -0
  35. package/dist/lib/message/version_0.js.map +1 -1
  36. package/dist/lib/metadata/index.d.ts +2 -2
  37. package/dist/lib/metadata/index.js +26 -26
  38. package/dist/lib/metadata/index.js.map +1 -1
  39. package/dist/lib/store/index.d.ts +5 -44
  40. package/dist/lib/store/index.js +39 -45
  41. package/dist/lib/store/index.js.map +1 -1
  42. package/dist/lib/store/rpc.d.ts +22 -0
  43. package/dist/lib/store/rpc.js +74 -0
  44. package/dist/lib/store/rpc.js.map +1 -0
  45. package/dist/lib/stream_manager/index.d.ts +1 -0
  46. package/dist/lib/stream_manager/index.js +2 -0
  47. package/dist/lib/stream_manager/index.js.map +1 -0
  48. package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
  49. package/dist/lib/stream_manager/stream_manager.js.map +1 -0
  50. package/dist/lib/stream_manager/utils.d.ts +2 -0
  51. package/dist/lib/stream_manager/utils.js +19 -0
  52. package/dist/lib/stream_manager/utils.js.map +1 -0
  53. package/package.json +130 -1
  54. package/src/index.ts +3 -3
  55. package/src/lib/base_protocol.ts +7 -10
  56. package/src/lib/connection_manager.ts +100 -57
  57. package/src/lib/filter/filter_rpc.ts +21 -19
  58. package/src/lib/filter/index.ts +54 -56
  59. package/src/lib/health_manager.ts +90 -0
  60. package/src/lib/keep_alive_manager.ts +27 -18
  61. package/src/lib/light_push/index.ts +21 -11
  62. package/src/lib/light_push/push_rpc.ts +5 -5
  63. package/src/lib/light_push/utils.ts +31 -0
  64. package/src/lib/message/version_0.ts +17 -15
  65. package/src/lib/metadata/index.ts +43 -44
  66. package/src/lib/store/index.ts +54 -94
  67. package/src/lib/store/rpc.ts +92 -0
  68. package/src/lib/stream_manager/index.ts +1 -0
  69. package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
  70. package/src/lib/stream_manager/utils.ts +22 -0
  71. package/dist/lib/store/history_rpc.d.ts +0 -27
  72. package/dist/lib/store/history_rpc.js +0 -72
  73. package/dist/lib/store/history_rpc.js.map +0 -1
  74. package/dist/lib/stream_manager.js.map +0 -1
  75. package/src/lib/store/history_rpc.ts +0 -93
  76. /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -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,WAAW,GAAG,CAAC,CAAC;AAEtB,MAAM,OAAO,aAAa;IAKf;IACA;IACA;IANQ,UAAU,CAAsC;IAChD,GAAG,CAAS;IAE7B,YACS,UAAkB,EAClB,cAAwC,EACxC,gBAA4C;QAF5C,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAA0B;QACxC,qBAAgB,GAAhB,gBAAgB,CAA4B;QAEnD,IAAI,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACxE,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,IAAU;QAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAErD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,C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AAI,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAClC,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,gDAAgD,SAAS,EAAE,CAC5D,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEM,aAAa,CAAC,MAAc;QAClC,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAChD,OAAO,WAAW,CAAC,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,130 @@
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
+ {
2
+ "name": "@waku/core",
3
+ "version": "0.0.31",
4
+ "description": "TypeScript implementation of the Waku v2 protocol",
5
+ "types": "./dist/index.d.ts",
6
+ "module": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./lib/message/version_0": {
13
+ "types": "./dist/lib/message/version_0.d.ts",
14
+ "import": "./dist/lib/message/version_0.js"
15
+ },
16
+ "./lib/base_protocol": {
17
+ "types": "./dist/lib/base_protocol.d.ts",
18
+ "import": "./dist/lib/base_protocol.js"
19
+ }
20
+ },
21
+ "typesVersions": {
22
+ "*": {
23
+ "lib/*": [
24
+ "dist/lib/*"
25
+ ],
26
+ "constants/*": [
27
+ "dist/constants/*"
28
+ ]
29
+ }
30
+ },
31
+ "type": "module",
32
+ "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/waku-org/js-waku.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/waku-org/js-waku/issues"
39
+ },
40
+ "license": "MIT OR Apache-2.0",
41
+ "keywords": [
42
+ "waku",
43
+ "decentralised",
44
+ "communication",
45
+ "web3",
46
+ "ethereum",
47
+ "dapps"
48
+ ],
49
+ "scripts": {
50
+ "build": "run-s build:**",
51
+ "build:esm": "tsc",
52
+ "build:bundle": "rollup --config rollup.config.js",
53
+ "fix": "run-s fix:*",
54
+ "fix:lint": "eslint src *.js --fix",
55
+ "check": "run-s check:*",
56
+ "check:tsc": "tsc -p tsconfig.dev.json",
57
+ "check:lint": "eslint src *.js",
58
+ "check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
59
+ "test": "NODE_ENV=test run-s test:*",
60
+ "test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha",
61
+ "test:browser": "NODE_ENV=test karma start karma.conf.cjs",
62
+ "watch:build": "tsc -p tsconfig.json -w",
63
+ "watch:test": "mocha --watch",
64
+ "prepublish": "npm run build",
65
+ "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
66
+ },
67
+ "engines": {
68
+ "node": ">=20"
69
+ },
70
+ "dependencies": {
71
+ "@libp2p/ping": "^1.1.2",
72
+ "@waku/enr": "^0.0.25",
73
+ "@waku/interfaces": "0.0.26",
74
+ "@waku/proto": "0.0.8",
75
+ "@waku/utils": "0.0.19",
76
+ "debug": "^4.3.4",
77
+ "it-all": "^3.0.4",
78
+ "it-length-prefixed": "^9.0.4",
79
+ "it-pipe": "^3.0.1",
80
+ "p-event": "^6.0.1",
81
+ "uint8arraylist": "^2.4.3",
82
+ "uuid": "^9.0.0"
83
+ },
84
+ "devDependencies": {
85
+ "@multiformats/multiaddr": "^12.0.0",
86
+ "@rollup/plugin-commonjs": "^25.0.7",
87
+ "@rollup/plugin-json": "^6.0.0",
88
+ "@rollup/plugin-node-resolve": "^15.2.3",
89
+ "@types/chai": "^4.3.11",
90
+ "@types/debug": "^4.1.12",
91
+ "@types/mocha": "^10.0.6",
92
+ "@types/uuid": "^9.0.8",
93
+ "@waku/build-utils": "*",
94
+ "chai": "^4.3.10",
95
+ "cspell": "^8.6.1",
96
+ "fast-check": "^3.19.0",
97
+ "ignore-loader": "^0.1.2",
98
+ "isomorphic-fetch": "^3.0.0",
99
+ "mocha": "^10.3.0",
100
+ "npm-run-all": "^4.1.5",
101
+ "process": "^0.11.10",
102
+ "rollup": "^4.12.0"
103
+ },
104
+ "peerDependencies": {
105
+ "@multiformats/multiaddr": "^12.0.0",
106
+ "libp2p": "^1.8.1",
107
+ "@waku/enr": "^0.0.24",
108
+ "@waku/interfaces": "0.0.25",
109
+ "@waku/proto": "0.0.7",
110
+ "@waku/utils": "0.0.18"
111
+ },
112
+ "peerDependenciesMeta": {
113
+ "@multiformats/multiaddr": {
114
+ "optional": true
115
+ },
116
+ "@waku/interfaces": {
117
+ "optional": true
118
+ }
119
+ },
120
+ "files": [
121
+ "dist",
122
+ "bundle",
123
+ "src/**/*.ts",
124
+ "!**/*.spec.*",
125
+ "!**/*.json",
126
+ "CHANGELOG.md",
127
+ "LICENSE",
128
+ "README.md"
129
+ ]
130
+ }
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
@@ -38,32 +38,15 @@ export class ConnectionManager
38
38
 
39
39
  private currentActiveParallelDialCount = 0;
40
40
  private pendingPeerDialQueue: Array<PeerId> = [];
41
- private online: boolean = false;
42
41
 
43
- public isConnected(): boolean {
44
- return this.online;
45
- }
42
+ private isP2PNetworkConnected: boolean = false;
46
43
 
47
- private toggleOnline(): void {
48
- if (!this.online) {
49
- this.online = true;
50
- this.dispatchEvent(
51
- new CustomEvent<boolean>(EConnectionStateEvents.CONNECTION_STATUS, {
52
- detail: this.online
53
- })
54
- );
44
+ public isConnected(): boolean {
45
+ if (globalThis?.navigator && !globalThis?.navigator?.onLine) {
46
+ return false;
55
47
  }
56
- }
57
48
 
58
- private toggleOffline(): void {
59
- if (this.online && this.libp2p.getConnections().length == 0) {
60
- this.online = false;
61
- this.dispatchEvent(
62
- new CustomEvent<boolean>(EConnectionStateEvents.CONNECTION_STATUS, {
63
- detail: this.online
64
- })
65
- );
66
- }
49
+ return this.isP2PNetworkConnected;
67
50
  }
68
51
 
69
52
  public static create(
@@ -89,7 +72,7 @@ export class ConnectionManager
89
72
  return instance;
90
73
  }
91
74
 
92
- stop(): void {
75
+ public stop(): void {
93
76
  this.keepAliveManager.stopAll();
94
77
  this.libp2p.removeEventListener(
95
78
  "peer:connect",
@@ -103,9 +86,10 @@ export class ConnectionManager
103
86
  "peer:discovery",
104
87
  this.onEventHandlers["peer:discovery"]
105
88
  );
89
+ this.stopNetworkStatusListener();
106
90
  }
107
91
 
108
- async dropConnection(peerId: PeerId): Promise<void> {
92
+ public async dropConnection(peerId: PeerId): Promise<void> {
109
93
  try {
110
94
  this.keepAliveManager.stop(peerId);
111
95
  await this.libp2p.hangUp(peerId);
@@ -173,7 +157,7 @@ export class ConnectionManager
173
157
  private constructor(
174
158
  libp2p: Libp2p,
175
159
  keepAliveOptions: KeepAliveOptions,
176
- private configuredPubsubTopics: PubsubTopic[],
160
+ public readonly configuredPubsubTopics: PubsubTopic[],
177
161
  relay?: IRelay,
178
162
  options?: Partial<ConnectionManagerOptions>
179
163
  ) {
@@ -187,9 +171,13 @@ export class ConnectionManager
187
171
  ...options
188
172
  };
189
173
 
190
- this.keepAliveManager = new KeepAliveManager(keepAliveOptions, relay);
174
+ this.keepAliveManager = new KeepAliveManager({
175
+ relay,
176
+ libp2p,
177
+ options: keepAliveOptions
178
+ });
191
179
 
192
- this.run()
180
+ this.startEventListeners()
193
181
  .then(() => log.info(`Connection Manager is now running`))
194
182
  .catch((error) =>
195
183
  log.error(`Unexpected error while running service`, error)
@@ -221,11 +209,12 @@ export class ConnectionManager
221
209
  }
222
210
  }
223
211
 
224
- private async run(): Promise<void> {
225
- // start event listeners
212
+ private async startEventListeners(): Promise<void> {
226
213
  this.startPeerDiscoveryListener();
227
214
  this.startPeerConnectionListener();
228
215
  this.startPeerDisconnectionListener();
216
+
217
+ this.startNetworkStatusListener();
229
218
  }
230
219
 
231
220
  private async dialPeer(peerId: PeerId): Promise<void> {
@@ -250,6 +239,7 @@ export class ConnectionManager
250
239
  this.dialAttemptsForPeer.set(peerId.toString(), -1);
251
240
 
252
241
  // Dialing succeeded, break the loop
242
+ this.keepAliveManager.start(peerId);
253
243
  break;
254
244
  } catch (error) {
255
245
  if (error instanceof AggregateError) {
@@ -356,7 +346,7 @@ export class ConnectionManager
356
346
  );
357
347
  }
358
348
 
359
- private async attemptDial(peerId: PeerId): Promise<void> {
349
+ public async attemptDial(peerId: PeerId): Promise<void> {
360
350
  if (!(await this.shouldDialPeer(peerId))) return;
361
351
 
362
352
  if (this.currentActiveParallelDialCount >= this.options.maxParallelDials) {
@@ -364,9 +354,7 @@ export class ConnectionManager
364
354
  return;
365
355
  }
366
356
 
367
- this.dialPeer(peerId).catch((err) => {
368
- log.error(`Error dialing peer ${peerId.toString()} : ${err}`);
369
- });
357
+ await this.dialPeer(peerId);
370
358
  }
371
359
 
372
360
  private onEventHandlers = {
@@ -389,11 +377,7 @@ export class ConnectionManager
389
377
 
390
378
  const peerId = evt.detail;
391
379
 
392
- this.keepAliveManager.start(
393
- peerId,
394
- this.libp2p.services.ping,
395
- this.libp2p.peerStore
396
- );
380
+ this.keepAliveManager.start(peerId);
397
381
 
398
382
  const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
399
383
  Tags.BOOTSTRAP
@@ -429,14 +413,18 @@ export class ConnectionManager
429
413
  )
430
414
  );
431
415
  }
432
- this.toggleOnline();
416
+
417
+ this.setP2PNetworkConnected();
433
418
  })();
434
419
  },
435
420
  "peer:disconnect": (evt: CustomEvent<PeerId>): void => {
436
421
  void (async () => {
437
422
  this.keepAliveManager.stop(evt.detail);
438
- this.toggleOffline();
423
+ this.setP2PNetworkDisconnected();
439
424
  })();
425
+ },
426
+ "browser:network": (): void => {
427
+ this.dispatchWakuConnectionEvent();
440
428
  }
441
429
  };
442
430
 
@@ -449,38 +437,40 @@ export class ConnectionManager
449
437
  * @returns true if the peer should be dialed, false otherwise
450
438
  */
451
439
  private async shouldDialPeer(peerId: PeerId): Promise<boolean> {
452
- // if we're already connected to the peer, don't dial
453
440
  const isConnected = this.libp2p.getConnections(peerId).length > 0;
454
441
  if (isConnected) {
455
442
  log.warn(`Already connected to peer ${peerId.toString()}. Not dialing.`);
456
443
  return false;
457
444
  }
458
445
 
459
- // if the peer is not part of any of the configured pubsub topics, don't dial
460
- if (!(await this.isPeerTopicConfigured(peerId))) {
446
+ const isSameShard = await this.isPeerTopicConfigured(peerId);
447
+ if (!isSameShard) {
461
448
  const shardInfo = await this.getPeerShardInfo(
462
449
  peerId,
463
450
  this.libp2p.peerStore
464
451
  );
452
+
465
453
  log.warn(
466
454
  `Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
467
455
  this.configuredPubsubTopics
468
456
  }).
469
457
  Not dialing.`
470
458
  );
459
+
471
460
  return false;
472
461
  }
473
462
 
474
- // if the peer is not dialable based on bootstrap status, don't dial
475
- if (!(await this.isPeerDialableBasedOnBootstrapStatus(peerId))) {
463
+ const isPreferredBasedOnBootstrap =
464
+ await this.isPeerDialableBasedOnBootstrapStatus(peerId);
465
+ if (!isPreferredBasedOnBootstrap) {
476
466
  log.warn(
477
467
  `Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`
478
468
  );
479
469
  return false;
480
470
  }
481
471
 
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())) {
472
+ const hasBeenDialed = this.dialAttemptsForPeer.has(peerId.toString());
473
+ if (hasBeenDialed) {
484
474
  log.warn(
485
475
  `Peer ${peerId.toString()} has already been attempted dial before, or already has a dial attempt in progress, skipping dial`
486
476
  );
@@ -502,19 +492,17 @@ export class ConnectionManager
502
492
 
503
493
  const isBootstrap = tagNames.some((tagName) => tagName === Tags.BOOTSTRAP);
504
494
 
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 {
495
+ if (!isBootstrap) {
514
496
  return true;
515
497
  }
516
498
 
517
- return false;
499
+ const currentBootstrapConnections = this.libp2p
500
+ .getConnections()
501
+ .filter((conn) => {
502
+ return conn.tags.find((name) => name === Tags.BOOTSTRAP);
503
+ }).length;
504
+
505
+ return currentBootstrapConnections < this.options.maxBootstrapPeersAllowed;
518
506
  }
519
507
 
520
508
  private async dispatchDiscoveryEvent(peerId: PeerId): Promise<void> {
@@ -573,4 +561,59 @@ export class ConnectionManager
573
561
  if (!shardInfoBytes) return undefined;
574
562
  return decodeRelayShard(shardInfoBytes);
575
563
  }
564
+
565
+ private startNetworkStatusListener(): void {
566
+ try {
567
+ globalThis.addEventListener(
568
+ "online",
569
+ this.onEventHandlers["browser:network"]
570
+ );
571
+ globalThis.addEventListener(
572
+ "offline",
573
+ this.onEventHandlers["browser:network"]
574
+ );
575
+ } catch (err) {
576
+ log.error(`Failed to start network listener: ${err}`);
577
+ }
578
+ }
579
+
580
+ private stopNetworkStatusListener(): void {
581
+ try {
582
+ globalThis.removeEventListener(
583
+ "online",
584
+ this.onEventHandlers["browser:network"]
585
+ );
586
+ globalThis.removeEventListener(
587
+ "offline",
588
+ this.onEventHandlers["browser:network"]
589
+ );
590
+ } catch (err) {
591
+ log.error(`Failed to stop network listener: ${err}`);
592
+ }
593
+ }
594
+
595
+ private setP2PNetworkConnected(): void {
596
+ if (!this.isP2PNetworkConnected) {
597
+ this.isP2PNetworkConnected = true;
598
+ this.dispatchWakuConnectionEvent();
599
+ }
600
+ }
601
+
602
+ private setP2PNetworkDisconnected(): void {
603
+ if (
604
+ this.isP2PNetworkConnected &&
605
+ this.libp2p.getConnections().length === 0
606
+ ) {
607
+ this.isP2PNetworkConnected = false;
608
+ this.dispatchWakuConnectionEvent();
609
+ }
610
+ }
611
+
612
+ private dispatchWakuConnectionEvent(): void {
613
+ this.dispatchEvent(
614
+ new CustomEvent<boolean>(EConnectionStateEvents.CONNECTION_STATUS, {
615
+ detail: this.isConnected()
616
+ })
617
+ );
618
+ }
576
619
  }
@@ -8,16 +8,16 @@ import { v4 as uuid } from "uuid";
8
8
  export class FilterPushRpc {
9
9
  public constructor(public proto: proto.MessagePush) {}
10
10
 
11
- static decode(bytes: Uint8Array): FilterPushRpc {
11
+ public static decode(bytes: Uint8Array): FilterPushRpc {
12
12
  const res = proto.MessagePush.decode(bytes);
13
13
  return new FilterPushRpc(res);
14
14
  }
15
15
 
16
- encode(): Uint8Array {
16
+ public encode(): Uint8Array {
17
17
  return proto.MessagePush.encode(this.proto);
18
18
  }
19
19
 
20
- get wakuMessage(): WakuMessage | undefined {
20
+ public get wakuMessage(): WakuMessage | undefined {
21
21
  return this.proto.wakuMessage;
22
22
  }
23
23
 
@@ -25,7 +25,7 @@ export class FilterPushRpc {
25
25
  * Get the pubsub topic from the FilterPushRpc object.
26
26
  * @returns string
27
27
  */
28
- get pubsubTopic(): string | undefined {
28
+ public get pubsubTopic(): string | undefined {
29
29
  return this.proto.pubsubTopic;
30
30
  }
31
31
  }
@@ -33,7 +33,7 @@ export class FilterPushRpc {
33
33
  export class FilterSubscribeRpc {
34
34
  public constructor(public proto: proto.FilterSubscribeRequest) {}
35
35
 
36
- static createSubscribeRequest(
36
+ public static createSubscribeRequest(
37
37
  pubsubTopic: string,
38
38
  contentTopics: string[]
39
39
  ): FilterSubscribeRpc {
@@ -46,7 +46,7 @@ export class FilterSubscribeRpc {
46
46
  });
47
47
  }
48
48
 
49
- static createUnsubscribeRequest(
49
+ public static createUnsubscribeRequest(
50
50
  pubsubTopic: string,
51
51
  contentTopics: string[]
52
52
  ): FilterSubscribeRpc {
@@ -59,7 +59,9 @@ export class FilterSubscribeRpc {
59
59
  });
60
60
  }
61
61
 
62
- static createUnsubscribeAllRequest(pubsubTopic: string): FilterSubscribeRpc {
62
+ public static createUnsubscribeAllRequest(
63
+ pubsubTopic: string
64
+ ): FilterSubscribeRpc {
63
65
  return new FilterSubscribeRpc({
64
66
  requestId: uuid(),
65
67
  filterSubscribeType:
@@ -69,7 +71,7 @@ export class FilterSubscribeRpc {
69
71
  });
70
72
  }
71
73
 
72
- static createSubscriberPingRequest(): FilterSubscribeRpc {
74
+ public static createSubscriberPingRequest(): FilterSubscribeRpc {
73
75
  return new FilterSubscribeRpc({
74
76
  requestId: uuid(),
75
77
  filterSubscribeType:
@@ -79,28 +81,28 @@ export class FilterSubscribeRpc {
79
81
  });
80
82
  }
81
83
 
82
- static decode(bytes: Uint8Array): FilterSubscribeRpc {
84
+ public static decode(bytes: Uint8Array): FilterSubscribeRpc {
83
85
  const res = proto.FilterSubscribeRequest.decode(bytes);
84
86
  return new FilterSubscribeRpc(res);
85
87
  }
86
88
 
87
- encode(): Uint8Array {
89
+ public encode(): Uint8Array {
88
90
  return proto.FilterSubscribeRequest.encode(this.proto);
89
91
  }
90
92
 
91
- get filterSubscribeType(): proto.FilterSubscribeRequest.FilterSubscribeType {
93
+ public get filterSubscribeType(): proto.FilterSubscribeRequest.FilterSubscribeType {
92
94
  return this.proto.filterSubscribeType;
93
95
  }
94
96
 
95
- get requestId(): string {
97
+ public get requestId(): string {
96
98
  return this.proto.requestId;
97
99
  }
98
100
 
99
- get pubsubTopic(): string | undefined {
101
+ public get pubsubTopic(): string | undefined {
100
102
  return this.proto.pubsubTopic;
101
103
  }
102
104
 
103
- get contentTopics(): string[] {
105
+ public get contentTopics(): string[] {
104
106
  return this.proto.contentTopics;
105
107
  }
106
108
  }
@@ -108,24 +110,24 @@ export class FilterSubscribeRpc {
108
110
  export class FilterSubscribeResponse {
109
111
  public constructor(public proto: proto.FilterSubscribeResponse) {}
110
112
 
111
- static decode(bytes: Uint8Array): FilterSubscribeResponse {
113
+ public static decode(bytes: Uint8Array): FilterSubscribeResponse {
112
114
  const res = proto.FilterSubscribeResponse.decode(bytes);
113
115
  return new FilterSubscribeResponse(res);
114
116
  }
115
117
 
116
- encode(): Uint8Array {
118
+ public encode(): Uint8Array {
117
119
  return proto.FilterSubscribeResponse.encode(this.proto);
118
120
  }
119
121
 
120
- get statusCode(): number {
122
+ public get statusCode(): number {
121
123
  return this.proto.statusCode;
122
124
  }
123
125
 
124
- get statusDesc(): string | undefined {
126
+ public get statusDesc(): string | undefined {
125
127
  return this.proto.statusDesc;
126
128
  }
127
129
 
128
- get requestId(): string {
130
+ public get requestId(): string {
129
131
  return this.proto.requestId;
130
132
  }
131
133
  }