Remove declarations from inside switch statements

This commit is contained in:
Justin Kalland 2018-12-20 12:36:54 -07:00
parent e21a3809f7
commit d1b9047c03
2 changed files with 7 additions and 4 deletions

View File

@ -127,6 +127,9 @@ class UDPTracker extends Tracker {
} }
const action = msg.readUInt32BE(0) const action = msg.readUInt32BE(0)
let interval
let addrs
let infoHashes
debug('UDP response %s, action %s', self.announceUrl, action) debug('UDP response %s, action %s', self.announceUrl, action)
switch (action) { switch (action) {
case 0: // handshake case 0: // handshake
@ -146,7 +149,7 @@ class UDPTracker extends Tracker {
if (msg.length < 20) return onError(new Error('invalid announce message')) if (msg.length < 20) return onError(new Error('invalid announce message'))
const interval = msg.readUInt32BE(8) interval = msg.readUInt32BE(8)
if (interval) self.setInterval(interval * 1000) if (interval) self.setInterval(interval * 1000)
self.client.emit('update', { self.client.emit('update', {
@ -155,7 +158,6 @@ class UDPTracker extends Tracker {
incomplete: msg.readUInt32BE(12) incomplete: msg.readUInt32BE(12)
}) })
let addrs
try { try {
addrs = compact2string.multi(msg.slice(20)) addrs = compact2string.multi(msg.slice(20))
} catch (err) { } catch (err) {
@ -174,7 +176,7 @@ class UDPTracker extends Tracker {
if (msg.length < 20 || (msg.length - 8) % 12 !== 0) { if (msg.length < 20 || (msg.length - 8) % 12 !== 0) {
return onError(new Error('invalid scrape message')) return onError(new Error('invalid scrape message'))
} }
const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0) infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') }) ? opts.infoHash.map(infoHash => { return infoHash.toString('hex') })
: [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ] : [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ]

View File

@ -749,6 +749,7 @@ Server.Swarm = Swarm
function makeUdpPacket (params) { function makeUdpPacket (params) {
let packet let packet
let scrapeResponse
switch (params.action) { switch (params.action) {
case common.ACTIONS.CONNECT: case common.ACTIONS.CONNECT:
packet = Buffer.concat([ packet = Buffer.concat([
@ -768,7 +769,7 @@ function makeUdpPacket (params) {
]) ])
break break
case common.ACTIONS.SCRAPE: case common.ACTIONS.SCRAPE:
const scrapeResponse = [ scrapeResponse = [
common.toUInt32(common.ACTIONS.SCRAPE), common.toUInt32(common.ACTIONS.SCRAPE),
common.toUInt32(params.transactionId) common.toUInt32(params.transactionId)
] ]