mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11:36 +00:00
Use blocks with brackets
This commit is contained in:
parent
bc861ef10a
commit
dc79834f77
@ -129,7 +129,7 @@ class UDPTracker extends Tracker {
|
|||||||
const action = msg.readUInt32BE(0)
|
const action = msg.readUInt32BE(0)
|
||||||
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
|
||||||
// Note: no check for `self.destroyed` so that pending messages to the
|
// Note: no check for `self.destroyed` so that pending messages to the
|
||||||
// tracker can still be sent/received even after destroy() is called
|
// 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)
|
else announce(msg.slice(8, 16), opts)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
}
|
||||||
case 1: // announce
|
case 1: { // announce
|
||||||
cleanup()
|
cleanup()
|
||||||
if (self.destroyed) return
|
if (self.destroyed) return
|
||||||
|
|
||||||
@ -166,8 +166,8 @@ class UDPTracker extends Tracker {
|
|||||||
})
|
})
|
||||||
|
|
||||||
break
|
break
|
||||||
|
}
|
||||||
case 2: // scrape
|
case 2: { // scrape
|
||||||
cleanup()
|
cleanup()
|
||||||
if (self.destroyed) return
|
if (self.destroyed) return
|
||||||
|
|
||||||
@ -189,8 +189,8 @@ class UDPTracker extends Tracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
}
|
||||||
case 3: // error
|
case 3: { // error
|
||||||
cleanup()
|
cleanup()
|
||||||
if (self.destroyed) return
|
if (self.destroyed) return
|
||||||
|
|
||||||
@ -198,10 +198,11 @@ class UDPTracker extends Tracker {
|
|||||||
self.client.emit('warning', new Error(msg.slice(8).toString()))
|
self.client.emit('warning', new Error(msg.slice(8).toString()))
|
||||||
|
|
||||||
break
|
break
|
||||||
|
}
|
||||||
default:
|
default: {
|
||||||
onError(new Error('tracker sent invalid action'))
|
onError(new Error('tracker sent invalid action'))
|
||||||
break
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
server.js
12
server.js
@ -750,14 +750,15 @@ Server.Swarm = Swarm
|
|||||||
function makeUdpPacket (params) {
|
function makeUdpPacket (params) {
|
||||||
let packet
|
let packet
|
||||||
switch (params.action) {
|
switch (params.action) {
|
||||||
case common.ACTIONS.CONNECT:
|
case common.ACTIONS.CONNECT: {
|
||||||
packet = Buffer.concat([
|
packet = Buffer.concat([
|
||||||
common.toUInt32(common.ACTIONS.CONNECT),
|
common.toUInt32(common.ACTIONS.CONNECT),
|
||||||
common.toUInt32(params.transactionId),
|
common.toUInt32(params.transactionId),
|
||||||
params.connectionId
|
params.connectionId
|
||||||
])
|
])
|
||||||
break
|
break
|
||||||
case common.ACTIONS.ANNOUNCE:
|
}
|
||||||
|
case common.ACTIONS.ANNOUNCE: {
|
||||||
packet = Buffer.concat([
|
packet = Buffer.concat([
|
||||||
common.toUInt32(common.ACTIONS.ANNOUNCE),
|
common.toUInt32(common.ACTIONS.ANNOUNCE),
|
||||||
common.toUInt32(params.transactionId),
|
common.toUInt32(params.transactionId),
|
||||||
@ -767,7 +768,8 @@ function makeUdpPacket (params) {
|
|||||||
params.peers
|
params.peers
|
||||||
])
|
])
|
||||||
break
|
break
|
||||||
case common.ACTIONS.SCRAPE:
|
}
|
||||||
|
case common.ACTIONS.SCRAPE: {
|
||||||
const scrapeResponse = [
|
const scrapeResponse = [
|
||||||
common.toUInt32(common.ACTIONS.SCRAPE),
|
common.toUInt32(common.ACTIONS.SCRAPE),
|
||||||
common.toUInt32(params.transactionId)
|
common.toUInt32(params.transactionId)
|
||||||
@ -782,13 +784,15 @@ function makeUdpPacket (params) {
|
|||||||
}
|
}
|
||||||
packet = Buffer.concat(scrapeResponse)
|
packet = Buffer.concat(scrapeResponse)
|
||||||
break
|
break
|
||||||
case common.ACTIONS.ERROR:
|
}
|
||||||
|
case common.ACTIONS.ERROR: {
|
||||||
packet = Buffer.concat([
|
packet = Buffer.concat([
|
||||||
common.toUInt32(common.ACTIONS.ERROR),
|
common.toUInt32(common.ACTIONS.ERROR),
|
||||||
common.toUInt32(params.transactionId || 0),
|
common.toUInt32(params.transactionId || 0),
|
||||||
Buffer.from(String(params['failure reason']))
|
Buffer.from(String(params['failure reason']))
|
||||||
])
|
])
|
||||||
break
|
break
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error(`Action not implemented: ${params.action}`)
|
throw new Error(`Action not implemented: ${params.action}`)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user