From 9fc68b67f3f811230c4d353e5a13485ccf651c9f Mon Sep 17 00:00:00 2001 From: Billie Hilton <587740+billiegoose@users.noreply.github.com> Date: Wed, 5 Jun 2024 04:04:38 -0400 Subject: [PATCH] count the number of connection events (#173) * count the number of connection events * PR feedback --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 2b56c73..036ec8a 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,7 @@ module.exports = class Hyperswarm extends EventEmitter { this.peers = new Map() this.explicitPeers = new Set() this.listening = null + this.stats = { updates: 0 } this._discovery = new Map() this._timer = new RetryTimer(this._requeue.bind(this), { @@ -74,6 +75,7 @@ module.exports = class Hyperswarm extends EventEmitter { this._firewall = firewall this.dht.on('network-change', this._handleNetworkChange.bind(this)) + this.on('update', this._handleUpdate) } _maybeRelayConnection (force) { @@ -331,6 +333,10 @@ module.exports = class Hyperswarm extends EventEmitter { return peerInfo } + _handleUpdate () { + this.stats.updates++ + } + _maybeDeletePeer (peerInfo) { if (!peerInfo.shouldGC()) return