diff options
author | Diego RodrÃguez Baquero <github@diegorbaquero.com> | 2021-07-11 04:27:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-11 04:27:48 +0300 |
commit | 46033ae52eca6e22301bb8ed9566c498d3494711 (patch) | |
tree | 93cf4583fc9471dbe8e0b050c55b643638768f40 /lib | |
parent | feb719d5426df7ad45d00ffadecb931780763134 (diff) |
fix: modernize code (#2134)
* fix: modernize code
* standard fix
Diffstat (limited to 'lib')
-rw-r--r-- | lib/peer.js | 16 | ||||
-rw-r--r-- | lib/torrent.js | 7 | ||||
-rw-r--r-- | lib/webconn.js | 4 |
3 files changed, 9 insertions, 18 deletions
diff --git a/lib/peer.js b/lib/peer.js index 5471773..c7da3ad 100644 --- a/lib/peer.js +++ b/lib/peer.js @@ -45,34 +45,26 @@ exports.createWebRTCPeer = (conn, swarm) => { * listening port of the TCP server. Until the remote peer sends a handshake, we don't * know what swarm the connection is intended for. */ -exports.createTCPIncomingPeer = conn => { - return _createIncomingPeer(conn, 'tcpIncoming') -} +exports.createTCPIncomingPeer = conn => _createIncomingPeer(conn, 'tcpIncoming') /** * Incoming uTP peers start out connected, because the remote peer connected to the * listening port of the uTP server. Until the remote peer sends a handshake, we don't * know what swarm the connection is intended for. */ -exports.createUTPIncomingPeer = conn => { - return _createIncomingPeer(conn, 'utpIncoming') -} +exports.createUTPIncomingPeer = conn => _createIncomingPeer(conn, 'utpIncoming') /** * Outgoing TCP peers start out with just an IP address. At some point (when there is an * available connection), the client can attempt to connect to the address. */ -exports.createTCPOutgoingPeer = (addr, swarm) => { - return _createOutgoingPeer(addr, swarm, 'tcpOutgoing') -} +exports.createTCPOutgoingPeer = (addr, swarm) => _createOutgoingPeer(addr, swarm, 'tcpOutgoing') /** * Outgoing uTP peers start out with just an IP address. At some point (when there is an * available connection), the client can attempt to connect to the address. */ -exports.createUTPOutgoingPeer = (addr, swarm) => { - return _createOutgoingPeer(addr, swarm, 'utpOutgoing') -} +exports.createUTPOutgoingPeer = (addr, swarm) => _createOutgoingPeer(addr, swarm, 'utpOutgoing') const _createIncomingPeer = (conn, type) => { const addr = `${conn.remoteAddress}:${conn.remotePort}` diff --git a/lib/torrent.js b/lib/torrent.js index f60d459..62fa016 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1269,7 +1269,7 @@ class Torrent extends EventEmitter { const self = this if (typeof window !== 'undefined' && typeof window.requestIdleCallback === 'function') { - window.requestIdleCallback(function () { self._updateWire(wire) }, { timeout: 250 }) + window.requestIdleCallback(() => { self._updateWire(wire) }, { timeout: 250 }) } else { self._updateWire(wire) } @@ -1677,8 +1677,8 @@ class Torrent extends EventEmitter { // is the torrent done? (if all current selections are satisfied, or there are // no selections, then torrent is done) let done = true - for (let i = 0; i < this._selections.length; i++) { - const selection = this._selections[i] + + for (const selection of this._selections) { for (let piece = selection.from; piece <= selection.to; piece++) { if (!this.bitfield.get(piece)) { done = false @@ -1687,6 +1687,7 @@ class Torrent extends EventEmitter { } if (!done) break } + if (!this.done && done) { this.done = true this._debug(`torrent done: ${this.infoHash}`) diff --git a/lib/webconn.js b/lib/webconn.js index c957fbb..22298b3 100644 --- a/lib/webconn.js +++ b/lib/webconn.js @@ -92,9 +92,7 @@ class WebConn extends Wire { end: rangeEnd }] } else { - const requestedFiles = files.filter(file => { - return file.offset <= rangeEnd && (file.offset + file.length) > rangeStart - }) + const requestedFiles = files.filter(file => file.offset <= rangeEnd && (file.offset + file.length) > rangeStart) if (requestedFiles.length < 1) { return cb(new Error('Could not find file corresponding to web seed range request')) } |