@waku/core 0.0.37-987c6cd.0 → 0.0.37-c24842a.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/index.js +168 -66
- package/bundle/lib/message/version_0.js +1 -1
- package/bundle/{version_0-BpF0pNhc.js → version_0-BHaZD8Qu.js} +172 -26
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/connection_manager/connection_limiter.d.ts +12 -3
- package/dist/lib/connection_manager/connection_limiter.js +98 -45
- package/dist/lib/connection_manager/connection_limiter.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +1 -4
- package/dist/lib/connection_manager/connection_manager.js +15 -7
- package/dist/lib/connection_manager/connection_manager.js.map +1 -1
- package/dist/lib/connection_manager/dialer.d.ts +7 -1
- package/dist/lib/connection_manager/dialer.js +41 -6
- package/dist/lib/connection_manager/dialer.js.map +1 -1
- package/dist/lib/connection_manager/discovery_dialer.d.ts +1 -1
- package/dist/lib/connection_manager/discovery_dialer.js.map +1 -1
- package/dist/lib/metadata/metadata.d.ts +2 -2
- package/dist/lib/metadata/metadata.js +14 -8
- package/dist/lib/metadata/metadata.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/connection_manager/connection_limiter.ts +156 -65
- package/src/lib/connection_manager/connection_manager.ts +16 -12
- package/src/lib/connection_manager/dialer.ts +60 -7
- package/src/lib/connection_manager/discovery_dialer.ts +2 -4
- package/src/lib/metadata/metadata.ts +13 -12
package/bundle/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { e as equals$2, c as coerce, b as base32, a as base58btc, d as base36, v as version_0, f as allocUnsafe, g as alloc, h as encodingLength$1, i as encode$3, j as decode$4, L as Logger, F as FilterSubscribeRequest, k as FilterSubscribeResponse$1, M as MessagePush, P as ProtocolError, l as PushRpc$1, m as PushResponse, S as StoreQueryRequest$1, n as StoreQueryResponse$1, T as Tags, o as createEncoder, p as pubsubTopicToSingleShardInfo, u as utf8ToBytes, q as contentTopicToShardIndex, t as toString, r as fromString, s as hexToBytes, w as isBytes, x as abytes, y as bytesToHex, z as concatBytes, A as anumber, B as randomBytes,
|
2
|
-
export { a2 as createDecoder } from './version_0-
|
1
|
+
import { e as equals$2, c as coerce, b as base32, a as base58btc, d as base36, v as version_0, f as allocUnsafe, g as alloc, h as encodingLength$1, i as encode$3, j as decode$4, L as Logger, F as FilterSubscribeRequest, k as FilterSubscribeResponse$1, M as MessagePush, P as ProtocolError, l as PushRpc$1, m as PushResponse, S as StoreQueryRequest$1, n as StoreQueryResponse$1, C as CONNECTION_LOCKED_TAG, T as Tags, o as createEncoder, p as pubsubTopicToSingleShardInfo, u as utf8ToBytes, q as contentTopicToShardIndex, t as toString, r as fromString, s as hexToBytes, w as isBytes, x as abytes, y as bytesToHex, z as concatBytes, A as anumber, B as randomBytes, D as sha512, E as enumeration, G as message, H as encodeMessage, I as decodeMessage, J as Hash, K as ahash, N as toBytes, O as clean, Q as aexists, R as sha256$1, U as bases, V as base64url, W as encodeUint8Array, X as bytesToUtf8, Y as WakuMetadataRequest, Z as WakuMetadataResponse, _ as concat$1, $ as sha256$2, a0 as bytesToHex$1, a1 as numberToBytes } from './version_0-BHaZD8Qu.js';
|
2
|
+
export { a2 as createDecoder } from './version_0-BHaZD8Qu.js';
|
3
3
|
|
4
4
|
/* eslint-disable */
|
5
5
|
var encode_1 = encode$2;
|
@@ -3059,6 +3059,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
3059
3059
|
});
|
3060
3060
|
|
3061
3061
|
const log$6 = new Logger("connection-limiter");
|
3062
|
+
const DEFAULT_CONNECTION_MONITOR_INTERVAL = 5 * 1_000;
|
3062
3063
|
/**
|
3063
3064
|
* This class is responsible for limiting the number of connections to peers.
|
3064
3065
|
* It also dials all known peers because libp2p might have emitted `peer:discovery` before initialization
|
@@ -3069,6 +3070,7 @@ class ConnectionLimiter {
|
|
3069
3070
|
events;
|
3070
3071
|
networkMonitor;
|
3071
3072
|
dialer;
|
3073
|
+
connectionMonitorInterval = null;
|
3072
3074
|
options;
|
3073
3075
|
constructor(options) {
|
3074
3076
|
this.libp2p = options.libp2p;
|
@@ -3077,14 +3079,16 @@ class ConnectionLimiter {
|
|
3077
3079
|
this.dialer = options.dialer;
|
3078
3080
|
this.options = options.options;
|
3079
3081
|
this.onWakuConnectionEvent = this.onWakuConnectionEvent.bind(this);
|
3080
|
-
this.onConnectedEvent = this.onConnectedEvent.bind(this);
|
3081
3082
|
this.onDisconnectedEvent = this.onDisconnectedEvent.bind(this);
|
3082
3083
|
}
|
3083
3084
|
start() {
|
3084
3085
|
// dial all known peers because libp2p might have emitted `peer:discovery` before initialization
|
3085
3086
|
void this.dialPeersFromStore();
|
3087
|
+
if (this.options.enableAutoRecovery &&
|
3088
|
+
this.connectionMonitorInterval === null) {
|
3089
|
+
this.connectionMonitorInterval = setInterval(() => void this.maintainConnections(), DEFAULT_CONNECTION_MONITOR_INTERVAL);
|
3090
|
+
}
|
3086
3091
|
this.events.addEventListener("waku:connection", this.onWakuConnectionEvent);
|
3087
|
-
this.libp2p.addEventListener("peer:connect", this.onConnectedEvent);
|
3088
3092
|
/**
|
3089
3093
|
* NOTE: Event is not being emitted on closing nor losing a connection.
|
3090
3094
|
* @see https://github.com/libp2p/js-libp2p/issues/939
|
@@ -3100,27 +3104,24 @@ class ConnectionLimiter {
|
|
3100
3104
|
}
|
3101
3105
|
stop() {
|
3102
3106
|
this.events.removeEventListener("waku:connection", this.onWakuConnectionEvent);
|
3103
|
-
this.libp2p.removeEventListener("peer:connect", this.onConnectedEvent);
|
3104
3107
|
this.libp2p.removeEventListener("peer:disconnect", this.onDisconnectedEvent);
|
3108
|
+
if (this.connectionMonitorInterval) {
|
3109
|
+
clearInterval(this.connectionMonitorInterval);
|
3110
|
+
this.connectionMonitorInterval = null;
|
3111
|
+
}
|
3105
3112
|
}
|
3106
3113
|
onWakuConnectionEvent() {
|
3114
|
+
if (!this.options.enableAutoRecovery) {
|
3115
|
+
log$6.info(`Auto recovery is disabled, skipping`);
|
3116
|
+
return;
|
3117
|
+
}
|
3107
3118
|
if (this.networkMonitor.isBrowserConnected()) {
|
3108
3119
|
void this.dialPeersFromStore();
|
3109
3120
|
}
|
3110
3121
|
}
|
3111
|
-
async
|
3112
|
-
|
3113
|
-
|
3114
|
-
const tags = await this.getTagsForPeer(peerId);
|
3115
|
-
const isBootstrap = tags.includes(Tags.BOOTSTRAP);
|
3116
|
-
if (!isBootstrap) {
|
3117
|
-
log$6.info(`Connected to peer ${peerId.toString()} is not a bootstrap peer`);
|
3118
|
-
return;
|
3119
|
-
}
|
3120
|
-
if (await this.hasMoreThanMaxBootstrapConnections()) {
|
3121
|
-
log$6.info(`Connected to peer ${peerId.toString()} and node has more than max bootstrap connections ${this.options.maxBootstrapPeers}. Dropping connection.`);
|
3122
|
-
await this.libp2p.hangUp(peerId);
|
3123
|
-
}
|
3122
|
+
async maintainConnections() {
|
3123
|
+
await this.maintainConnectionsCount();
|
3124
|
+
await this.maintainBootstrapConnections();
|
3124
3125
|
}
|
3125
3126
|
async onDisconnectedEvent() {
|
3126
3127
|
if (this.libp2p.getConnections().length === 0) {
|
@@ -3128,54 +3129,106 @@ class ConnectionLimiter {
|
|
3128
3129
|
await this.dialPeersFromStore();
|
3129
3130
|
}
|
3130
3131
|
}
|
3131
|
-
async
|
3132
|
-
log$6.info(`
|
3133
|
-
const
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
.
|
3138
|
-
|
3132
|
+
async maintainConnectionsCount() {
|
3133
|
+
log$6.info(`Maintaining connections count`);
|
3134
|
+
const connections = this.libp2p.getConnections();
|
3135
|
+
if (connections.length <= this.options.maxConnections) {
|
3136
|
+
log$6.info(`Node has less than max connections ${this.options.maxConnections}, trying to dial more peers`);
|
3137
|
+
const peers = await this.getPrioritizedPeers();
|
3138
|
+
if (peers.length === 0) {
|
3139
|
+
log$6.info(`No peers to dial, node is utilizing all known peers`);
|
3140
|
+
return;
|
3141
|
+
}
|
3142
|
+
const promises = peers
|
3143
|
+
.slice(0, this.options.maxConnections - connections.length)
|
3144
|
+
.map((p) => this.dialer.dial(p.id));
|
3145
|
+
await Promise.all(promises);
|
3146
|
+
return;
|
3147
|
+
}
|
3148
|
+
log$6.info(`Node has more than max connections ${this.options.maxConnections}, dropping connections`);
|
3139
3149
|
try {
|
3140
|
-
|
3150
|
+
const connectionsToDrop = connections
|
3151
|
+
.filter((c) => !c.tags.includes(CONNECTION_LOCKED_TAG))
|
3152
|
+
.slice(this.options.maxConnections);
|
3153
|
+
if (connectionsToDrop.length === 0) {
|
3154
|
+
log$6.info(`No connections to drop, skipping`);
|
3155
|
+
return;
|
3156
|
+
}
|
3157
|
+
const promises = connectionsToDrop.map((c) => this.libp2p.hangUp(c.remotePeer));
|
3141
3158
|
await Promise.all(promises);
|
3142
|
-
log$6.info(`
|
3159
|
+
log$6.info(`Dropped ${connectionsToDrop.length} connections`);
|
3143
3160
|
}
|
3144
3161
|
catch (error) {
|
3145
|
-
log$6.error(`Unexpected error while
|
3162
|
+
log$6.error(`Unexpected error while maintaining connections`, error);
|
3146
3163
|
}
|
3147
3164
|
}
|
3148
|
-
async
|
3165
|
+
async maintainBootstrapConnections() {
|
3166
|
+
log$6.info(`Maintaining bootstrap connections`);
|
3167
|
+
const bootstrapPeers = await this.getBootstrapPeers();
|
3168
|
+
if (bootstrapPeers.length <= this.options.maxBootstrapPeers) {
|
3169
|
+
return;
|
3170
|
+
}
|
3149
3171
|
try {
|
3150
|
-
const
|
3151
|
-
|
3152
|
-
|
3153
|
-
|
3154
|
-
|
3155
|
-
return bootstrapPeers.length > this.options.maxBootstrapPeers;
|
3172
|
+
const peersToDrop = bootstrapPeers.slice(this.options.maxBootstrapPeers);
|
3173
|
+
log$6.info(`Dropping ${peersToDrop.length} bootstrap connections because node has more than max bootstrap connections ${this.options.maxBootstrapPeers}`);
|
3174
|
+
const promises = peersToDrop.map((p) => this.libp2p.hangUp(p.id));
|
3175
|
+
await Promise.all(promises);
|
3176
|
+
log$6.info(`Dropped ${peersToDrop.length} bootstrap connections`);
|
3156
3177
|
}
|
3157
3178
|
catch (error) {
|
3158
|
-
log$6.error(`Unexpected error while
|
3159
|
-
return false;
|
3179
|
+
log$6.error(`Unexpected error while maintaining bootstrap connections`, error);
|
3160
3180
|
}
|
3161
3181
|
}
|
3162
|
-
async
|
3182
|
+
async dialPeersFromStore() {
|
3183
|
+
log$6.info(`Dialing peers from store`);
|
3163
3184
|
try {
|
3164
|
-
|
3185
|
+
const peers = await this.getPrioritizedPeers();
|
3186
|
+
if (peers.length === 0) {
|
3187
|
+
log$6.info(`No peers to dial, skipping`);
|
3188
|
+
return;
|
3189
|
+
}
|
3190
|
+
const promises = peers.map((p) => this.dialer.dial(p.id));
|
3191
|
+
log$6.info(`Dialing ${peers.length} peers from store`);
|
3192
|
+
await Promise.all(promises);
|
3193
|
+
log$6.info(`Dialed ${promises.length} peers from store`);
|
3165
3194
|
}
|
3166
3195
|
catch (error) {
|
3167
|
-
log$6.error(`
|
3168
|
-
return null;
|
3196
|
+
log$6.error(`Unexpected error while dialing peer store peers`, error);
|
3169
3197
|
}
|
3170
3198
|
}
|
3171
|
-
|
3199
|
+
/**
|
3200
|
+
* Returns a list of peers ordered by priority:
|
3201
|
+
* - bootstrap peers
|
3202
|
+
* - peers from peer exchange
|
3203
|
+
* - peers from local store (last because we are not sure that locally stored information is up to date)
|
3204
|
+
*/
|
3205
|
+
async getPrioritizedPeers() {
|
3206
|
+
const allPeers = await this.libp2p.peerStore.all();
|
3207
|
+
const allConnections = this.libp2p.getConnections();
|
3208
|
+
log$6.info(`Found ${allPeers.length} peers in store, and found ${allConnections.length} connections`);
|
3209
|
+
const notConnectedPeers = allPeers.filter((p) => !allConnections.some((c) => c.remotePeer.equals(p.id)) &&
|
3210
|
+
p.addresses.some((a) => a.multiaddr.toString().includes("wss") ||
|
3211
|
+
a.multiaddr.toString().includes("ws")));
|
3212
|
+
const bootstrapPeers = notConnectedPeers.filter((p) => p.tags.has(Tags.BOOTSTRAP));
|
3213
|
+
const peerExchangePeers = notConnectedPeers.filter((p) => p.tags.has(Tags.PEER_EXCHANGE));
|
3214
|
+
const localStorePeers = notConnectedPeers.filter((p) => p.tags.has(Tags.LOCAL));
|
3215
|
+
return [...bootstrapPeers, ...peerExchangePeers, ...localStorePeers];
|
3216
|
+
}
|
3217
|
+
async getBootstrapPeers() {
|
3218
|
+
const peers = await Promise.all(this.libp2p
|
3219
|
+
.getConnections()
|
3220
|
+
.map((conn) => conn.remotePeer)
|
3221
|
+
.map((id) => this.getPeer(id)));
|
3222
|
+
const bootstrapPeers = peers.filter((peer) => peer && peer.tags.has(Tags.BOOTSTRAP));
|
3223
|
+
return bootstrapPeers;
|
3224
|
+
}
|
3225
|
+
async getPeer(peerId) {
|
3172
3226
|
try {
|
3173
|
-
|
3174
|
-
return Array.from(peer.tags.keys());
|
3227
|
+
return await this.libp2p.peerStore.get(peerId);
|
3175
3228
|
}
|
3176
3229
|
catch (error) {
|
3177
3230
|
log$6.error(`Failed to get peer ${peerId}, error: ${error}`);
|
3178
|
-
return
|
3231
|
+
return null;
|
3179
3232
|
}
|
3180
3233
|
}
|
3181
3234
|
}
|
@@ -3184,28 +3237,36 @@ const log$5 = new Logger("dialer");
|
|
3184
3237
|
class Dialer {
|
3185
3238
|
libp2p;
|
3186
3239
|
shardReader;
|
3240
|
+
options;
|
3187
3241
|
dialingQueue = [];
|
3188
3242
|
dialHistory = new Map();
|
3243
|
+
failedDials = new Map();
|
3189
3244
|
dialingInterval = null;
|
3190
3245
|
isProcessing = false;
|
3246
|
+
isImmediateDialing = false;
|
3191
3247
|
constructor(options) {
|
3192
3248
|
this.libp2p = options.libp2p;
|
3193
3249
|
this.shardReader = options.shardReader;
|
3250
|
+
this.options = options.options;
|
3194
3251
|
}
|
3195
3252
|
start() {
|
3253
|
+
log$5.info("Starting dialer");
|
3196
3254
|
if (!this.dialingInterval) {
|
3197
3255
|
this.dialingInterval = setInterval(() => {
|
3198
3256
|
void this.processQueue();
|
3199
3257
|
}, 500);
|
3200
3258
|
}
|
3201
3259
|
this.dialHistory.clear();
|
3260
|
+
this.failedDials.clear();
|
3202
3261
|
}
|
3203
3262
|
stop() {
|
3263
|
+
log$5.info("Stopping dialer");
|
3204
3264
|
if (this.dialingInterval) {
|
3205
3265
|
clearInterval(this.dialingInterval);
|
3206
3266
|
this.dialingInterval = null;
|
3207
3267
|
}
|
3208
3268
|
this.dialHistory.clear();
|
3269
|
+
this.failedDials.clear();
|
3209
3270
|
}
|
3210
3271
|
async dial(peerId) {
|
3211
3272
|
const shouldSkip = await this.shouldSkipPeer(peerId);
|
@@ -3213,22 +3274,28 @@ class Dialer {
|
|
3213
3274
|
log$5.info(`Skipping peer: ${peerId}`);
|
3214
3275
|
return;
|
3215
3276
|
}
|
3277
|
+
const isEmptyQueue = this.dialingQueue.length === 0;
|
3278
|
+
const isNotDialing = !this.isProcessing && !this.isImmediateDialing;
|
3216
3279
|
// If queue is empty and we're not currently processing, dial immediately
|
3217
|
-
if (
|
3280
|
+
if (isEmptyQueue && isNotDialing) {
|
3281
|
+
this.isImmediateDialing = true;
|
3282
|
+
log$5.info("Dialed peer immediately");
|
3218
3283
|
await this.dialPeer(peerId);
|
3284
|
+
this.isImmediateDialing = false;
|
3285
|
+
log$5.info("Released immediate dial lock");
|
3219
3286
|
}
|
3220
3287
|
else {
|
3221
|
-
// Add to queue
|
3222
3288
|
this.dialingQueue.push(peerId);
|
3223
3289
|
log$5.info(`Added peer to dialing queue, queue size: ${this.dialingQueue.length}`);
|
3224
3290
|
}
|
3225
3291
|
}
|
3226
3292
|
async processQueue() {
|
3227
|
-
if (this.dialingQueue.length === 0 || this.isProcessing)
|
3293
|
+
if (this.dialingQueue.length === 0 || this.isProcessing) {
|
3228
3294
|
return;
|
3295
|
+
}
|
3229
3296
|
this.isProcessing = true;
|
3230
3297
|
try {
|
3231
|
-
const peersToDial = this.dialingQueue.slice(0,
|
3298
|
+
const peersToDial = this.dialingQueue.slice(0, this.options.maxDialingPeers);
|
3232
3299
|
this.dialingQueue = this.dialingQueue.slice(peersToDial.length);
|
3233
3300
|
log$5.info(`Processing dial queue: dialing ${peersToDial.length} peers, ${this.dialingQueue.length} remaining in queue`);
|
3234
3301
|
await Promise.all(peersToDial.map((peerId) => this.dialPeer(peerId)));
|
@@ -3242,10 +3309,12 @@ class Dialer {
|
|
3242
3309
|
log$5.info(`Dialing peer from queue: ${peerId}`);
|
3243
3310
|
await this.libp2p.dial(peerId);
|
3244
3311
|
this.dialHistory.set(peerId.toString(), Date.now());
|
3312
|
+
this.failedDials.delete(peerId.toString());
|
3245
3313
|
log$5.info(`Successfully dialed peer from queue: ${peerId}`);
|
3246
3314
|
}
|
3247
3315
|
catch (error) {
|
3248
3316
|
log$5.error(`Error dialing peer ${peerId}`, error);
|
3317
|
+
this.failedDials.set(peerId.toString(), Date.now());
|
3249
3318
|
}
|
3250
3319
|
}
|
3251
3320
|
async shouldSkipPeer(peerId) {
|
@@ -3254,11 +3323,14 @@ class Dialer {
|
|
3254
3323
|
log$5.info(`Skipping peer ${peerId} - already connected`);
|
3255
3324
|
return true;
|
3256
3325
|
}
|
3257
|
-
|
3258
|
-
if (lastDialed && Date.now() - lastDialed < 10_000) {
|
3326
|
+
if (this.isRecentlyDialed(peerId)) {
|
3259
3327
|
log$5.info(`Skipping peer ${peerId} - already dialed in the last 10 seconds`);
|
3260
3328
|
return true;
|
3261
3329
|
}
|
3330
|
+
if (this.isRecentlyFailed(peerId)) {
|
3331
|
+
log$5.info(`Skipping peer ${peerId} - recently failed to dial`);
|
3332
|
+
return true;
|
3333
|
+
}
|
3262
3334
|
try {
|
3263
3335
|
const hasShardInfo = await this.shardReader.hasShardInfo(peerId);
|
3264
3336
|
if (!hasShardInfo) {
|
@@ -3277,6 +3349,22 @@ class Dialer {
|
|
3277
3349
|
return true; // Skip peer when there's an error
|
3278
3350
|
}
|
3279
3351
|
}
|
3352
|
+
isRecentlyDialed(peerId) {
|
3353
|
+
const lastDialed = this.dialHistory.get(peerId.toString());
|
3354
|
+
if (lastDialed &&
|
3355
|
+
Date.now() - lastDialed < this.options.dialCooldown * 1000) {
|
3356
|
+
return true;
|
3357
|
+
}
|
3358
|
+
return false;
|
3359
|
+
}
|
3360
|
+
isRecentlyFailed(peerId) {
|
3361
|
+
const lastFailed = this.failedDials.get(peerId.toString());
|
3362
|
+
if (lastFailed &&
|
3363
|
+
Date.now() - lastFailed < this.options.failedDialCooldown * 1000) {
|
3364
|
+
return true;
|
3365
|
+
}
|
3366
|
+
return false;
|
3367
|
+
}
|
3280
3368
|
}
|
3281
3369
|
|
3282
3370
|
const log$4 = new Logger("discovery-dialer");
|
@@ -8917,11 +9005,15 @@ const mapToPeerId = (input) => {
|
|
8917
9005
|
};
|
8918
9006
|
|
8919
9007
|
const log$1 = new Logger("connection-manager");
|
8920
|
-
const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED =
|
9008
|
+
const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 3;
|
8921
9009
|
const DEFAULT_PING_KEEP_ALIVE_SEC = 5 * 60;
|
8922
9010
|
const DEFAULT_RELAY_KEEP_ALIVE_SEC = 5 * 60;
|
9011
|
+
const DEFAULT_ENABLE_AUTO_RECOVERY = true;
|
9012
|
+
const DEFAULT_MAX_CONNECTIONS = 10;
|
9013
|
+
const DEFAULT_MAX_DIALING_PEERS = 3;
|
9014
|
+
const DEFAULT_FAILED_DIAL_COOLDOWN_SEC = 60;
|
9015
|
+
const DEFAULT_DIAL_COOLDOWN_SEC = 10;
|
8923
9016
|
class ConnectionManager {
|
8924
|
-
pubsubTopics;
|
8925
9017
|
keepAliveManager;
|
8926
9018
|
discoveryDialer;
|
8927
9019
|
dialer;
|
@@ -8932,11 +9024,15 @@ class ConnectionManager {
|
|
8932
9024
|
libp2p;
|
8933
9025
|
constructor(options) {
|
8934
9026
|
this.libp2p = options.libp2p;
|
8935
|
-
this.pubsubTopics = options.pubsubTopics;
|
8936
9027
|
this.options = {
|
8937
9028
|
maxBootstrapPeers: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED,
|
9029
|
+
maxConnections: DEFAULT_MAX_CONNECTIONS,
|
8938
9030
|
pingKeepAlive: DEFAULT_PING_KEEP_ALIVE_SEC,
|
8939
9031
|
relayKeepAlive: DEFAULT_RELAY_KEEP_ALIVE_SEC,
|
9032
|
+
enableAutoRecovery: DEFAULT_ENABLE_AUTO_RECOVERY,
|
9033
|
+
maxDialingPeers: DEFAULT_MAX_DIALING_PEERS,
|
9034
|
+
failedDialCooldown: DEFAULT_FAILED_DIAL_COOLDOWN_SEC,
|
9035
|
+
dialCooldown: DEFAULT_DIAL_COOLDOWN_SEC,
|
8940
9036
|
...options.config
|
8941
9037
|
};
|
8942
9038
|
this.keepAliveManager = new KeepAliveManager({
|
@@ -8953,7 +9049,8 @@ class ConnectionManager {
|
|
8953
9049
|
});
|
8954
9050
|
this.dialer = new Dialer({
|
8955
9051
|
libp2p: options.libp2p,
|
8956
|
-
shardReader: this.shardReader
|
9052
|
+
shardReader: this.shardReader,
|
9053
|
+
options: this.options
|
8957
9054
|
});
|
8958
9055
|
this.discoveryDialer = new DiscoveryDialer({
|
8959
9056
|
libp2p: options.libp2p,
|
@@ -8972,12 +9069,14 @@ class ConnectionManager {
|
|
8972
9069
|
});
|
8973
9070
|
}
|
8974
9071
|
start() {
|
9072
|
+
this.dialer.start();
|
8975
9073
|
this.networkMonitor.start();
|
8976
9074
|
this.discoveryDialer.start();
|
8977
9075
|
this.keepAliveManager.start();
|
8978
9076
|
this.connectionLimiter.start();
|
8979
9077
|
}
|
8980
9078
|
stop() {
|
9079
|
+
this.dialer.stop();
|
8981
9080
|
this.networkMonitor.stop();
|
8982
9081
|
this.discoveryDialer.stop();
|
8983
9082
|
this.keepAliveManager.stop();
|
@@ -9029,9 +9128,6 @@ class ConnectionManager {
|
|
9029
9128
|
log$1.info(`Found ${result.length} connected peers for codec ${codec}`);
|
9030
9129
|
return result;
|
9031
9130
|
}
|
9032
|
-
isTopicConfigured(pubsubTopic) {
|
9033
|
-
return this.pubsubTopics.includes(pubsubTopic);
|
9034
|
-
}
|
9035
9131
|
async hasShardInfo(peerId) {
|
9036
9132
|
return this.shardReader.hasShardInfo(peerId);
|
9037
9133
|
}
|
@@ -9043,13 +9139,13 @@ class ConnectionManager {
|
|
9043
9139
|
const log = new Logger("metadata");
|
9044
9140
|
const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
9045
9141
|
class Metadata {
|
9046
|
-
|
9142
|
+
clusterId;
|
9047
9143
|
streamManager;
|
9048
9144
|
libp2pComponents;
|
9049
9145
|
handshakesConfirmed = new Map();
|
9050
9146
|
multicodec = MetadataCodec;
|
9051
|
-
constructor(
|
9052
|
-
this.
|
9147
|
+
constructor(clusterId, libp2p) {
|
9148
|
+
this.clusterId = clusterId;
|
9053
9149
|
this.streamManager = new StreamManager(MetadataCodec, libp2p);
|
9054
9150
|
this.libp2pComponents = libp2p;
|
9055
9151
|
void libp2p.registrar.handle(MetadataCodec, (streamData) => {
|
@@ -9060,7 +9156,10 @@ class Metadata {
|
|
9060
9156
|
* Make a metadata query to a peer
|
9061
9157
|
*/
|
9062
9158
|
async query(peerId) {
|
9063
|
-
const request = WakuMetadataRequest.encode(
|
9159
|
+
const request = WakuMetadataRequest.encode({
|
9160
|
+
clusterId: this.clusterId,
|
9161
|
+
shards: [] // Only services node need to provide shards
|
9162
|
+
});
|
9064
9163
|
const peer = await this.libp2pComponents.peerStore.get(peerId);
|
9065
9164
|
if (!peer) {
|
9066
9165
|
return {
|
@@ -9109,7 +9208,10 @@ class Metadata {
|
|
9109
9208
|
async onRequest(streamData) {
|
9110
9209
|
try {
|
9111
9210
|
const { stream, connection } = streamData;
|
9112
|
-
const encodedShardInfo = WakuMetadataResponse.encode(
|
9211
|
+
const encodedShardInfo = WakuMetadataResponse.encode({
|
9212
|
+
clusterId: this.clusterId,
|
9213
|
+
shards: [] // Only service nodes need to provide shards
|
9214
|
+
});
|
9113
9215
|
const encodedResponse = await pipe([encodedShardInfo], encode, stream, decode, async (source) => await all(source));
|
9114
9216
|
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
9115
9217
|
if (error) {
|
@@ -9149,8 +9251,8 @@ class Metadata {
|
|
9149
9251
|
this.handshakesConfirmed.set(peerId.toString(), shardInfo);
|
9150
9252
|
}
|
9151
9253
|
}
|
9152
|
-
function wakuMetadata(
|
9153
|
-
return (components) => new Metadata(
|
9254
|
+
function wakuMetadata(clusterId) {
|
9255
|
+
return (components) => new Metadata(clusterId, components);
|
9154
9256
|
}
|
9155
9257
|
|
9156
9258
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
export { a5 as DecodedMessage, a7 as Decoder, a6 as Encoder, a3 as Version, a2 as createDecoder, o as createEncoder, a4 as proto } from '../../version_0-
|
1
|
+
export { a5 as DecodedMessage, a7 as Decoder, a6 as Encoder, a3 as Version, a2 as createDecoder, o as createEncoder, a4 as proto } from '../../version_0-BHaZD8Qu.js';
|