mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-02-21 20:59:02 +00:00
fixes for PR #107
This commit is contained in:
parent
1db2cb8736
commit
b34fc100a1
20
client.js
20
client.js
@ -1,7 +1,8 @@
|
||||
module.exports = Client
|
||||
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
var debug = require('debug')('bittorrent-tracker')
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
var extend = require('xtend')
|
||||
var inherits = require('inherits')
|
||||
var once = require('once')
|
||||
var parallel = require('run-parallel')
|
||||
@ -20,12 +21,13 @@ inherits(Client, EventEmitter)
|
||||
*
|
||||
* Find torrent peers, to help a torrent client participate in a torrent swarm.
|
||||
*
|
||||
* @param {string|Buffer} peerId peer id
|
||||
* @param {Number} port torrent client listening port
|
||||
* @param {Object} torrent parsed torrent
|
||||
* @param {Object} opts options object
|
||||
* @param {Number} opts.rtcConfig RTCPeerConnection configuration object
|
||||
* @param {Number} opts.wrtc custom webrtc implementation
|
||||
* @param {string|Buffer} peerId peer id
|
||||
* @param {Number} port torrent client listening port
|
||||
* @param {Object} torrent parsed torrent
|
||||
* @param {Object} opts options object
|
||||
* @param {Number} opts.rtcConfig RTCPeerConnection configuration object
|
||||
* @param {Number} opts.wrtc custom webrtc implementation
|
||||
* @param {Object} opts.getAnnounceOpts callback to provide data to tracker
|
||||
*/
|
||||
function Client (peerId, port, torrent, opts) {
|
||||
var self = this
|
||||
@ -270,9 +272,7 @@ Client.prototype._defaultAnnounceOpts = function (opts) {
|
||||
opts.left = self.torrentLength - opts.downloaded
|
||||
}
|
||||
|
||||
if (opts.getAnnounceOpts == null) {
|
||||
opts.getAnnounceOpts = self._getAnnounceOpts
|
||||
}
|
||||
if (self._getAnnounceOpts) opts = extend(opts, self._getAnnounceOpts())
|
||||
|
||||
return opts
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ module.exports = HTTPTracker
|
||||
var bencode = require('bencode')
|
||||
var compact2string = require('compact2string')
|
||||
var debug = require('debug')('bittorrent-tracker:http-tracker')
|
||||
var extend = require('xtend')
|
||||
var get = require('simple-get')
|
||||
var inherits = require('inherits')
|
||||
|
||||
@ -40,27 +41,12 @@ HTTPTracker.prototype.announce = function (opts) {
|
||||
var self = this
|
||||
if (self.destroyed) return
|
||||
|
||||
// Refresh opts if the callback is provided
|
||||
var cbopts
|
||||
if (opts.getAnnounceOpts) {
|
||||
cbopts = opts.getAnnounceOpts()
|
||||
if (cbopts.uploaded) opts.uploaded = cbopts.uploaded
|
||||
if (cbopts.downloaded) opts.downloaded = cbopts.downloaded
|
||||
if (cbopts.left) opts.left = cbopts.left
|
||||
}
|
||||
|
||||
var params = {
|
||||
numwant: opts.numwant,
|
||||
uploaded: opts.uploaded,
|
||||
downloaded: opts.downloaded,
|
||||
left: opts.left,
|
||||
event: opts.event,
|
||||
var params = extend(opts, {
|
||||
compact: (opts.compact == null) ? 1 : opts.compact,
|
||||
info_hash: self.client._infoHashBinary,
|
||||
peer_id: self.client._peerIdBinary,
|
||||
port: self.client._port,
|
||||
extras: cbopts && cbopts.extraAnnounceOpts
|
||||
}
|
||||
port: self.client._port
|
||||
})
|
||||
if (self._trackerId) params.trackerid = self._trackerId
|
||||
|
||||
self._request(self.announceUrl, params, self._onAnnounceResponse.bind(self))
|
||||
|
@ -189,15 +189,6 @@ UDPTracker.prototype._request = function (opts) {
|
||||
function announce (connectionId, opts) {
|
||||
transactionId = genTransactionId()
|
||||
|
||||
// Refresh opts if the callback is provided
|
||||
var cbopts
|
||||
if (opts.getAnnounceOpts) {
|
||||
cbopts = opts.getAnnounceOpts()
|
||||
if (cbopts.uploaded) opts.uploaded = cbopts.uploaded
|
||||
if (cbopts.downloaded) opts.downloaded = cbopts.downloaded
|
||||
if (cbopts.left) opts.left = cbopts.left
|
||||
}
|
||||
|
||||
send(Buffer.concat([
|
||||
connectionId,
|
||||
common.toUInt32(common.ACTIONS.ANNOUNCE),
|
||||
|
@ -1,6 +1,7 @@
|
||||
module.exports = WebSocketTracker
|
||||
|
||||
var debug = require('debug')('bittorrent-tracker:websocket-tracker')
|
||||
var extend = require('xtend')
|
||||
var hat = require('hat')
|
||||
var inherits = require('inherits')
|
||||
var Peer = require('simple-peer')
|
||||
@ -44,27 +45,13 @@ WebSocketTracker.prototype.announce = function (opts) {
|
||||
// Limit the number of offers that are generated, since it can be slow
|
||||
var numwant = Math.min(opts.numwant, 10)
|
||||
|
||||
// Refresh opts if the callback is provided
|
||||
var cbopts
|
||||
if (opts.getAnnounceOpts) {
|
||||
cbopts = opts.getAnnounceOpts()
|
||||
if (cbopts.uploaded) opts.uploaded = cbopts.uploaded
|
||||
if (cbopts.downloaded) opts.downloaded = cbopts.downloaded
|
||||
if (cbopts.left) opts.left = cbopts.left
|
||||
}
|
||||
|
||||
self._generateOffers(numwant, function (offers) {
|
||||
var params = {
|
||||
var params = extend(opts, {
|
||||
numwant: numwant,
|
||||
uploaded: opts.uploaded || 0,
|
||||
downloaded: opts.downloaded,
|
||||
left: opts.left,
|
||||
event: opts.event,
|
||||
info_hash: self.client._infoHashBinary,
|
||||
peer_id: self.client._peerIdBinary,
|
||||
offers: offers,
|
||||
extras: cbopts && cbopts.extraAnnounceOpts
|
||||
}
|
||||
offers: offers
|
||||
})
|
||||
if (self._trackerId) params.trackerid = self._trackerId
|
||||
|
||||
self._send(params)
|
||||
|
Loading…
Reference in New Issue
Block a user