From 6f01633579d6821b0452af259c388e638804b511 Mon Sep 17 00:00:00 2001 From: HDegroote <75906619+HDegroote@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:59:03 +0100 Subject: [PATCH] Bugfix: correctly calculate average RTT (#2) --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 81adc39..67154b1 100644 --- a/index.js +++ b/index.js @@ -375,6 +375,7 @@ class HypercoreStatsSnapshot { this.cores = cores this._totalPeersConns = new Set() + this._totalPeerCoreCombos = 0 this.totalWireSyncReceived = 0 this.totalWireSyncTransmitted = 0 @@ -411,9 +412,9 @@ class HypercoreStatsSnapshot { } get avgRoundTripTimeMs () { - return this.totalPeers === 0 + return this._totalPeerCoreCombos === 0 ? 0 - : this._totalRoundTripTime / this.totalPeers + : this._totalRoundTripTime / this._totalPeerCoreCombos } calculate () { @@ -446,6 +447,7 @@ class HypercoreStatsSnapshot { } for (const peer of core.peers) { + this._totalPeerCoreCombos++ const udxStream = peer.stream.rawStream this.totalInflightBlocks += peer.inflight this._totalPeersConns.add(udxStream)