diff --git a/lib/parse_http.js b/lib/parse_http.js index d90d3e5..bfc0d94 100644 --- a/lib/parse_http.js +++ b/lib/parse_http.js @@ -12,11 +12,13 @@ function parseHttpRequest (req, options) { if (options.action === 'announce' || s[0] === '/announce') { params.action = common.ACTIONS.ANNOUNCE - if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20) + if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20) { throw new Error('invalid info_hash') + } params.info_hash = common.binaryToHex(params.info_hash) - if (typeof params.peer_id !== 'string' || params.peer_id.length !== 20) + if (typeof params.peer_id !== 'string' || params.peer_id.length !== 20) { throw new Error('invalid peer_id') + } params.peer_id = common.binaryToHex(params.peer_id) params.port = Number(params.port) @@ -35,13 +37,13 @@ function parseHttpRequest (req, options) { params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port } else if (options.action === 'scrape' || s[0] === '/scrape') { params.action = common.ACTIONS.SCRAPE - if (typeof params.info_hash === 'string') - params.info_hash = [ params.info_hash ] + if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ] if (Array.isArray(params.info_hash)) { params.info_hash = params.info_hash.map(function (binaryInfoHash) { - if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) + if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) { throw new Error('invalid info_hash') + } return common.binaryToHex(binaryInfoHash) }) } diff --git a/lib/parse_udp.js b/lib/parse_udp.js index 3fac4ec..dd6634f 100644 --- a/lib/parse_udp.js +++ b/lib/parse_udp.js @@ -5,11 +5,9 @@ var ipLib = require('ip') var common = require('./common') function parseUdpRequest (msg, rinfo) { - if (msg.length < 16) - throw new Error('received packet is too short') + if (msg.length < 16) throw new Error('received packet is too short') - if (rinfo.family !== 'IPv4') - throw new Error('udp tracker does not support IPv6') + if (rinfo.family !== 'IPv4') throw new Error('udp tracker does not support IPv6') var params = { connectionId: msg.slice(0, 8), // 64-bit @@ -18,8 +16,9 @@ function parseUdpRequest (msg, rinfo) { } // TODO: randomize - if (!bufferEqual(params.connectionId, common.CONNECTION_ID)) + if (!bufferEqual(params.connectionId, common.CONNECTION_ID)) { throw new Error('received packet with invalid connection id') + } if (params.action === common.ACTIONS.CONNECT) { // No further params