diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index 19bb25d..239ae12 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -127,9 +127,6 @@ class UDPTracker extends Tracker { } const action = msg.readUInt32BE(0) - let interval - let addrs - let infoHashes debug('UDP response %s, action %s', self.announceUrl, action) switch (action) { case 0: // handshake @@ -149,7 +146,7 @@ class UDPTracker extends Tracker { if (msg.length < 20) return onError(new Error('invalid announce message')) - interval = msg.readUInt32BE(8) + const interval = msg.readUInt32BE(8) if (interval) self.setInterval(interval * 1000) self.client.emit('update', { @@ -158,6 +155,7 @@ class UDPTracker extends Tracker { incomplete: msg.readUInt32BE(12) }) + let addrs try { addrs = compact2string.multi(msg.slice(20)) } catch (err) { @@ -176,7 +174,7 @@ class UDPTracker extends Tracker { if (msg.length < 20 || (msg.length - 8) % 12 !== 0) { return onError(new Error('invalid scrape message')) } - infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0) + const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0) ? opts.infoHash.map(infoHash => { return infoHash.toString('hex') }) : [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ] diff --git a/server.js b/server.js index 9a68544..9d29bef 100644 --- a/server.js +++ b/server.js @@ -749,7 +749,6 @@ Server.Swarm = Swarm function makeUdpPacket (params) { let packet - let scrapeResponse switch (params.action) { case common.ACTIONS.CONNECT: packet = Buffer.concat([ @@ -769,7 +768,7 @@ function makeUdpPacket (params) { ]) break case common.ACTIONS.SCRAPE: - scrapeResponse = [ + const scrapeResponse = [ common.toUInt32(common.ACTIONS.SCRAPE), common.toUInt32(params.transactionId) ]