Skip to content

Commit ebb86f7

Browse files
committed
JavaScript Standard Style
https://github.com/feross/standard
1 parent 556f672 commit ebb86f7

File tree

9 files changed

+17
-27
lines changed

9 files changed

+17
-27
lines changed

client.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ var EventEmitter = require('events').EventEmitter
1010
var extend = require('extend.js')
1111
var get = require('simple-get')
1212
var hat = require('hat')
13-
var http = require('http')
14-
var https = require('https')
1513
var inherits = require('inherits')
1614
var once = require('once')
1715
var url = require('url')

lib/parse_http.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ function parseHttpRequest (req, options) {
3232
? req.headers['x-forwarded-for'] || req.connection.remoteAddress
3333
: req.connection.remoteAddress.replace(REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
3434
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
35-
36-
} else if (s[0] === '/scrape') { // unofficial scrape message
35+
} else if (s[0] === '/scrape') {
3736
params.action = common.ACTIONS.SCRAPE
3837
if (typeof params.info_hash === 'string')
3938
params.info_hash = [ params.info_hash ]
@@ -45,7 +44,6 @@ function parseHttpRequest (req, options) {
4544
return common.binaryToHex(binaryInfoHash)
4645
})
4746
}
48-
4947
} else {
5048
throw new Error('Invalid action in HTTP request: ' + params.action)
5149
}

lib/parse_udp.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function parseUdpRequest (msg, rinfo) {
2323

2424
if (params.action === common.ACTIONS.CONNECT) {
2525
// No further params
26-
2726
} else if (params.action === common.ACTIONS.ANNOUNCE) {
2827
params.info_hash = msg.slice(16, 36).toString('hex') // 20 bytes
2928
params.peer_id = msg.slice(36, 56).toString('hex') // 20 bytes
@@ -51,13 +50,11 @@ function parseUdpRequest (msg, rinfo) {
5150
params.port = msg.readUInt16BE(96) || rinfo.port // optional
5251
params.addr = params.ip + ':' + params.port // TODO: ipv6 brackets
5352
params.compact = 1 // udp is always compact
54-
5553
} else if (params.action === common.ACTIONS.SCRAPE) { // scrape message
5654
// TODO: support multiple info_hash scrape
5755
if (msg.length > 36) throw new Error('multiple info_hash scrape not supported')
5856

5957
params.info_hash = [ msg.slice(16, 36).toString('hex') ] // 20 bytes
60-
6158
} else {
6259
throw new Error('Invalid action in UDP packet: ' + params.action)
6360
}

lib/swarm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Swarm.prototype.announce = function (params, cb) {
2828
incomplete: self.incomplete,
2929
peers: self._getPeers(params.numwant)
3030
})
31-
3231
} else {
3332
cb(new Error('invalid event'))
3433
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"devDependencies": {
3333
"magnet-uri": "^4.0.0",
3434
"parse-torrent": "^3.0.1",
35+
"standard": "^1.0.0",
3536
"tape": "^3.0.3"
3637
},
3738
"homepage": "http://webtorrent.io",
@@ -52,6 +53,6 @@
5253
"url": "git://github.com/feross/bittorrent-tracker.git"
5354
},
5455
"scripts": {
55-
"test": "tape test/*.js"
56+
"test": "standard && tape test/*.js"
5657
}
5758
}

server.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var parseUdpRequest = require('./lib/parse_udp')
1818
// Use random port above 1024
1919
portfinder.basePort = Math.floor(Math.random() * 60000) + 1025
2020

21-
2221
inherits(Server, EventEmitter)
2322

2423
/**
@@ -183,11 +182,7 @@ Server.prototype.onUdpRequest = function (msg, rinfo) {
183182
response.transactionId = params.transactionId
184183
response.connectionId = params.connectionId
185184
var buf = makeUdpPacket(response)
186-
self._udpSocket.send(buf, 0, buf.length, rinfo.port, rinfo.address, function () {
187-
try {
188-
socket.close()
189-
} catch (err) {}
190-
})
185+
self._udpSocket.send(buf, 0, buf.length, rinfo.port, rinfo.address)
191186
})
192187
}
193188

@@ -274,43 +269,50 @@ Server.prototype._onScrape = function (params, cb) {
274269
}
275270

276271
function makeUdpPacket (params) {
272+
var packet
277273
switch (params.action) {
278274
case common.ACTIONS.CONNECT:
279-
return Buffer.concat([
275+
packet = Buffer.concat([
280276
common.toUInt32(common.ACTIONS.CONNECT),
281277
common.toUInt32(params.transactionId),
282278
params.connectionId
283279
])
280+
break
284281
case common.ACTIONS.ANNOUNCE:
285-
return Buffer.concat([
282+
packet = Buffer.concat([
286283
common.toUInt32(common.ACTIONS.ANNOUNCE),
287284
common.toUInt32(params.transactionId),
288285
common.toUInt32(params.interval),
289286
common.toUInt32(params.incomplete),
290287
common.toUInt32(params.complete),
291288
params.peers
292289
])
290+
break
293291
case common.ACTIONS.SCRAPE:
294292
var firstInfoHash = Object.keys(params.files)[0]
295293
var scrapeInfo = firstInfoHash ? {
296294
complete: params.files[firstInfoHash].complete,
297295
incomplete: params.files[firstInfoHash].incomplete,
298296
completed: params.files[firstInfoHash].complete // TODO: this only provides a lower-bound
299297
} : {}
300-
return Buffer.concat([
298+
packet = Buffer.concat([
301299
common.toUInt32(common.ACTIONS.SCRAPE),
302300
common.toUInt32(params.transactionId),
303301
common.toUInt32(scrapeInfo.complete),
304302
common.toUInt32(scrapeInfo.completed),
305303
common.toUInt32(scrapeInfo.incomplete)
306304
])
305+
break
307306
case common.ACTIONS.ERROR:
308-
return Buffer.concat([
307+
packet = Buffer.concat([
309308
common.toUInt32(common.ACTIONS.ERROR),
310309
common.toUInt32(params.transactionId || 0),
311310
new Buffer(params.message, 'utf8')
312311
])
313-
default:
314-
throw new Error('Action not implemented: ' + params.action)
312+
break
313+
default:
314+
throw new Error('Action not implemented: ' + params.action)
315+
break
315316
}
317+
return packet
316318
}

test/client-large-torrent.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ test('large torrent: client.start()', function (t) {
5353
t.pass('server close')
5454
})
5555
})
56-
5756
})
5857
})
5958
})

test/client.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ function testClientStop (t, serverType) {
8383
t.pass('server close')
8484
})
8585
})
86-
8786
}, 1000)
8887
})
8988
}
@@ -113,7 +112,6 @@ function testClientUpdate (t, serverType) {
113112
client.start()
114113

115114
client.once('update', function () {
116-
117115
client.once('update', function (data) {
118116
// received an update!
119117
t.equal(data.announce, announceUrl)

test/scrape.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ test('server: all info_hash scrape', function (t) {
138138
parsedBitlove.announce = [ announceUrl ]
139139

140140
server.once('listening', function () {
141-
142141
// announce a torrent to the tracker
143142
var client = new Client(peerId, port, parsedBitlove)
144143
client.on('error', function (err) {
@@ -147,7 +146,6 @@ test('server: all info_hash scrape', function (t) {
147146
client.start()
148147

149148
server.once('start', function () {
150-
151149
// now do a scrape of everything by omitting the info_hash param
152150
get.concat(scrapeUrl, function (err, data, res) {
153151
if (err) throw err

0 commit comments

Comments
 (0)