diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-03-07 04:54:26 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-03-07 04:54:26 +0300 |
commit | 7ba50a46f79cc778727a047e121bfdcbb16fd50e (patch) | |
tree | ac7382c8570d058265b208db02e29d4130ef93a2 /lib/torrent.js | |
parent | 2a3c90fb20942ab7e6eee709508d3564b349cc01 (diff) |
style: always use braces
Diffstat (limited to 'lib/torrent.js')
-rw-r--r-- | lib/torrent.js | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 9b7dd34..b37cc51 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -257,8 +257,7 @@ Torrent.prototype._onMetadata = function (metadata) { }) self.storage.on('done', function () { - if (self.discovery.tracker) - self.discovery.tracker.complete() + if (self.discovery.tracker) self.discovery.tracker.complete() debug('torrent ' + self.infoHash + ' done') self.emit('done') @@ -327,15 +326,9 @@ Torrent.prototype.destroy = function (cb) { clearInterval(self._rechokeIntervalId) var tasks = [] - if (self.swarm) tasks.push(function (cb) { - self.swarm.destroy(cb) - }) - if (self.discovery) tasks.push(function (cb) { - self.discovery.stop(cb) - }) - if (self.storage) tasks.push(function (cb) { - self.storage.close(cb) - }) + if (self.swarm) tasks.push(function (cb) { self.swarm.destroy(cb) }) + if (self.discovery) tasks.push(function (cb) { self.discovery.stop(cb) }) + if (self.storage) tasks.push(function (cb) { self.storage.close(cb) }) parallel(tasks, cb) } @@ -370,8 +363,9 @@ Torrent.prototype.addPeer = function (peer) { */ Torrent.prototype.select = function (start, end, priority, notify) { var self = this - if (start > end || start < 0 || end >= self.storage.pieces.length) + if (start > end || start < 0 || end >= self.storage.pieces.length) { throw new Error('invalid selection ', start, ':', end) + } priority = Number(priority) || 0 debug('select %s-%s (priority %s)', start, end, priority) @@ -446,19 +440,21 @@ Torrent.prototype._onWire = function (wire) { } // use ut_pex extension - if (typeof ut_pex === 'function') wire.use(ut_pex()) + if (typeof ut_pex === 'function') { + wire.use(ut_pex()) - // wire.ut_pex.start() // TODO two-way communication - if (wire.ut_pex) wire.ut_pex.on('peer', function (peer) { - debug('got peer via ut_pex ' + peer) - self.addPeer(peer) - }) + // wire.ut_pex.start() // TODO two-way communication + wire.ut_pex.on('peer', function (peer) { + debug('got peer via ut_pex ' + peer) + self.addPeer(peer) + }) - if (wire.ut_pex) wire.ut_pex.on('dropped', function (peer) { - // the remote peer believes a given peer has been dropped from the swarm. - // if we're not currently connected to it, then remove it from the swarm's queue. - if (!(peer in self.swarm._peers)) self.swarm.removePeer(peer) - }) + wire.ut_pex.on('dropped', function (peer) { + // the remote peer believes a given peer has been dropped from the swarm. + // if we're not currently connected to it, then remove it from the swarm's queue. + if (!(peer in self.swarm._peers)) self.swarm.removePeer(peer) + }) + } // Send KEEP-ALIVE (every 60s) so peers will not disconnect the wire wire.setKeepAlive(true) @@ -827,10 +823,8 @@ Torrent.prototype._updateWire = function (wire) { Torrent.prototype._rechoke = function () { var self = this - if (self._rechokeOptimisticTime > 0) - self._rechokeOptimisticTime -= 1 - else - self._rechokeOptimisticWire = null + if (self._rechokeOptimisticTime > 0) self._rechokeOptimisticTime -= 1 + else self._rechokeOptimisticWire = null var peers = [] @@ -877,16 +871,19 @@ Torrent.prototype._rechoke = function () { function rechokeSort (peerA, peerB) { // Prefer higher download speed - if (peerA.downloadSpeed !== peerB.downloadSpeed) + if (peerA.downloadSpeed !== peerB.downloadSpeed) { return peerB.downloadSpeed - peerA.downloadSpeed + } // Prefer higher upload speed - if (peerA.uploadSpeed !== peerB.uploadSpeed) + if (peerA.uploadSpeed !== peerB.uploadSpeed) { return peerB.uploadSpeed - peerA.uploadSpeed + } // Prefer unchoked - if (peerA.wire.amChoking !== peerB.wire.amChoking) + if (peerA.wire.amChoking !== peerB.wire.amChoking) { return peerA.wire.amChoking ? 1 : -1 + } // Random order return peerA.salt - peerB.salt @@ -957,8 +954,9 @@ Torrent.prototype._request = function (wire, index, hotswap) { var endGame = (wire.requests.length === 0 && self.storage.numMissing < 30) var block = self.storage.reserveBlock(index, endGame) - if (!block && !endGame && hotswap && self._hotswap(wire, index)) + if (!block && !endGame && hotswap && self._hotswap(wire, index)) { block = self.storage.reserveBlock(index, false) + } if (!block) return false var r = self._reservations[index] |