diff --git a/lib/replicator.js b/lib/replicator.js index 96be4b56..55fd4db6 100644 --- a/lib/replicator.js +++ b/lib/replicator.js @@ -525,6 +525,8 @@ class Peer { } onopen ({ seeks, capability }) { + if (this.replicator.destroyed) return + const expected = caps.replicate(this.stream.isInitiator === false, this.replicator.key, this.stream.handshakeHash) if (b4a.equals(capability, expected) !== true) { // TODO: change this to a rejection instead, less leakage @@ -605,6 +607,8 @@ class Peer { } async onsync ({ fork, length, remoteLength, canUpgrade, uploading, downloading, hasManifest }) { + if (this.replicator.destroyed) return + const lengthChanged = length !== this.remoteLength const sameFork = fork === this.core.tree.fork @@ -669,6 +673,8 @@ class Peer { // Safe to call in the background - never fails async _canUpgrade (remoteLength, remoteFork) { + if (this.replicator.destroyed) return false + if (remoteFork !== this.core.tree.fork) return false if (remoteLength === 0) return true @@ -708,6 +714,8 @@ class Peer { async onrequest (msg) { this.tracer.trace('onrequest', msg) + if (this.replicator.destroyed) return + const size = this.remoteRequests.size this.remoteRequests.set(msg.id, msg) @@ -848,6 +856,8 @@ class Peer { async ondata (data) { this.tracer.trace('ondata', data) + if (this.replicator.destroyed) return + // always allow a fork conflict proof to be sent if (data.request === 0 && data.upgrade && data.upgrade.start === 0) { if (await this.core.checkConflict(data, this)) return