diff options
Diffstat (limited to 'lib/torrent.js')
-rw-r--r-- | lib/torrent.js | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 0f6b891..ab2dcda 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -587,9 +587,14 @@ Torrent.prototype._verifyPieces = function () { parallelLimit(self.pieces.map(function (_, index) { return function (cb) { if (self.destroyed) return cb(new Error('torrent is destroyed')) + self.store.get(index, function (err, buf) { + if (self.destroyed) return cb(new Error('torrent is destroyed')) + if (err) return process.nextTick(cb, null) // ignore error sha1(buf, function (hash) { + if (self.destroyed) return cb(new Error('torrent is destroyed')) + if (hash === self._hashes[index]) { if (!self.pieces[index]) return self._debug('piece verified %s', index) @@ -1523,6 +1528,8 @@ Torrent.prototype._request = function (wire, index, hotswap) { // TODO: might need to set self.pieces[index] = null here since sha1 is async sha1(buf, function (hash) { + if (self.destroyed) return + if (hash === self._hashes[index]) { if (!self.pieces[index]) return self._debug('piece verified %s', index) |