Skip to content

Commit d1b9047

Browse files
author
Justin Kalland
committed
Remove declarations from inside switch statements
1 parent e21a380 commit d1b9047

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/client/udp-tracker.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ class UDPTracker extends Tracker {
127127
}
128128

129129
const action = msg.readUInt32BE(0)
130+
let interval
131+
let addrs
132+
let infoHashes
130133
debug('UDP response %s, action %s', self.announceUrl, action)
131134
switch (action) {
132135
case 0: // handshake
@@ -146,7 +149,7 @@ class UDPTracker extends Tracker {
146149

147150
if (msg.length < 20) return onError(new Error('invalid announce message'))
148151

149-
const interval = msg.readUInt32BE(8)
152+
interval = msg.readUInt32BE(8)
150153
if (interval) self.setInterval(interval * 1000)
151154

152155
self.client.emit('update', {
@@ -155,7 +158,6 @@ class UDPTracker extends Tracker {
155158
incomplete: msg.readUInt32BE(12)
156159
})
157160

158-
let addrs
159161
try {
160162
addrs = compact2string.multi(msg.slice(20))
161163
} catch (err) {
@@ -174,7 +176,7 @@ class UDPTracker extends Tracker {
174176
if (msg.length < 20 || (msg.length - 8) % 12 !== 0) {
175177
return onError(new Error('invalid scrape message'))
176178
}
177-
const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
179+
infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
178180
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') })
179181
: [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ]
180182

server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ Server.Swarm = Swarm
749749

750750
function makeUdpPacket (params) {
751751
let packet
752+
let scrapeResponse
752753
switch (params.action) {
753754
case common.ACTIONS.CONNECT:
754755
packet = Buffer.concat([
@@ -768,7 +769,7 @@ function makeUdpPacket (params) {
768769
])
769770
break
770771
case common.ACTIONS.SCRAPE:
771-
const scrapeResponse = [
772+
scrapeResponse = [
772773
common.toUInt32(common.ACTIONS.SCRAPE),
773774
common.toUInt32(params.transactionId)
774775
]

0 commit comments

Comments
 (0)