diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-01-27 05:04:18 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-01-27 05:04:18 +0300 |
commit | bb07d4db0e213611899d834b022e00936172557e (patch) | |
tree | 898c2ab31961ddfa2bc0c950e5bd44b4e1522529 /lib/torrent.js | |
parent | a3fdd9aafeb70f1fea545879131523b2906c3979 (diff) |
JavaScript Standard Style
Diffstat (limited to 'lib/torrent.js')
-rw-r--r-- | lib/torrent.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 9127eba..f3ec093 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -75,7 +75,6 @@ function Torrent (torrentId, opts) { var parsedTorrent = (torrentId && torrentId.parsedTorrent) || parseTorrent(torrentId) if (parsedTorrent && parsedTorrent.infoHash) { onTorrentId(parsedTorrent) - } else if (typeof get === 'function' && /^https?:/.test(torrentId)) { // http or https url to torrent file get.concat({ @@ -86,14 +85,12 @@ function Torrent (torrentId, opts) { return self.emit('error', new Error('error downloading torrent: ' + err.message)) onTorrentId(data) }) - } else if (typeof fs.readFile === 'function') { // assume it's a filesystem path fs.readFile(torrentId, function (err, torrent) { if (err) return self.emit('error', new Error('invalid torrent id')) onTorrentId(torrent) }) - } else throw new Error('invalid torrent id') function onTorrentId (torrentId) { @@ -277,7 +274,7 @@ Torrent.prototype._onMetadata = function (metadata) { numPieces += 1 self.emit('verifying', { percentDone: 100 * numPieces / self.storage.pieces.length, - percentVerified: 100 * numVerified / self.storage.pieces.length, + percentVerified: 100 * numVerified / self.storage.pieces.length }) if (!err && buffer) { @@ -432,7 +429,7 @@ Torrent.prototype._onWire = function (wire) { // use ut_pex extension if (typeof ut_pex === 'function') wire.use(ut_pex()) - //wire.ut_pex.start() // TODO two-way communication + // 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) @@ -481,7 +478,8 @@ Torrent.prototype._onWireWithMetadata = function (wire) { function onChokeTimeout () { if (self._destroyed || wire._destroyed) return - if (self.swarm.numQueued > 2 * (self.swarm.numConns - self.swarm.numPeers) && wire.amInterested) { + if (self.swarm.numQueued > 2 * (self.swarm.numConns - self.swarm.numPeers) && + wire.amInterested) { wire.destroy() } else { timeoutId = setTimeout(onChokeTimeout, timeoutMs) @@ -963,12 +961,18 @@ Torrent.prototype._request = function (wire, index, hotswap) { if (r[i] === wire) r[i] = null if (err) { - debug('error getting piece ' + index + '(offset: ' + block.offset + ' length: ' + block.length + ') from ' + wire.remoteAddress + ' ' + err.message) + debug( + 'error getting piece %s (offset: %s length: %s) from %s: %s', + index, block.offset, block.length, wire.remoteAddress, err.message + ) self.storage.cancelBlock(index, block.offset) process.nextTick(self._update.bind(self)) return false } else { - // debug('got piece ' + index + '(offset: ' + block.offset + ' length: ' + block.length + ') from ' + wire.remoteAddress) + debug( + 'got piece %s (offset: %s length: %s) from %s', + index, block.offset, block.length, wire.remoteAddress + ) self.storage.writeBlock(index, block.offset, buffer, function (err) { if (err) { debug('error writing block') @@ -993,7 +997,7 @@ Torrent.prototype.createServer = function (opts) { } function getPipelineLength (wire, duration) { - return Math.ceil(2 + duration * wire.downloadSpeed() / Storage.BLOCK_LENGTH); + return Math.ceil(2 + duration * wire.downloadSpeed() / Storage.BLOCK_LENGTH) } /** |