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 | |
parent | 2a3c90fb20942ab7e6eee709508d3564b349cc01 (diff) |
style: always use braces
Diffstat (limited to 'lib')
-rw-r--r-- | lib/file-stream.js | 3 | ||||
-rw-r--r-- | lib/media-stream.js | 3 | ||||
-rw-r--r-- | lib/server.js | 3 | ||||
-rw-r--r-- | lib/torrent.js | 60 |
4 files changed, 35 insertions, 34 deletions
diff --git a/lib/file-stream.js b/lib/file-stream.js index 231b614..5ea5bc2 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -58,8 +58,9 @@ FileStream.prototype.notify = function () { var self = this if (!self._reading || self._missing === 0) return - if (!self._storage.bitfield.get(self._piece)) + if (!self._storage.bitfield.get(self._piece)) { return self._storage.emit('critical', self._piece, self._piece + self._criticalLength) + } if (self._notifying) return self._notifying = true diff --git a/lib/media-stream.js b/lib/media-stream.js index 01f7d92..c99e408 100644 --- a/lib/media-stream.js +++ b/lib/media-stream.js @@ -53,8 +53,9 @@ MediaStream.prototype._write = function (chunk, encoding, cb) { return } - if (self._sourceBuffer.updating) + if (self._sourceBuffer.updating) { return cb(new Error('Cannot append buffer while source buffer updating')) + } self._sourceBuffer.appendBuffer(chunk) debug('appendBuffer %s', chunk.length) diff --git a/lib/server.js b/lib/server.js index 9b05ae9..6490e70 100644 --- a/lib/server.js +++ b/lib/server.js @@ -28,8 +28,9 @@ module.exports = function Server (torrent, opts) { return res.end() } - if (req.headers.origin) + if (req.headers.origin) { res.setHeader('Access-Control-Allow-Origin', req.headers.origin) + } var pathname = url.parse(req.url).pathname if (pathname === '/favicon.ico') return res.end() 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] |