From 46033ae52eca6e22301bb8ed9566c498d3494711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Sat, 10 Jul 2021 20:27:48 -0500 Subject: fix: modernize code (#2134) * fix: modernize code * standard fix --- lib/peer.js | 16 ++++------------ lib/torrent.js | 7 ++++--- lib/webconn.js | 4 +--- 3 files changed, 9 insertions(+), 18 deletions(-) (limited to 'lib') 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')) } -- cgit v1.2.3