hyperswarm
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -73,2 +73,3 @@ const { EventEmitter } = require('events') | ||
_enqueue (peerInfo) { | ||
if (peerInfo.queued) return | ||
peerInfo.queued = true | ||
@@ -83,3 +84,3 @@ peerInfo._flushTick = this._flushTick | ||
for (const peerInfo of batch) { | ||
if ((peerInfo._updatePriority() === false) || this._allConnections.has(peerInfo.publicKey)) continue | ||
if ((peerInfo._updatePriority() === false) || this._allConnections.has(peerInfo.publicKey) || peerInfo.queued) continue | ||
peerInfo.queued = true | ||
@@ -124,3 +125,3 @@ peerInfo._flushTick = this._flushTick | ||
_shouldRequeue (peerInfo) { | ||
if (this.explicitPeers.has(peerInfo)) return true | ||
if (peerInfo.explicit) return true | ||
for (const topic of peerInfo.topics) { | ||
@@ -353,2 +354,3 @@ if (this._discovery.has(b4a.toString(topic, 'hex')) && !this.destroyed) { | ||
if (!this.explicitPeers.has(peerInfo)) { | ||
peerInfo.explicit = true | ||
this.explicitPeers.add(peerInfo) | ||
@@ -366,2 +368,3 @@ } | ||
const peerInfo = this.peers.get(keyString) | ||
peerInfo.explicit = false | ||
this.explicitPeers.delete(peerInfo) | ||
@@ -368,0 +371,0 @@ } |
@@ -21,2 +21,3 @@ const { EventEmitter } = require('events') | ||
this.tried = false | ||
this.explicit = false | ||
@@ -79,2 +80,3 @@ // Set by the Swarm | ||
_updatePriority () { | ||
if (this.explicit && this.attempts > 3) this._deprioritize() | ||
if (this.banned || this.queued || this.attempts > 3) return false | ||
@@ -81,0 +83,0 @@ this.priority = this._getPriority() |
@@ -5,7 +5,8 @@ const BulkTimer = require('./bulk-timer') | ||
const BACKOFF_S = 1000 + Math.round(BACKOFF_JITTER * Math.random()) | ||
const BACKOFF_M = 5000 + Math.round(BACKOFF_JITTER * Math.random()) | ||
const BACKOFF_L = 15000 + Math.round(BACKOFF_JITTER * Math.random()) | ||
const BACKOFF_M = 5000 + Math.round(2 * BACKOFF_JITTER * Math.random()) | ||
const BACKOFF_L = 15000 + Math.round(4 * BACKOFF_JITTER * Math.random()) | ||
const BACKOFF_X = 1000 * 60 * 10 + Math.round(240 * BACKOFF_JITTER * Math.random()) | ||
module.exports = class RetryTimer { | ||
constructor (push, { backoffs = [BACKOFF_S, BACKOFF_M, BACKOFF_L], jitter = BACKOFF_JITTER } = {}) { | ||
constructor (push, { backoffs = [BACKOFF_S, BACKOFF_M, BACKOFF_L, BACKOFF_X], jitter = BACKOFF_JITTER } = {}) { | ||
this.jitter = jitter | ||
@@ -17,6 +18,12 @@ this.backoffs = backoffs | ||
this._lTimer = new BulkTimer(backoffs[2] + Math.round(jitter * Math.random()), push) | ||
this._xTimer = new BulkTimer(backoffs[3] + Math.round(jitter * Math.random()), push) | ||
} | ||
_selectRetryTimer (peerInfo) { | ||
if (peerInfo.banned || !peerInfo.reconnecting || peerInfo.attempts > 3) return null | ||
if (peerInfo.banned || !peerInfo.reconnecting) return null | ||
if (peerInfo.attempts > 3) { | ||
return peerInfo.explicit ? this._xTimer : null | ||
} | ||
if (peerInfo.attempts === 0) return this._sTimer | ||
@@ -36,2 +43,4 @@ if (peerInfo.proven) { | ||
} | ||
return null | ||
} | ||
@@ -49,3 +58,4 @@ | ||
this._lTimer.destroy() | ||
this._xTimer.destroy() | ||
} | ||
} |
{ | ||
"name": "hyperswarm", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "A distributed networking stack for connecting peers", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
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
57987
1425