diff --git a/lib/swarm.js b/lib/swarm.js index 2413139..fbdc9df 100644 --- a/lib/swarm.js +++ b/lib/swarm.js @@ -1,5 +1,4 @@ var debug = require('debug')('bittorrent-tracker') -var string2compact = require('string2compact') module.exports = Swarm @@ -85,9 +84,7 @@ Swarm.prototype.announce = function (params, cb) { if (params.left === 0 && peer) peer.complete = true // send peers - var peers = params.compact === 1 - ? self._getPeersCompact(params.numwant) - : self._getPeers(params.numwant) + var peers = self._getPeers(params.numwant) cb(null, { complete: this.complete, @@ -111,20 +108,6 @@ Swarm.prototype._getPeers = function (numwant) { return peers } -Swarm.prototype._getPeersCompact = function (numwant) { - var peers = [] - - for (var peerId in this.peers) { - if (peers.length >= numwant) break - var peer = this.peers[peerId] - if (!peer) continue // ignore null values - peers.push(peer.ip + ':' + peer.port) - } - - return string2compact(peers) -} - - Swarm.prototype.scrape = function (infoHash, params, cb) { cb(null, { complete: this.complete, diff --git a/server.js b/server.js index 241e12c..e567835 100644 --- a/server.js +++ b/server.js @@ -9,6 +9,7 @@ var inherits = require('inherits') var ipLib = require('ip') var portfinder = require('portfinder') var series = require('run-series') +var string2compact = require('string2compact') var common = require('./lib/common') var Swarm = require('./lib/swarm') @@ -216,6 +217,11 @@ Server.prototype._onAnnounce = function (params, cb) { if (response) { if (!response.action) response.action = common.ACTIONS.ANNOUNCE if (!response.intervalMs) response.intervalMs = self._intervalMs + if (params.compact === 1) { + response.peers = string2compact(response.peers.map(function (peer) { + return peer.ip + ':' + peer.port // TODO: ipv6 brackets + })) + } } cb(err, response) })