Use blocks with brackets

This commit is contained in:
Justin Kalland 2018-12-20 12:59:53 -07:00
parent bc861ef10a
commit dc79834f77
2 changed files with 18 additions and 13 deletions

View File

@ -129,7 +129,7 @@ class UDPTracker extends Tracker {
const action = msg.readUInt32BE(0)
debug('UDP response %s, action %s', self.announceUrl, action)
switch (action) {
case 0: // handshake
case 0: { // handshake
// Note: no check for `self.destroyed` so that pending messages to the
// tracker can still be sent/received even after destroy() is called
@ -139,8 +139,8 @@ class UDPTracker extends Tracker {
else announce(msg.slice(8, 16), opts)
break
case 1: // announce
}
case 1: { // announce
cleanup()
if (self.destroyed) return
@ -166,8 +166,8 @@ class UDPTracker extends Tracker {
})
break
case 2: // scrape
}
case 2: { // scrape
cleanup()
if (self.destroyed) return
@ -189,8 +189,8 @@ class UDPTracker extends Tracker {
}
break
case 3: // error
}
case 3: { // error
cleanup()
if (self.destroyed) return
@ -198,12 +198,13 @@ class UDPTracker extends Tracker {
self.client.emit('warning', new Error(msg.slice(8).toString()))
break
default:
}
default: {
onError(new Error('tracker sent invalid action'))
break
}
}
}
function send (message) {
if (!parsedUrl.port) {

View File

@ -750,14 +750,15 @@ Server.Swarm = Swarm
function makeUdpPacket (params) {
let packet
switch (params.action) {
case common.ACTIONS.CONNECT:
case common.ACTIONS.CONNECT: {
packet = Buffer.concat([
common.toUInt32(common.ACTIONS.CONNECT),
common.toUInt32(params.transactionId),
params.connectionId
])
break
case common.ACTIONS.ANNOUNCE:
}
case common.ACTIONS.ANNOUNCE: {
packet = Buffer.concat([
common.toUInt32(common.ACTIONS.ANNOUNCE),
common.toUInt32(params.transactionId),
@ -767,7 +768,8 @@ function makeUdpPacket (params) {
params.peers
])
break
case common.ACTIONS.SCRAPE:
}
case common.ACTIONS.SCRAPE: {
const scrapeResponse = [
common.toUInt32(common.ACTIONS.SCRAPE),
common.toUInt32(params.transactionId)
@ -782,13 +784,15 @@ function makeUdpPacket (params) {
}
packet = Buffer.concat(scrapeResponse)
break
case common.ACTIONS.ERROR:
}
case common.ACTIONS.ERROR: {
packet = Buffer.concat([
common.toUInt32(common.ACTIONS.ERROR),
common.toUInt32(params.transactionId || 0),
Buffer.from(String(params['failure reason']))
])
break
}
default:
throw new Error(`Action not implemented: ${params.action}`)
}