style: always use braces except for single-line

This commit is contained in:
Feross Aboukhadijeh 2015-03-06 18:12:59 -08:00
parent 1808290d7a
commit 57cef88169
2 changed files with 11 additions and 10 deletions

View File

@ -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)
})
}

View File

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