Skip to content

Commit

Permalink
Bugfix: correctly calculate average RTT (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote authored Nov 15, 2024
1 parent b11ec82 commit 6f01633
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class HypercoreStatsSnapshot {
this.cores = cores

this._totalPeersConns = new Set()
this._totalPeerCoreCombos = 0

this.totalWireSyncReceived = 0
this.totalWireSyncTransmitted = 0
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6f01633

Please sign in to comment.