diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-04-06 07:20:44 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-04-06 07:20:44 +0300 |
commit | f2ea073b5691a6a213868142cf4481fe1b9ea850 (patch) | |
tree | ca9161243b88606ec5df6e5a789b582b5f5ac324 /lib | |
parent | 00da34d0b80fd0a2b5ad9c07e334fb52de6a8e7b (diff) |
do not request pieces until store is ready
Fixes regression introduced in #715
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 7f583c4..0e83e56 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -251,6 +251,11 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) { self._onSwarmListening() }) + self._rechokeIntervalId = setInterval(function () { + self._rechoke() + }, RECHOKE_INTERVAL) + if (self._rechokeIntervalId.unref) self._rechokeIntervalId.unref() + self.emit('infoHash', self.infoHash) } @@ -496,15 +501,14 @@ Torrent.prototype._onStore = function () { // start off selecting the entire torrent with low priority self.select(0, self.pieces.length - 1, false) - self._rechokeIntervalId = setInterval(function () { - self._rechoke() - }, RECHOKE_INTERVAL) - if (self._rechokeIntervalId.unref) self._rechokeIntervalId.unref() - self.ready = true self.emit('ready') + // Files may start out done if the file was already in the store self._checkDone() + + // In case any selections were made before torrent was ready + self._updateSelections() } /** @@ -518,10 +522,7 @@ Torrent.prototype.destroy = function (cb) { self.client.remove(self) - if (self._rechokeIntervalId) { - clearInterval(self._rechokeIntervalId) - self._rechokeIntervalId = null - } + clearInterval(self._rechokeIntervalId) var tasks = [] @@ -849,13 +850,7 @@ Torrent.prototype._onWireWithMetadata = function (wire) { */ Torrent.prototype._updateSelections = function () { var self = this - if (!self.swarm || self.destroyed) return - if (!self.metadata) { - self.once('metadata', function () { - self._updateSelections() - }) - return - } + if (!self.ready || self.destroyed) return process.nextTick(function () { self._gcSelections() @@ -1080,6 +1075,7 @@ Torrent.prototype._updateWire = function (wire) { */ Torrent.prototype._rechoke = function () { var self = this + if (!self.ready) return if (self._rechokeOptimisticTime > 0) self._rechokeOptimisticTime -= 1 else self._rechokeOptimisticWire = null |