@waku/core 0.0.24 → 0.0.25-a42b7be.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/{base_protocol-2a0c882e.js → base_protocol-4bcf7514.js} +19 -11
- package/bundle/index-27b91e3b.js +31 -0
- package/bundle/index.js +199 -167
- package/bundle/lib/base_protocol.js +2 -1
- package/bundle/lib/message/version_0.js +2 -1
- package/bundle/lib/predefined_bootstrap_nodes.js +2 -0
- package/bundle/{version_0-f4afd324.js → version_0-2f1176e3.js} +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/connection_manager.d.ts +2 -1
- package/dist/lib/connection_manager.js +35 -27
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.js +28 -17
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/keep_alive_manager.js +8 -8
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +16 -12
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/message/version_0.js +3 -4
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/store/index.js +7 -8
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.js +4 -4
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +3 -4
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.js +8 -8
- package/dist/lib/waku.js.map +1 -1
- package/package.json +1 -127
- package/src/lib/connection_manager.ts +46 -28
- package/src/lib/filter/index.ts +40 -17
- package/src/lib/keep_alive_manager.ts +8 -8
- package/src/lib/light_push/index.ts +23 -12
- package/src/lib/message/version_0.ts +3 -4
- package/src/lib/store/index.ts +7 -9
- package/src/lib/stream_manager.ts +7 -5
- package/src/lib/wait_for_remote_peer.ts +3 -4
- package/src/lib/waku.ts +8 -8
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stream_manager.js","sourceRoot":"","sources":["../../src/lib/stream_manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"stream_manager.js","sourceRoot":"","sources":["../../src/lib/stream_manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,OAAO,aAAa;IAKf;IACA;IACA;IAND,UAAU,CAAsC;IACvC,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,gBAAgB,CACnB,aAAa,EACb,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3C,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;IAC9B,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;YAClB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,gDAAgD;SAC9E;QAED,mDAAmD;QACnD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAElC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE5B,MAAM,MAA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,gBAAgB,CAAC,IAAI,CAAC,CAAC;SAC7B;IACH,CAAC,CAAC;CACH"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Protocols } from "@waku/interfaces";
|
2
|
-
import
|
2
|
+
import { Logger } from "@waku/utils";
|
3
3
|
import { pEvent } from "p-event";
|
4
|
-
const log =
|
4
|
+
const log = new Logger("wait-for-remote-peer");
|
5
5
|
/**
|
6
6
|
* Wait for a remote peer to be ready given the passed protocols.
|
7
7
|
* Must be used after attempting to connect to nodes, using
|
@@ -60,13 +60,12 @@ async function waitForConnectedPeer(protocol) {
|
|
60
60
|
const codec = protocol.multicodec;
|
61
61
|
const peers = await protocol.peers();
|
62
62
|
if (peers.length) {
|
63
|
-
log(`${codec} peer found: `, peers[0].id.toString());
|
63
|
+
log.info(`${codec} peer found: `, peers[0].id.toString());
|
64
64
|
return;
|
65
65
|
}
|
66
66
|
await new Promise((resolve) => {
|
67
67
|
const cb = (evt) => {
|
68
68
|
if (evt.detail?.protocols?.includes(codec)) {
|
69
|
-
log("Resolving for", codec, evt.detail.protocols);
|
70
69
|
protocol.removeLibp2pEventListener("peer:identify", cb);
|
71
70
|
resolve();
|
72
71
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wait_for_remote_peer.js","sourceRoot":"","sources":["../../src/lib/wait_for_remote_peer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,
|
1
|
+
{"version":3,"file":"wait_for_remote_peer.js","sourceRoot":"","sources":["../../src/lib/wait_for_remote_peer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAE/C;;;;;;;;;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,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;YACpD,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;SAClC;KACF;AACH,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,EAAU,EAAE,YAAoB,EAAiB,EAAE,CACvE,IAAI,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhF,KAAK,UAAU,eAAe,CAC5B,OAAmB,EACnB,SAAiB,EACjB,YAAoB;IAEpB,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAU;IACrC,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,IAAI,IAAI,CAAC,KAAK,EAAE;QACd,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KACjC;IAED,IAAI,IAAI,CAAC,MAAM,EAAE;QACf,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;KAClC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE;QACd,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KACjC;IAED,IAAI,IAAI,CAAC,SAAS,EAAE;QAClB,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;KACrC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/lib/waku.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import { isPeerId } from "@libp2p/interface/peer-id";
|
2
2
|
import { multiaddr } from "@multiformats/multiaddr";
|
3
3
|
import { Protocols } from "@waku/interfaces";
|
4
|
-
import
|
4
|
+
import { Logger } from "@waku/utils";
|
5
5
|
import { ConnectionManager } from "./connection_manager.js";
|
6
6
|
export const DefaultPingKeepAliveValueSecs = 5 * 60;
|
7
7
|
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
8
8
|
export const DefaultUserAgent = "js-waku";
|
9
|
-
const log =
|
9
|
+
const log = new Logger("waku");
|
10
10
|
export class WakuNode {
|
11
11
|
pubsubTopics;
|
12
12
|
libp2p;
|
@@ -36,7 +36,7 @@ export class WakuNode {
|
|
36
36
|
: 0;
|
37
37
|
const peerId = this.libp2p.peerId.toString();
|
38
38
|
this.connectionManager = ConnectionManager.create(peerId, libp2p, { pingKeepAlive, relayKeepAlive }, pubsubTopics, this.relay);
|
39
|
-
log("Waku node created", peerId, `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
39
|
+
log.info("Waku node created", peerId, `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
40
40
|
.lightPush}, filter: ${!!this.filter}`);
|
41
41
|
}
|
42
42
|
/**
|
@@ -60,7 +60,7 @@ export class WakuNode {
|
|
60
60
|
this.relay.gossipSub.multicodecs.forEach((codec) => codecs.push(codec));
|
61
61
|
}
|
62
62
|
else {
|
63
|
-
log("Relay codec not included in dial codec: protocol not mounted locally");
|
63
|
+
log.error("Relay codec not included in dial codec: protocol not mounted locally");
|
64
64
|
}
|
65
65
|
}
|
66
66
|
if (_protocols.includes(Protocols.Store)) {
|
@@ -68,7 +68,7 @@ export class WakuNode {
|
|
68
68
|
codecs.push(this.store.multicodec);
|
69
69
|
}
|
70
70
|
else {
|
71
|
-
log("Store codec not included in dial codec: protocol not mounted locally");
|
71
|
+
log.error("Store codec not included in dial codec: protocol not mounted locally");
|
72
72
|
}
|
73
73
|
}
|
74
74
|
if (_protocols.includes(Protocols.LightPush)) {
|
@@ -76,7 +76,7 @@ export class WakuNode {
|
|
76
76
|
codecs.push(this.lightPush.multicodec);
|
77
77
|
}
|
78
78
|
else {
|
79
|
-
log("Light Push codec not included in dial codec: protocol not mounted locally");
|
79
|
+
log.error("Light Push codec not included in dial codec: protocol not mounted locally");
|
80
80
|
}
|
81
81
|
}
|
82
82
|
if (_protocols.includes(Protocols.Filter)) {
|
@@ -84,10 +84,10 @@ export class WakuNode {
|
|
84
84
|
codecs.push(this.filter.multicodec);
|
85
85
|
}
|
86
86
|
else {
|
87
|
-
log("Filter codec not included in dial codec: protocol not mounted locally");
|
87
|
+
log.error("Filter codec not included in dial codec: protocol not mounted locally");
|
88
88
|
}
|
89
89
|
}
|
90
|
-
log(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
90
|
+
log.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
91
91
|
return this.libp2p.dialProtocol(peerId, codecs);
|
92
92
|
}
|
93
93
|
async start() {
|
package/dist/lib/waku.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"waku.js","sourceRoot":"","sources":["../../src/lib/waku.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAU,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAA6B,MAAM,yBAAyB,CAAC;AAU/E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,
|
1
|
+
{"version":3,"file":"waku.js","sourceRoot":"","sources":["../../src/lib/waku.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAU,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAA6B,MAAM,yBAAyB,CAAC;AAU/E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,GAAG,EAAE,CAAC;AACpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,GAAG,EAAE,CAAC;AACrD,MAAM,CAAC,MAA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CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;YACvD,MAAM,4BAA4B,CAAC;SACpC;QACD,OAAO,cAAc,GAAG,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClE,CAAC;CACF;AACD,SAAS,sBAAsB,CAC7B,MAA+B;IAE/B,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACvD,CAAC"}
|
package/package.json
CHANGED
@@ -1,127 +1 @@
|
|
1
|
-
{
|
2
|
-
"name": "@waku/core",
|
3
|
-
"version": "0.0.24",
|
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/predefined_bootstrap_nodes": {
|
13
|
-
"types": "./dist/lib/predefined_bootstrap_nodes.d.ts",
|
14
|
-
"import": "./dist/lib/predefined_bootstrap_nodes.js"
|
15
|
-
},
|
16
|
-
"./lib/message/version_0": {
|
17
|
-
"types": "./dist/lib/message/version_0.d.ts",
|
18
|
-
"import": "./dist/lib/message/version_0.js"
|
19
|
-
},
|
20
|
-
"./lib/base_protocol": {
|
21
|
-
"types": "./dist/lib/base_protocol.d.ts",
|
22
|
-
"import": "./dist/lib/base_protocol.js"
|
23
|
-
}
|
24
|
-
},
|
25
|
-
"typesVersions": {
|
26
|
-
"*": {
|
27
|
-
"lib/*": [
|
28
|
-
"dist/lib/*"
|
29
|
-
],
|
30
|
-
"constants/*": [
|
31
|
-
"dist/constants/*"
|
32
|
-
]
|
33
|
-
}
|
34
|
-
},
|
35
|
-
"type": "module",
|
36
|
-
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
|
37
|
-
"repository": {
|
38
|
-
"type": "git",
|
39
|
-
"url": "https://github.com/waku-org/js-waku.git"
|
40
|
-
},
|
41
|
-
"bugs": {
|
42
|
-
"url": "https://github.com/waku-org/js-waku/issues"
|
43
|
-
},
|
44
|
-
"license": "MIT OR Apache-2.0",
|
45
|
-
"keywords": [
|
46
|
-
"waku",
|
47
|
-
"decentralised",
|
48
|
-
"communication",
|
49
|
-
"web3",
|
50
|
-
"ethereum",
|
51
|
-
"dapps"
|
52
|
-
],
|
53
|
-
"scripts": {
|
54
|
-
"build": "run-s build:**",
|
55
|
-
"build:esm": "tsc",
|
56
|
-
"build:bundle": "rollup --config rollup.config.js",
|
57
|
-
"fix": "run-s fix:*",
|
58
|
-
"fix:lint": "eslint src *.js --fix",
|
59
|
-
"check": "run-s check:*",
|
60
|
-
"check:tsc": "tsc -p tsconfig.dev.json",
|
61
|
-
"check:lint": "eslint src *.js",
|
62
|
-
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
63
|
-
"test": "run-s test:*",
|
64
|
-
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
65
|
-
"test:browser": "karma start karma.conf.cjs",
|
66
|
-
"watch:build": "tsc -p tsconfig.json -w",
|
67
|
-
"watch:test": "mocha --watch",
|
68
|
-
"prepublish": "npm run build",
|
69
|
-
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
70
|
-
},
|
71
|
-
"engines": {
|
72
|
-
"node": ">=18"
|
73
|
-
},
|
74
|
-
"dependencies": {
|
75
|
-
"@noble/hashes": "^1.3.2",
|
76
|
-
"@waku/enr": "^0.0.18",
|
77
|
-
"@waku/interfaces": "0.0.19",
|
78
|
-
"@waku/proto": "0.0.5",
|
79
|
-
"@waku/utils": "0.0.12",
|
80
|
-
"debug": "^4.3.4",
|
81
|
-
"it-all": "^3.0.3",
|
82
|
-
"it-length-prefixed": "^9.0.1",
|
83
|
-
"it-pipe": "^3.0.1",
|
84
|
-
"p-event": "^6.0.0",
|
85
|
-
"uint8arraylist": "^2.4.3",
|
86
|
-
"uuid": "^9.0.0"
|
87
|
-
},
|
88
|
-
"devDependencies": {
|
89
|
-
"@multiformats/multiaddr": "^12.0.0",
|
90
|
-
"@rollup/plugin-commonjs": "^25.0.4",
|
91
|
-
"@rollup/plugin-json": "^6.0.0",
|
92
|
-
"@rollup/plugin-node-resolve": "^15.1.0",
|
93
|
-
"@types/chai": "^4.3.5",
|
94
|
-
"@types/debug": "^4.1.8",
|
95
|
-
"@types/mocha": "^10.0.1",
|
96
|
-
"@types/uuid": "^9.0.3",
|
97
|
-
"@waku/build-utils": "*",
|
98
|
-
"chai": "^4.3.7",
|
99
|
-
"cspell": "^7.3.2",
|
100
|
-
"fast-check": "^3.13.1",
|
101
|
-
"ignore-loader": "^0.1.2",
|
102
|
-
"isomorphic-fetch": "^3.0.0",
|
103
|
-
"mocha": "^10.2.0",
|
104
|
-
"npm-run-all": "^4.1.5",
|
105
|
-
"process": "^0.11.10",
|
106
|
-
"rollup": "^3.29.2"
|
107
|
-
},
|
108
|
-
"peerDependencies": {
|
109
|
-
"@multiformats/multiaddr": "^12.0.0",
|
110
|
-
"libp2p": "^0.46.3"
|
111
|
-
},
|
112
|
-
"peerDependenciesMeta": {
|
113
|
-
"@multiformats/multiaddr": {
|
114
|
-
"optional": true
|
115
|
-
}
|
116
|
-
},
|
117
|
-
"files": [
|
118
|
-
"dist",
|
119
|
-
"bundle",
|
120
|
-
"src/**/*.ts",
|
121
|
-
"!**/*.spec.*",
|
122
|
-
"!**/*.json",
|
123
|
-
"CHANGELOG.md",
|
124
|
-
"LICENSE",
|
125
|
-
"README.md"
|
126
|
-
]
|
127
|
-
}
|
1
|
+
{"name":"@waku/core","version":"0.0.25-a42b7be.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/predefined_bootstrap_nodes":{"types":"./dist/lib/predefined_bootstrap_nodes.d.ts","import":"./dist/lib/predefined_bootstrap_nodes.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":"run-s test:*","test:node":"TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"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":{"@noble/hashes":"^1.3.2","@waku/enr":"0.0.19-a42b7be.0","@waku/interfaces":"0.0.20-a42b7be.0","@waku/proto":"0.0.6-a42b7be.0","@waku/utils":"0.0.13-a42b7be.0","debug":"^4.3.4","it-all":"^3.0.3","it-length-prefixed":"^9.0.1","it-pipe":"^3.0.1","p-event":"^6.0.0","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@multiformats/multiaddr":"^12.0.0","@rollup/plugin-commonjs":"^25.0.4","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.5","@types/debug":"^4.1.10","@types/mocha":"^10.0.1","@types/uuid":"^9.0.3","@waku/build-utils":"*","chai":"^4.3.7","cspell":"^7.3.2","fast-check":"^3.13.1","ignore-loader":"^0.1.2","isomorphic-fetch":"^3.0.0","mocha":"^10.2.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^3.29.2"},"peerDependencies":{"@multiformats/multiaddr":"^12.0.0","libp2p":"^0.46.3"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
|
@@ -17,11 +17,11 @@ import {
|
|
17
17
|
} from "@waku/interfaces";
|
18
18
|
import { Libp2p, Tags } from "@waku/interfaces";
|
19
19
|
import { shardInfoToPubSubTopics } from "@waku/utils";
|
20
|
-
import
|
20
|
+
import { Logger } from "@waku/utils";
|
21
21
|
|
22
22
|
import { KeepAliveManager } from "./keep_alive_manager.js";
|
23
23
|
|
24
|
-
const log =
|
24
|
+
const log = new Logger("connection-manager");
|
25
25
|
|
26
26
|
export const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1;
|
27
27
|
export const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
|
@@ -38,7 +38,7 @@ export class ConnectionManager
|
|
38
38
|
private dialAttemptsForPeer: Map<string, number> = new Map();
|
39
39
|
private dialErrorsForPeer: Map<string, any> = new Map();
|
40
40
|
|
41
|
-
private
|
41
|
+
private currentActiveParallelDialCount = 0;
|
42
42
|
private pendingPeerDialQueue: Array<PeerId> = [];
|
43
43
|
|
44
44
|
public static create(
|
@@ -128,14 +128,16 @@ export class ConnectionManager
|
|
128
128
|
this.keepAliveManager = new KeepAliveManager(keepAliveOptions, relay);
|
129
129
|
|
130
130
|
this.run()
|
131
|
-
.then(() => log(`Connection Manager is now running`))
|
132
|
-
.catch((error) =>
|
131
|
+
.then(() => log.info(`Connection Manager is now running`))
|
132
|
+
.catch((error) =>
|
133
|
+
log.error(`Unexpected error while running service`, error)
|
134
|
+
);
|
133
135
|
|
134
136
|
// libp2p emits `peer:discovery` events during its initialization
|
135
137
|
// which means that before the ConnectionManager is initialized, some peers may have been discovered
|
136
138
|
// we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
|
137
139
|
this.dialPeerStorePeers().catch((error) =>
|
138
|
-
log(`Unexpected error while dialing peer store peers`, error)
|
140
|
+
log.error(`Unexpected error while dialing peer store peers`, error)
|
139
141
|
);
|
140
142
|
}
|
141
143
|
|
@@ -153,7 +155,7 @@ export class ConnectionManager
|
|
153
155
|
try {
|
154
156
|
await Promise.all(dialPromises);
|
155
157
|
} catch (error) {
|
156
|
-
log(`Unexpected error while dialing peer store peers`, error);
|
158
|
+
log.error(`Unexpected error while dialing peer store peers`, error);
|
157
159
|
}
|
158
160
|
}
|
159
161
|
|
@@ -181,11 +183,13 @@ export class ConnectionManager
|
|
181
183
|
}
|
182
184
|
|
183
185
|
private async dialPeer(peerId: PeerId): Promise<void> {
|
184
|
-
this.
|
186
|
+
this.currentActiveParallelDialCount += 1;
|
185
187
|
let dialAttempt = 0;
|
186
188
|
while (dialAttempt < this.options.maxDialAttemptsForPeer) {
|
187
189
|
try {
|
188
|
-
log
|
190
|
+
log.info(
|
191
|
+
`Dialing peer ${peerId.toString()} on attempt ${dialAttempt + 1}`
|
192
|
+
);
|
189
193
|
await this.libp2p.dial(peerId);
|
190
194
|
|
191
195
|
const tags = await this.getTagNamesForPeer(peerId);
|
@@ -195,16 +199,21 @@ export class ConnectionManager
|
|
195
199
|
conn.tags = Array.from(new Set([...conn.tags, ...tags]));
|
196
200
|
});
|
197
201
|
|
198
|
-
|
202
|
+
// instead of deleting the peer from the peer store, we set the dial attempt to -1
|
203
|
+
// this helps us keep track of peers that have been dialed before
|
204
|
+
this.dialAttemptsForPeer.set(peerId.toString(), -1);
|
205
|
+
|
199
206
|
// Dialing succeeded, break the loop
|
200
207
|
break;
|
201
208
|
} catch (error) {
|
202
209
|
if (error instanceof AggregateError) {
|
203
210
|
// Handle AggregateError
|
204
|
-
log
|
211
|
+
log.error(
|
212
|
+
`Error dialing peer ${peerId.toString()} - ${error.errors}`
|
213
|
+
);
|
205
214
|
} else {
|
206
215
|
// Handle generic error
|
207
|
-
log(
|
216
|
+
log.error(
|
208
217
|
`Error dialing peer ${peerId.toString()} - ${
|
209
218
|
(error as any).message
|
210
219
|
}`
|
@@ -218,7 +227,7 @@ export class ConnectionManager
|
|
218
227
|
}
|
219
228
|
|
220
229
|
// Always decrease the active dial count and process the dial queue
|
221
|
-
this.
|
230
|
+
this.currentActiveParallelDialCount--;
|
222
231
|
this.processDialQueue();
|
223
232
|
|
224
233
|
// If max dial attempts reached and dialing failed, delete the peer
|
@@ -230,9 +239,9 @@ export class ConnectionManager
|
|
230
239
|
let errorMessage;
|
231
240
|
if (error instanceof AggregateError) {
|
232
241
|
if (!error.errors) {
|
233
|
-
log(`No errors array found for AggregateError`);
|
242
|
+
log.warn(`No errors array found for AggregateError`);
|
234
243
|
} else if (error.errors.length === 0) {
|
235
|
-
log(`Errors array is empty for AggregateError`);
|
244
|
+
log.warn(`Errors array is empty for AggregateError`);
|
236
245
|
} else {
|
237
246
|
errorMessage = JSON.stringify(error.errors[0]);
|
238
247
|
}
|
@@ -240,8 +249,8 @@ export class ConnectionManager
|
|
240
249
|
errorMessage = error.message;
|
241
250
|
}
|
242
251
|
|
243
|
-
log(
|
244
|
-
`Deleting undialable peer ${peerId.toString()} from peer store.
|
252
|
+
log.info(
|
253
|
+
`Deleting undialable peer ${peerId.toString()} from peer store. Reason: ${errorMessage}`
|
245
254
|
);
|
246
255
|
}
|
247
256
|
|
@@ -259,9 +268,9 @@ export class ConnectionManager
|
|
259
268
|
try {
|
260
269
|
this.keepAliveManager.stop(peerId);
|
261
270
|
await this.libp2p.hangUp(peerId);
|
262
|
-
log(`Dropped connection with peer ${peerId.toString()}`);
|
271
|
+
log.info(`Dropped connection with peer ${peerId.toString()}`);
|
263
272
|
} catch (error) {
|
264
|
-
log(
|
273
|
+
log.error(
|
265
274
|
`Error dropping connection with peer ${peerId.toString()} - ${error}`
|
266
275
|
);
|
267
276
|
}
|
@@ -270,12 +279,12 @@ export class ConnectionManager
|
|
270
279
|
private processDialQueue(): void {
|
271
280
|
if (
|
272
281
|
this.pendingPeerDialQueue.length > 0 &&
|
273
|
-
this.
|
282
|
+
this.currentActiveParallelDialCount < this.options.maxParallelDials
|
274
283
|
) {
|
275
284
|
const peerId = this.pendingPeerDialQueue.shift();
|
276
285
|
if (!peerId) return;
|
277
286
|
this.attemptDial(peerId).catch((error) => {
|
278
|
-
log(error);
|
287
|
+
log.error(error);
|
279
288
|
});
|
280
289
|
}
|
281
290
|
}
|
@@ -316,13 +325,13 @@ export class ConnectionManager
|
|
316
325
|
private async attemptDial(peerId: PeerId): Promise<void> {
|
317
326
|
if (!(await this.shouldDialPeer(peerId))) return;
|
318
327
|
|
319
|
-
if (this.
|
328
|
+
if (this.currentActiveParallelDialCount >= this.options.maxParallelDials) {
|
320
329
|
this.pendingPeerDialQueue.push(peerId);
|
321
330
|
return;
|
322
331
|
}
|
323
332
|
|
324
333
|
this.dialPeer(peerId).catch((err) => {
|
325
|
-
log(`Error dialing peer ${peerId.toString()} : ${err}`);
|
334
|
+
log.error(`Error dialing peer ${peerId.toString()} : ${err}`);
|
326
335
|
});
|
327
336
|
}
|
328
337
|
|
@@ -336,7 +345,7 @@ export class ConnectionManager
|
|
336
345
|
try {
|
337
346
|
await this.attemptDial(peerId);
|
338
347
|
} catch (error) {
|
339
|
-
log(`Error dialing peer ${peerId.toString()} : ${error}`);
|
348
|
+
log.error(`Error dialing peer ${peerId.toString()} : ${error}`);
|
340
349
|
}
|
341
350
|
})();
|
342
351
|
},
|
@@ -398,13 +407,14 @@ export class ConnectionManager
|
|
398
407
|
* 1. If the peer is already connected, don't dial
|
399
408
|
* 2. If the peer is not part of any of the configured pubsub topics, don't dial
|
400
409
|
* 3. If the peer is not dialable based on bootstrap status, don't dial
|
410
|
+
* 4. If the peer is already has an active dial attempt, or has been dialed before, don't dial it
|
401
411
|
* @returns true if the peer should be dialed, false otherwise
|
402
412
|
*/
|
403
413
|
private async shouldDialPeer(peerId: PeerId): Promise<boolean> {
|
404
414
|
// if we're already connected to the peer, don't dial
|
405
415
|
const isConnected = this.libp2p.getConnections(peerId).length > 0;
|
406
416
|
if (isConnected) {
|
407
|
-
log(`Already connected to peer ${peerId.toString()}. Not dialing.`);
|
417
|
+
log.warn(`Already connected to peer ${peerId.toString()}. Not dialing.`);
|
408
418
|
return false;
|
409
419
|
}
|
410
420
|
|
@@ -414,7 +424,7 @@ export class ConnectionManager
|
|
414
424
|
peerId,
|
415
425
|
this.libp2p.peerStore
|
416
426
|
);
|
417
|
-
log(
|
427
|
+
log.warn(
|
418
428
|
`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
|
419
429
|
this.configuredPubSubTopics
|
420
430
|
}).
|
@@ -425,12 +435,20 @@ export class ConnectionManager
|
|
425
435
|
|
426
436
|
// if the peer is not dialable based on bootstrap status, don't dial
|
427
437
|
if (!(await this.isPeerDialableBasedOnBootstrapStatus(peerId))) {
|
428
|
-
log(
|
438
|
+
log.warn(
|
429
439
|
`Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`
|
430
440
|
);
|
431
441
|
return false;
|
432
442
|
}
|
433
443
|
|
444
|
+
// If the peer is already already has an active dial attempt, or has been dialed before, don't dial it
|
445
|
+
if (this.dialAttemptsForPeer.has(peerId.toString())) {
|
446
|
+
log.warn(
|
447
|
+
`Peer ${peerId.toString()} has already been attempted dial before, or already has a dial attempt in progress, skipping dial`
|
448
|
+
);
|
449
|
+
return false;
|
450
|
+
}
|
451
|
+
|
434
452
|
return true;
|
435
453
|
}
|
436
454
|
|
@@ -486,7 +504,7 @@ export class ConnectionManager
|
|
486
504
|
const peer = await this.libp2p.peerStore.get(peerId);
|
487
505
|
return Array.from(peer.tags.keys());
|
488
506
|
} catch (error) {
|
489
|
-
log(`Failed to get peer ${peerId}, error: ${error}`);
|
507
|
+
log.error(`Failed to get peer ${peerId}, error: ${error}`);
|
490
508
|
return [];
|
491
509
|
}
|
492
510
|
}
|