Merge pull request #53 from feross/fix-interval

server: fix interval unit
This commit is contained in:
Feross Aboukhadijeh 2015-01-05 20:12:13 -08:00
commit 2631afbf1e

View File

@ -42,8 +42,8 @@ function Server (opts) {
opts = opts || {} opts = opts || {}
self._intervalMs = opts.interval self._intervalMs = opts.interval
? opts.interval / 1000 ? opts.interval
: 10 * 60 // 10 min (in secs) : 10 * 60 * 1000 // 10 min
self._trustProxy = !!opts.trustProxy self._trustProxy = !!opts.trustProxy
@ -209,7 +209,7 @@ Server.prototype._onAnnounce = function (params, cb) {
swarm.announce(params, function (err, response) { swarm.announce(params, function (err, response) {
if (response) { if (response) {
if (!response.action) response.action = common.ACTIONS.ANNOUNCE if (!response.action) response.action = common.ACTIONS.ANNOUNCE
if (!response.intervalMs) response.intervalMs = self._intervalMs if (!response.interval) response.interval = Math.ceil(self._intervalMs / 1000)
if (params.compact === 1) { if (params.compact === 1) {
var peers = response.peers var peers = response.peers
@ -258,7 +258,7 @@ Server.prototype._onScrape = function (params, cb) {
var response = { var response = {
action: common.ACTIONS.SCRAPE, action: common.ACTIONS.SCRAPE,
files: {}, files: {},
flags: { min_request_interval: self._intervalMs } flags: { min_request_interval: Math.ceil(self._intervalMs / 1000) }
} }
results.forEach(function (result) { results.forEach(function (result) {
@ -285,7 +285,7 @@ function makeUdpPacket (params) {
return Buffer.concat([ return Buffer.concat([
common.toUInt32(common.ACTIONS.ANNOUNCE), common.toUInt32(common.ACTIONS.ANNOUNCE),
common.toUInt32(params.transactionId), common.toUInt32(params.transactionId),
common.toUInt32(params.intervalMs), common.toUInt32(params.interval),
common.toUInt32(params.incomplete), common.toUInt32(params.incomplete),
common.toUInt32(params.complete), common.toUInt32(params.complete),
params.peers params.peers