hyperswarm
Advanced tools
Comparing version 4.7.15 to 4.8.0
34
index.js
@@ -59,3 +59,17 @@ const { EventEmitter } = require('events') | ||
this.listening = null | ||
this.stats = { updates: 0 } | ||
this.stats = { | ||
updates: 0, | ||
connects: { | ||
client: { | ||
opened: 0, | ||
closed: 0, | ||
attempted: 0 | ||
}, | ||
server: { | ||
// Note: there is no notion of 'attempts' for server connections | ||
opened: 0, | ||
closed: 0 | ||
} | ||
} | ||
} | ||
@@ -173,2 +187,4 @@ this._discovery = new Map() | ||
this.stats.connects.client.attempted++ | ||
this.connecting++ | ||
@@ -180,2 +196,4 @@ this._clientConnections++ | ||
opened = true | ||
this.stats.connects.client.opened++ | ||
this._connectDone() | ||
@@ -200,2 +218,4 @@ this.connections.add(conn) | ||
if (!opened) this._connectDone() | ||
this.stats.connects.client.closed++ | ||
this.connections.delete(conn) | ||
@@ -281,5 +301,9 @@ this._allConnections.delete(conn) | ||
if (existing) { | ||
// If both connections are from the same peer, | ||
// - pick the new one if the existing stream is already established (has sent and received bytes), | ||
// because the other client must have lost that connection and be reconnecting | ||
// - otherwise, pick the one thats expected to initiate in a tie break | ||
const existingIsOutdated = existing.rawBytesRead > 0 && existing.rawBytesWritten > 0 | ||
const expectedInitiator = b4a.compare(conn.publicKey, conn.remotePublicKey) > 0 | ||
// if both connections are from the same peer, pick the one thats expected to initiate in a tie break | ||
const keepNew = expectedInitiator === conn.isInitiator | ||
const keepNew = existingIsOutdated || (expectedInitiator === conn.isInitiator) | ||
@@ -299,2 +323,5 @@ if (keepNew === false) { | ||
// When reaching here, the connection will always be 'opened' next tick | ||
this.stats.connects.server.opened++ | ||
const peerInfo = this._upsertPeer(conn.remotePublicKey, null) | ||
@@ -310,2 +337,3 @@ | ||
this._serverConnections-- | ||
this.stats.connects.server.closed++ | ||
@@ -312,0 +340,0 @@ this._maybeDeletePeer(peerInfo) |
{ | ||
"name": "hyperswarm", | ||
"version": "4.7.15", | ||
"version": "4.8.0", | ||
"description": "A distributed networking stack for connecting peers", | ||
@@ -5,0 +5,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39165
891