mirror of
https://github.com/logos-storage/bittorrent-tracker.git
synced 2026-01-05 22:43:08 +00:00
style: always use braces except for single-line
This commit is contained in:
parent
1808290d7a
commit
57cef88169
@ -12,11 +12,13 @@ function parseHttpRequest (req, options) {
|
|||||||
if (options.action === 'announce' || s[0] === '/announce') {
|
if (options.action === 'announce' || s[0] === '/announce') {
|
||||||
params.action = common.ACTIONS.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')
|
throw new Error('invalid info_hash')
|
||||||
|
}
|
||||||
params.info_hash = common.binaryToHex(params.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')
|
throw new Error('invalid peer_id')
|
||||||
|
}
|
||||||
params.peer_id = common.binaryToHex(params.peer_id)
|
params.peer_id = common.binaryToHex(params.peer_id)
|
||||||
|
|
||||||
params.port = Number(params.port)
|
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
|
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
|
||||||
} else if (options.action === 'scrape' || s[0] === '/scrape') {
|
} else if (options.action === 'scrape' || s[0] === '/scrape') {
|
||||||
params.action = common.ACTIONS.SCRAPE
|
params.action = common.ACTIONS.SCRAPE
|
||||||
if (typeof params.info_hash === 'string')
|
if (typeof params.info_hash === 'string') params.info_hash = [ params.info_hash ]
|
||||||
params.info_hash = [ params.info_hash ]
|
|
||||||
|
|
||||||
if (Array.isArray(params.info_hash)) {
|
if (Array.isArray(params.info_hash)) {
|
||||||
params.info_hash = params.info_hash.map(function (binaryInfoHash) {
|
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')
|
throw new Error('invalid info_hash')
|
||||||
|
}
|
||||||
return common.binaryToHex(binaryInfoHash)
|
return common.binaryToHex(binaryInfoHash)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,11 +5,9 @@ var ipLib = require('ip')
|
|||||||
var common = require('./common')
|
var common = require('./common')
|
||||||
|
|
||||||
function parseUdpRequest (msg, rinfo) {
|
function parseUdpRequest (msg, rinfo) {
|
||||||
if (msg.length < 16)
|
if (msg.length < 16) throw new Error('received packet is too short')
|
||||||
throw new Error('received packet is too short')
|
|
||||||
|
|
||||||
if (rinfo.family !== 'IPv4')
|
if (rinfo.family !== 'IPv4') throw new Error('udp tracker does not support IPv6')
|
||||||
throw new Error('udp tracker does not support IPv6')
|
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
connectionId: msg.slice(0, 8), // 64-bit
|
connectionId: msg.slice(0, 8), // 64-bit
|
||||||
@ -18,8 +16,9 @@ function parseUdpRequest (msg, rinfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: randomize
|
// 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')
|
throw new Error('received packet with invalid connection id')
|
||||||
|
}
|
||||||
|
|
||||||
if (params.action === common.ACTIONS.CONNECT) {
|
if (params.action === common.ACTIONS.CONNECT) {
|
||||||
// No further params
|
// No further params
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user