Skip to content

Commit e3c65bc

Browse files
committed
PR Feedback for webtorrent#120
1 parent bea1021 commit e3c65bc

File tree

5 files changed

+6
-12
lines changed

5 files changed

+6
-12
lines changed

lib/common-node.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ exports.EVENT_NAMES = {
2424
started: 'start',
2525
stopped: 'stop'
2626
}
27-
exports.PEER_TYPES = {
28-
http: 'http',
29-
udp: 'udp',
30-
websocket: 'ws'
31-
}
3227

3328
function toUInt32 (n) {
3429
var buf = new Buffer(4)

lib/server/parse-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ function parseHttpRequest (req, opts) {
66
if (!opts) opts = {}
77
var s = req.url.split('?')
88
var params = common.querystringParse(s[1])
9+
params.type = 'http'
910

1011
if (opts.action === 'announce' || s[0] === '/announce') {
1112
params.action = common.ACTIONS.ANNOUNCE
12-
params.type = common.PEER_TYPES.http
1313

1414
if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20) {
1515
throw new Error('invalid info_hash')

lib/server/parse-udp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function parseUdpRequest (msg, rinfo) {
1111
connectionId: msg.slice(0, 8), // 64-bit
1212
action: msg.readUInt32BE(8),
1313
transactionId: msg.readUInt32BE(12),
14-
type: common.PEER_TYPES.udp
14+
type: 'udp'
1515
}
1616

1717
if (!bufferEqual(params.connectionId, common.CONNECTION_ID)) {

lib/server/parse-websocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function parseWebSocketRequest (socket, opts, params) {
77
params = JSON.parse(params) // may throw
88

99
params.action = common.ACTIONS.ANNOUNCE
10-
params.type = common.PEER_TYPES.websocket
10+
params.type = 'ws'
1111
params.socket = socket
1212

1313
if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20) {

lib/server/swarm.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module.exports = Swarm
22

33
var debug = require('debug')('bittorrent-tracker')
44
var randomIterate = require('random-iterate')
5-
var common = require('../common')
65

76
// Regard this as the default implementation of an interface that you
87
// need to support when overriding Server.createSwarm() and Server.getSwarm()
@@ -14,7 +13,7 @@ function Swarm (infoHash, server) {
1413

1514
Swarm.prototype.announce = function (params, cb) {
1615
var self = this
17-
var id = params.type === common.PEER_TYPES.websocket ? params.peer_id : params.addr
16+
var id = params.type === 'ws' ? params.peer_id : params.addr
1817
var peer = self.peers[id]
1918

2019
if (params.event === 'started') {
@@ -51,7 +50,7 @@ Swarm.prototype._onAnnounceStarted = function (params, peer) {
5150

5251
if (params.left === 0) this.complete += 1
5352
else this.incomplete += 1
54-
var id = params.type === common.PEER_TYPES.websocket ? params.peer_id : params.addr
53+
var id = params.type === 'ws' ? params.peer_id : params.addr
5554
peer = this.peers[id] = {
5655
complete: params.left === 0,
5756
peerId: params.peer_id, // as hex
@@ -69,7 +68,7 @@ Swarm.prototype._onAnnounceStopped = function (params, peer) {
6968

7069
if (peer.complete) this.complete -= 1
7170
else this.incomplete -= 1
72-
var id = params.type === common.PEER_TYPES.websocket ? params.peer_id : params.addr
71+
var id = params.type === 'ws' ? params.peer_id : params.addr
7372
delete this.peers[id]
7473
}
7574

0 commit comments

Comments
 (0)