Skip to content

Commit bc861ef

Browse files
author
Justin Kalland
committed
Revert "Remove declarations from inside switch statements"
This reverts commit d1b9047.
1 parent d1b9047 commit bc861ef

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

lib/client/udp-tracker.js

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

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

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

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

155152
self.client.emit('update', {
@@ -158,6 +155,7 @@ class UDPTracker extends Tracker {
158155
incomplete: msg.readUInt32BE(12)
159156
})
160157

158+
let addrs
161159
try {
162160
addrs = compact2string.multi(msg.slice(20))
163161
} catch (err) {
@@ -176,7 +174,7 @@ class UDPTracker extends Tracker {
176174
if (msg.length < 20 || (msg.length - 8) % 12 !== 0) {
177175
return onError(new Error('invalid scrape message'))
178176
}
179-
infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
177+
const infoHashes = (Array.isArray(opts.infoHash) && opts.infoHash.length > 0)
180178
? opts.infoHash.map(infoHash => { return infoHash.toString('hex') })
181179
: [ (opts.infoHash && opts.infoHash.toString('hex')) || self.client.infoHash ]
182180

server.js

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

750750
function makeUdpPacket (params) {
751751
let packet
752-
let scrapeResponse
753752
switch (params.action) {
754753
case common.ACTIONS.CONNECT:
755754
packet = Buffer.concat([
@@ -769,7 +768,7 @@ function makeUdpPacket (params) {
769768
])
770769
break
771770
case common.ACTIONS.SCRAPE:
772-
scrapeResponse = [
771+
const scrapeResponse = [
773772
common.toUInt32(common.ACTIONS.SCRAPE),
774773
common.toUInt32(params.transactionId)
775774
]

0 commit comments

Comments
 (0)