hyperswarm
Advanced tools
Comparing version 4.7.4 to 4.7.5
10
index.js
@@ -477,4 +477,8 @@ const { EventEmitter } = require('events') | ||
const promises = [] | ||
promises.push(this.server.suspend()) | ||
for (const discovery of this._discovery.values()) { | ||
discovery.suspend() | ||
promises.push(discovery.suspend()) | ||
} | ||
@@ -486,4 +490,6 @@ | ||
await this.dht.suspend() | ||
promises.push(this.dht.suspend()) | ||
this.suspended = true | ||
await Promise.allSettled(promises) | ||
} | ||
@@ -490,0 +496,0 @@ |
const safetyCatch = require('safety-catch') | ||
const b4a = require('b4a') | ||
@@ -59,5 +60,10 @@ const REFRESH_INTERVAL = 1000 * 60 * 10 // 10 min | ||
_isActive () { | ||
return !this.destroyed && !this.suspended | ||
} | ||
// TODO: Allow announce to be an argument to this | ||
// TODO: Maybe announce should be a setter? | ||
async _refresh () { | ||
if (this.suspended) return | ||
const clock = ++this._refreshes | ||
@@ -68,3 +74,3 @@ | ||
this._wait = null | ||
if (clock !== this._refreshes) return | ||
if (clock !== this._refreshes || !this._isActive()) return | ||
} | ||
@@ -83,3 +89,3 @@ | ||
// if a parallel refresh is happening, yield to the new one | ||
if (clock !== this._refreshes) return | ||
if (clock !== this._refreshes || !this._isActive()) return | ||
this._needsUnannounce = true | ||
@@ -97,3 +103,3 @@ } | ||
for await (const data of this._activeQuery) { | ||
if (!this.isClient) continue | ||
if (!this.isClient || !this._isActive()) continue | ||
for (const peer of data.peers) { | ||
@@ -103,6 +109,8 @@ this._onpeer(peer, data) | ||
} | ||
} catch (err) { | ||
if (this._isActive()) throw err | ||
} finally { | ||
if (this._activeQuery === query) { | ||
this._activeQuery = null | ||
if (!this.destroyed) this._refreshLater(false) | ||
if (!this.destroyed && !this.suspended) this._refreshLater(false) | ||
} | ||
@@ -176,6 +184,3 @@ } | ||
async _destroy () { | ||
if (this.destroyed) return | ||
this.destroyed = true | ||
async _abort () { | ||
if (this._wait) await this._wait | ||
@@ -192,2 +197,4 @@ | ||
const nodes = this._closestNodes | ||
if (this._currentRefresh) { | ||
@@ -201,4 +208,15 @@ try { | ||
if (this._isActive()) return | ||
if (this._closestNodes !== nodes) { | ||
for (const node of this._closestNodes) { | ||
for (const n of nodes) { | ||
if (!n.id || !node.id || b4a.equals(n.id, node.id)) continue | ||
nodes.push(n) | ||
} | ||
} | ||
} | ||
if (this._needsUnannounce) { | ||
await this.swarm.dht.unannounce(this.topic, this.swarm.keyPair) | ||
await this.swarm.dht.unannounce(this.topic, this.swarm.keyPair, { closestNodes: nodes, onlyClosestNodes: true }) | ||
this._needsUnannounce = false | ||
@@ -208,10 +226,12 @@ } | ||
suspend () { | ||
_destroy () { | ||
if (this.destroyed) return | ||
this.destroyed = true | ||
return this._abort() | ||
} | ||
async suspend () { | ||
if (this.suspended) return | ||
this.suspended = true | ||
if (this._timer) { | ||
clearTimeout(this._timer) | ||
this._timer = null | ||
} | ||
return this._abort() | ||
} | ||
@@ -218,0 +238,0 @@ |
{ | ||
"name": "hyperswarm", | ||
"version": "4.7.4", | ||
"version": "4.7.5", | ||
"description": "A distributed networking stack for connecting peers", | ||
@@ -12,3 +12,3 @@ "files": [ | ||
"events": "^3.3.0", | ||
"hyperdht": "^6.7.0", | ||
"hyperdht": "^6.10.0", | ||
"safety-catch": "^1.0.2", | ||
@@ -15,0 +15,0 @@ "shuffled-priority-queue": "^2.1.0" |
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
37703
851
Updatedhyperdht@^6.10.0