Skip to content

Commit 57cef88

Browse files
committed
style: always use braces except for single-line
1 parent 1808290 commit 57cef88

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/parse_http.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ function parseHttpRequest (req, options) {
1212
if (options.action === 'announce' || s[0] === '/announce') {
1313
params.action = common.ACTIONS.ANNOUNCE
1414

15-
if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20)
15+
if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20) {
1616
throw new Error('invalid info_hash')
17+
}
1718
params.info_hash = common.binaryToHex(params.info_hash)
18-
if (typeof params.peer_id !== 'string' || params.peer_id.length !== 20)
19+
if (typeof params.peer_id !== 'string' || params.peer_id.length !== 20) {
1920
throw new Error('invalid peer_id')
21+
}
2022
params.peer_id = common.binaryToHex(params.peer_id)
2123

2224
params.port = Number(params.port)
@@ -35,13 +37,13 @@ function parseHttpRequest (req, options) {
3537
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
3638
} else if (options.action === 'scrape' || s[0] === '/scrape') {
3739
params.action = common.ACTIONS.SCRAPE
38-
if (typeof params.info_hash === 'string')
39-
params.info_hash = [ params.info_hash ]
40+
if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ]
4041

4142
if (Array.isArray(params.info_hash)) {
4243
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
43-
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20)
44+
if (typeof binaryInfoHash !== 'string' || binaryInfoHash.length !== 20) {
4445
throw new Error('invalid info_hash')
46+
}
4547
return common.binaryToHex(binaryInfoHash)
4648
})
4749
}

lib/parse_udp.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ var ipLib = require('ip')
55
var common = require('./common')
66

77
function parseUdpRequest (msg, rinfo) {
8-
if (msg.length < 16)
9-
throw new Error('received packet is too short')
8+
if (msg.length < 16) throw new Error('received packet is too short')
109

11-
if (rinfo.family !== 'IPv4')
12-
throw new Error('udp tracker does not support IPv6')
10+
if (rinfo.family !== 'IPv4') throw new Error('udp tracker does not support IPv6')
1311

1412
var params = {
1513
connectionId: msg.slice(0, 8), // 64-bit
@@ -18,8 +16,9 @@ function parseUdpRequest (msg, rinfo) {
1816
}
1917

2018
// TODO: randomize
21-
if (!bufferEqual(params.connectionId, common.CONNECTION_ID))
19+
if (!bufferEqual(params.connectionId, common.CONNECTION_ID)) {
2220
throw new Error('received packet with invalid connection id')
21+
}
2322

2423
if (params.action === common.ACTIONS.CONNECT) {
2524
// No further params

0 commit comments

Comments
 (0)