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
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2013-10-28 06:20:16 +0400
committerFeross Aboukhadijeh <feross@feross.org>2013-10-28 06:20:16 +0400
commit2b0a3a4208a3d2e46183f4252c50f99276c350a1 (patch)
treeb194153d8a54809f32ed188f34ab90c46d8858f0 /lib
parentefb2bc773fba9a9edd69af8986f137359251ddee (diff)
better logging
Diffstat (limited to 'lib')
-rw-r--r--lib/bittorrent-dht/index.js22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/bittorrent-dht/index.js b/lib/bittorrent-dht/index.js
index c32227a..c95b254 100644
--- a/lib/bittorrent-dht/index.js
+++ b/lib/bittorrent-dht/index.js
@@ -31,7 +31,7 @@ function parseNodeInfo (compact) {
try {
var nodes = []
for (var i = 0; i < compact.length; i += 26) {
- nodes.push(compact2string(bops.subarray(compact, i+20, i+26)))
+ nodes.push(compact2string(bops.subarray(compact, i + 20, i + 26)))
}
return nodes
} catch (err) {
@@ -56,7 +56,6 @@ util.inherits(DHT, EventEmitter)
* @param {string|Buffer} infoHash
*/
function DHT (infoHash) {
- log('new DHT')
var self = this
EventEmitter.call(self)
@@ -76,8 +75,7 @@ function DHT (infoHash) {
self.missingNodes = 0
self.nodeId = randomId()
- console.log('our node id: ' + bops.to(self.nodeId, 'hex'))
- console.log(self.nodeId)
+ log('our node id: ' + bops.to(self.nodeId, 'hex'))
self.requestId = 1
self.pendingRequests = {}
@@ -91,7 +89,9 @@ function DHT (infoHash) {
info_hash: self.infoHash
}
}
- console.log(self.message)
+ log('created message: ')
+ log(JSON.stringify(self.message))
+
self.message = bencode.encode(self.message)
self.pendingRequests[self.requestId] = 1
@@ -104,10 +104,10 @@ DHT.prototype._onNode = function (addr) {
var self = this
if (self.nodes[addr]) return // already know about this node
process.nextTick(function () {
- self.emit('node', self.infoHash, addr)
+ self.emit('node', addr, bops.to(self.infoHash, 'hex'))
})
- if (self.missingNodes > 0) return self.query(addr)
- if (self.queue.length < 50) self.queue.push(addr)
+ // if (self.missingNodes > 0) return self.query(addr)
+ // if (self.queue.length < 50) self.queue.push(addr)
}
DHT.prototype._onPeer = function (addr) {
@@ -116,7 +116,7 @@ DHT.prototype._onPeer = function (addr) {
self.peers[addr] = true
self.missingNodes = Math.max(0, self.missingNodes - 1)
process.nextTick(function () {
- self.emit('peer', self.infoHash, addr)
+ self.emit('peer', addr, bops.to(self.infoHash, 'hex'))
})
}
@@ -126,9 +126,9 @@ DHT.prototype._onData = function (data, host, port) {
var message
try {
- console.log('got response from ' + host + ':' + port)
+ log('got response from ' + host + ':' + port)
message = bencode.decode(data)
- console.log(message)
+ log(JSON.stringify(message))
if (!message) throw new Error('message is undefined')
} catch (err) {
console.error('Failed to decode UDP data from node ' + host + ':' + port)