From dc79834f771d415e3e88a2c613198df400932838 Mon Sep 17 00:00:00 2001 From: Justin Kalland Date: Thu, 20 Dec 2018 12:59:53 -0700 Subject: [PATCH] Use blocks with brackets --- lib/client/udp-tracker.js | 19 ++++++++++--------- server.js | 12 ++++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index 239ae12..ffbbcc7 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -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,10 +198,11 @@ 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 + } } } diff --git a/server.js b/server.js index 9d29bef..10eb839 100644 --- a/server.js +++ b/server.js @@ -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}`) }