Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/client/udp-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -166,8 +166,8 @@ class UDPTracker extends Tracker {
})

break

case 2: // scrape
}
case 2: { // scrape
cleanup()
if (self.destroyed) return

Expand All @@ -189,16 +189,16 @@ class UDPTracker extends Tracker {
}

break

case 3: // error
}
case 3: { // error
cleanup()
if (self.destroyed) return

if (msg.length < 8) return onError(new Error('invalid error message'))
self.client.emit('warning', new Error(msg.slice(8).toString()))

break

}
default:
onError(new Error('tracker sent invalid action'))
break
Expand Down
12 changes: 8 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand All @@ -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}`)
}
Expand Down