Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2017-02-03 03:06:07 +0300
committerFeross Aboukhadijeh <feross@feross.org>2017-02-03 03:06:07 +0300
commit39d2f8ca59f9a29519727bd66b87c0b7b9930100 (patch)
tree516d5e90fb1104f678c97f827336a365c57b17f3 /index.js
parenta40ce23da18b5e9ec0b35fbdb53687af752b13ab (diff)
include peerId in index.js debug logs
Diffstat (limited to 'index.js')
-rw-r--r--index.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/index.js b/index.js
index 708571d..ee9a891 100644
--- a/index.js
+++ b/index.js
@@ -78,6 +78,8 @@ function WebTorrent (opts) {
}
self.nodeIdBuffer = Buffer.from(self.nodeId, 'hex')
+ self._debugId = self.peerId.toString('hex').substring(0, 7)
+
self.destroyed = false
self.listening = false
self.torrentPort = opts.torrentPort || 0
@@ -86,7 +88,7 @@ function WebTorrent (opts) {
self.torrents = []
self.maxConns = Number(opts.maxConns) || 55
- debug(
+ self._debug(
'new webtorrent (peerId %s, nodeId %s, port %s)',
self.peerId, self.nodeId, self.torrentPort
)
@@ -252,7 +254,7 @@ WebTorrent.prototype.add = function (torrentId, opts, ontorrent) {
if (self.destroyed) throw new Error('client is destroyed')
if (typeof opts === 'function') return self.add(torrentId, null, opts)
- debug('add')
+ self._debug('add')
opts = opts ? extend(opts) : {}
var torrent = new Torrent(torrentId, self, opts)
@@ -299,7 +301,7 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
if (self.destroyed) throw new Error('client is destroyed')
if (typeof opts === 'function') return self.seed(input, null, opts)
- debug('seed')
+ self._debug('seed')
opts = opts ? extend(opts) : {}
// When seeding from fs path, initialize store from that path to avoid a copy
@@ -362,7 +364,7 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
}
function _onseed (torrent) {
- debug('on seed')
+ self._debug('on seed')
if (typeof onseed === 'function') onseed(torrent)
torrent.emit('seed')
self.emit('seed', torrent)
@@ -377,7 +379,7 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
* @param {function} cb
*/
WebTorrent.prototype.remove = function (torrentId, cb) {
- debug('remove')
+ this._debug('remove')
var torrent = this.get(torrentId)
if (!torrent) throw new Error('No torrent with id ' + torrentId)
this._remove(torrentId, cb)
@@ -408,7 +410,7 @@ WebTorrent.prototype.destroy = function (cb) {
WebTorrent.prototype._destroy = function (err, cb) {
var self = this
- debug('client destroy')
+ self._debug('client destroy')
self.destroyed = true
var tasks = self.torrents.map(function (torrent) {
@@ -439,6 +441,7 @@ WebTorrent.prototype._destroy = function (err, cb) {
}
WebTorrent.prototype._onListening = function () {
+ this._debug('listening')
this.listening = true
if (this._tcpPool) {
@@ -451,6 +454,12 @@ WebTorrent.prototype._onListening = function () {
this.emit('listening')
}
+WebTorrent.prototype._debug = function () {
+ var args = [].slice.call(arguments)
+ args[0] = '[' + this._debugId + '] ' + args[0]
+ debug.apply(null, args)
+}
+
/**
* Check if `obj` is a node Readable stream
* @param {*} obj