@waku/core 0.0.24 → 0.0.25
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/CHANGELOG.md +25 -0
- 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 +6 -6
- 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;QAE5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,IAAI,CAAC,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/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,CAAC,IAAI,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,MAA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EAAE,EAAE,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,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.25",
|
4
4
|
"description": "TypeScript implementation of the Waku v2 protocol",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -73,10 +73,10 @@
|
|
73
73
|
},
|
74
74
|
"dependencies": {
|
75
75
|
"@noble/hashes": "^1.3.2",
|
76
|
-
"@waku/enr": "^0.0.
|
77
|
-
"@waku/interfaces": "0.0.
|
76
|
+
"@waku/enr": "^0.0.19",
|
77
|
+
"@waku/interfaces": "0.0.20",
|
78
78
|
"@waku/proto": "0.0.5",
|
79
|
-
"@waku/utils": "0.0.
|
79
|
+
"@waku/utils": "0.0.13",
|
80
80
|
"debug": "^4.3.4",
|
81
81
|
"it-all": "^3.0.3",
|
82
82
|
"it-length-prefixed": "^9.0.1",
|
@@ -89,9 +89,9 @@
|
|
89
89
|
"@multiformats/multiaddr": "^12.0.0",
|
90
90
|
"@rollup/plugin-commonjs": "^25.0.4",
|
91
91
|
"@rollup/plugin-json": "^6.0.0",
|
92
|
-
"@rollup/plugin-node-resolve": "^15.
|
92
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
93
93
|
"@types/chai": "^4.3.5",
|
94
|
-
"@types/debug": "^4.1.
|
94
|
+
"@types/debug": "^4.1.10",
|
95
95
|
"@types/mocha": "^10.0.1",
|
96
96
|
"@types/uuid": "^9.0.3",
|
97
97
|
"@waku/build-utils": "*",
|
@@ -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
|
}
|
package/src/lib/filter/index.ts
CHANGED
@@ -22,7 +22,7 @@ import {
|
|
22
22
|
groupByContentTopic,
|
23
23
|
toAsyncIterator
|
24
24
|
} from "@waku/utils";
|
25
|
-
import
|
25
|
+
import { Logger } from "@waku/utils";
|
26
26
|
import all from "it-all";
|
27
27
|
import * as lp from "it-length-prefixed";
|
28
28
|
import { pipe } from "it-pipe";
|
@@ -36,7 +36,7 @@ import {
|
|
36
36
|
FilterSubscribeRpc
|
37
37
|
} from "./filter_rpc.js";
|
38
38
|
|
39
|
-
const log =
|
39
|
+
const log = new Logger("filter:v2");
|
40
40
|
|
41
41
|
type SubscriptionCallback<T extends IDecodedMessage> = {
|
42
42
|
decoders: IDecoder<T>[];
|
@@ -74,6 +74,16 @@ class Subscription {
|
|
74
74
|
callback: Callback<T>
|
75
75
|
): Promise<void> {
|
76
76
|
const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
|
77
|
+
|
78
|
+
// check that all decoders are configured for the same pubsub topic as this subscription
|
79
|
+
decodersArray.forEach((decoder) => {
|
80
|
+
if (decoder.pubsubTopic !== this.pubsubTopic) {
|
81
|
+
throw new Error(
|
82
|
+
`Pubsub topic not configured: decoder is configured for pubsub topic ${decoder.pubsubTopic} but this subscription is for pubsub topic ${this.pubsubTopic}. Please create a new Subscription for the different pubsub topic.`
|
83
|
+
);
|
84
|
+
}
|
85
|
+
});
|
86
|
+
|
77
87
|
const decodersGroupedByCT = groupByContentTopic(decodersArray);
|
78
88
|
const contentTopics = Array.from(decodersGroupedByCT.keys());
|
79
89
|
|
@@ -108,7 +118,7 @@ class Subscription {
|
|
108
118
|
);
|
109
119
|
}
|
110
120
|
|
111
|
-
log(
|
121
|
+
log.info(
|
112
122
|
"Subscribed to peer ",
|
113
123
|
this.peer.id.toString(),
|
114
124
|
"for content topics",
|
@@ -174,6 +184,12 @@ class Subscription {
|
|
174
184
|
async (source) => await all(source)
|
175
185
|
);
|
176
186
|
|
187
|
+
if (!res || !res.length) {
|
188
|
+
throw Error(
|
189
|
+
`No response received for request ${request.requestId}: ${res}`
|
190
|
+
);
|
191
|
+
}
|
192
|
+
|
177
193
|
const { statusCode, requestId, statusDesc } =
|
178
194
|
FilterSubscribeResponse.decode(res[0].slice());
|
179
195
|
|
@@ -183,9 +199,9 @@ class Subscription {
|
|
183
199
|
);
|
184
200
|
}
|
185
201
|
|
186
|
-
log("Ping successful");
|
202
|
+
log.info("Ping successful");
|
187
203
|
} catch (error) {
|
188
|
-
log("Error pinging: ", error);
|
204
|
+
log.error("Error pinging: ", error);
|
189
205
|
throw new Error("Error pinging: " + error);
|
190
206
|
}
|
191
207
|
}
|
@@ -206,6 +222,12 @@ class Subscription {
|
|
206
222
|
async (source) => await all(source)
|
207
223
|
);
|
208
224
|
|
225
|
+
if (!res || !res.length) {
|
226
|
+
throw Error(
|
227
|
+
`No response received for request ${request.requestId}: ${res}`
|
228
|
+
);
|
229
|
+
}
|
230
|
+
|
209
231
|
const { statusCode, requestId, statusDesc } =
|
210
232
|
FilterSubscribeResponse.decode(res[0].slice());
|
211
233
|
|
@@ -216,7 +238,7 @@ class Subscription {
|
|
216
238
|
}
|
217
239
|
|
218
240
|
this.subscriptionCallbacks.clear();
|
219
|
-
log("Unsubscribed from all content topics");
|
241
|
+
log.info("Unsubscribed from all content topics");
|
220
242
|
} catch (error) {
|
221
243
|
throw new Error("Error unsubscribing from all content topics: " + error);
|
222
244
|
}
|
@@ -226,7 +248,7 @@ class Subscription {
|
|
226
248
|
const contentTopic = message.contentTopic;
|
227
249
|
const subscriptionCallback = this.subscriptionCallbacks.get(contentTopic);
|
228
250
|
if (!subscriptionCallback) {
|
229
|
-
log("No subscription callback available for ", contentTopic);
|
251
|
+
log.error("No subscription callback available for ", contentTopic);
|
230
252
|
return;
|
231
253
|
}
|
232
254
|
await pushMessage(subscriptionCallback, this.pubsubTopic, message);
|
@@ -260,7 +282,7 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
260
282
|
this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
|
261
283
|
|
262
284
|
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
|
263
|
-
log("Failed to register ", FilterCodecs.PUSH, e);
|
285
|
+
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
264
286
|
});
|
265
287
|
|
266
288
|
this.activeSubscriptions = new Map();
|
@@ -332,7 +354,6 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
332
354
|
}
|
333
355
|
|
334
356
|
private onRequest(streamData: IncomingStreamData): void {
|
335
|
-
log("Receiving message push");
|
336
357
|
try {
|
337
358
|
pipe(streamData.stream, lp.decode, async (source) => {
|
338
359
|
for await (const bytes of source) {
|
@@ -341,12 +362,12 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
341
362
|
const { pubsubTopic, wakuMessage } = response;
|
342
363
|
|
343
364
|
if (!wakuMessage) {
|
344
|
-
log("Received empty message");
|
365
|
+
log.error("Received empty message");
|
345
366
|
return;
|
346
367
|
}
|
347
368
|
|
348
369
|
if (!pubsubTopic) {
|
349
|
-
log("PubSub topic missing from push message");
|
370
|
+
log.error("PubSub topic missing from push message");
|
350
371
|
return;
|
351
372
|
}
|
352
373
|
|
@@ -357,7 +378,9 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
357
378
|
);
|
358
379
|
|
359
380
|
if (!subscription) {
|
360
|
-
log(
|
381
|
+
log.error(
|
382
|
+
`No subscription locally registered for topic ${pubsubTopic}`
|
383
|
+
);
|
361
384
|
return;
|
362
385
|
}
|
363
386
|
|
@@ -365,14 +388,14 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
365
388
|
}
|
366
389
|
}).then(
|
367
390
|
() => {
|
368
|
-
log("Receiving pipe closed.");
|
391
|
+
log.info("Receiving pipe closed.");
|
369
392
|
},
|
370
393
|
(e) => {
|
371
|
-
log("Error with receiving pipe", e);
|
394
|
+
log.error("Error with receiving pipe", e);
|
372
395
|
}
|
373
396
|
);
|
374
397
|
} catch (e) {
|
375
|
-
log("Error decoding message", e);
|
398
|
+
log.error("Error decoding message", e);
|
376
399
|
}
|
377
400
|
}
|
378
401
|
}
|
@@ -392,7 +415,7 @@ async function pushMessage<T extends IDecodedMessage>(
|
|
392
415
|
|
393
416
|
const { contentTopic } = message;
|
394
417
|
if (!contentTopic) {
|
395
|
-
log("Message has no content topic, skipping");
|
418
|
+
log.warn("Message has no content topic, skipping");
|
396
419
|
return;
|
397
420
|
}
|
398
421
|
|
@@ -407,6 +430,6 @@ async function pushMessage<T extends IDecodedMessage>(
|
|
407
430
|
|
408
431
|
await callback(decodedMessage);
|
409
432
|
} catch (e) {
|
410
|
-
log("Error decoding message", e);
|
433
|
+
log.error("Error decoding message", e);
|
411
434
|
}
|
412
435
|
}
|
@@ -2,14 +2,14 @@ import type { PeerId } from "@libp2p/interface/peer-id";
|
|
2
2
|
import type { PeerStore } from "@libp2p/interface/peer-store";
|
3
3
|
import type { IRelay, PeerIdStr } from "@waku/interfaces";
|
4
4
|
import type { KeepAliveOptions } from "@waku/interfaces";
|
5
|
+
import { Logger } from "@waku/utils";
|
5
6
|
import { utf8ToBytes } from "@waku/utils/bytes";
|
6
|
-
import debug from "debug";
|
7
7
|
import type { PingService } from "libp2p/ping";
|
8
8
|
|
9
9
|
import { createEncoder } from "./message/version_0.js";
|
10
10
|
|
11
11
|
export const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
12
|
-
const log =
|
12
|
+
const log = new Logger("keep-alive");
|
13
13
|
|
14
14
|
export class KeepAliveManager {
|
15
15
|
private pingKeepAliveTimers: Map<string, ReturnType<typeof setInterval>>;
|
@@ -48,9 +48,9 @@ export class KeepAliveManager {
|
|
48
48
|
// also update the peer store with the latency
|
49
49
|
try {
|
50
50
|
ping = await libp2pPing.ping(peerId);
|
51
|
-
log(`Ping succeeded (${peerIdStr})`, ping);
|
51
|
+
log.info(`Ping succeeded (${peerIdStr})`, ping);
|
52
52
|
} catch (error) {
|
53
|
-
log(`Ping failed for peer (${peerIdStr}).
|
53
|
+
log.error(`Ping failed for peer (${peerIdStr}).
|
54
54
|
Next ping will be attempted in ${pingPeriodSecs} seconds.
|
55
55
|
`);
|
56
56
|
return;
|
@@ -63,10 +63,10 @@ export class KeepAliveManager {
|
|
63
63
|
}
|
64
64
|
});
|
65
65
|
} catch (e) {
|
66
|
-
log("Failed to update ping", e);
|
66
|
+
log.error("Failed to update ping", e);
|
67
67
|
}
|
68
68
|
} catch (e) {
|
69
|
-
log(`Ping failed (${peerIdStr})`, e);
|
69
|
+
log.error(`Ping failed (${peerIdStr})`, e);
|
70
70
|
}
|
71
71
|
})();
|
72
72
|
}, pingPeriodSecs * 1000);
|
@@ -128,10 +128,10 @@ export class KeepAliveManager {
|
|
128
128
|
ephemeral: true
|
129
129
|
});
|
130
130
|
const interval = setInterval(() => {
|
131
|
-
log("Sending Waku Relay ping message");
|
131
|
+
log.info("Sending Waku Relay ping message");
|
132
132
|
relay
|
133
133
|
.send(encoder, { payload: new Uint8Array([1]) })
|
134
|
-
.catch((e) => log("Failed to send relay ping", e));
|
134
|
+
.catch((e) => log.error("Failed to send relay ping", e));
|
135
135
|
}, relayPeriodSecs * 1000);
|
136
136
|
intervals.push(interval);
|
137
137
|
}
|