torrent-discovery
Advanced tools
Comparing version 3.0.2 to 3.0.3
26
index.js
@@ -28,2 +28,6 @@ module.exports = Discovery | ||
self.infoHash = null | ||
self.infoHashHex = null | ||
self.torrent = null | ||
self._externalDHT = typeof self.dht === 'object' | ||
@@ -40,13 +44,19 @@ self._performedDHTLookup = false | ||
var self = this | ||
if (self.torrent) return | ||
if (torrent && torrent.infoHash) { | ||
if (!self.infoHash && Buffer.isBuffer(torrent) || typeof torrent === 'string') { | ||
self.infoHash = typeof torrent === 'string' | ||
? new Buffer(torrent, 'hex') | ||
: torrent | ||
} else if (!self.torrent && torrent && torrent.infoHash) { | ||
self.torrent = torrent | ||
self.infoHash = torrent.infoHash | ||
self.infoHash = typeof torrent.infoHash === 'string' | ||
? new Buffer(torrent.infoHash, 'hex') | ||
: torrent.infoHash | ||
} else { | ||
if (self.infoHash) return | ||
self.infoHash = torrent | ||
return | ||
} | ||
debug('setTorrent %s', self.infoHash) | ||
self.infoHashHex = self.infoHash.toString('hex') | ||
debug('setTorrent %s', self.infoHashHex) | ||
// If tracker exists, then it was created with just infoHash. Set torrent length | ||
@@ -82,3 +92,3 @@ // so client can report correct information about uploads. | ||
self.dht.on('peer', function (addr, infoHash) { | ||
if (infoHash === self.infoHash) self.emit('peer', addr) | ||
if (infoHash === self.infoHashHex) self.emit('peer', addr) | ||
}) | ||
@@ -93,3 +103,3 @@ if (!self._externalDHT) self.dht.listen(port) | ||
var torrent = self.torrent || { | ||
infoHash: self.infoHash, | ||
infoHash: self.infoHashHex, | ||
announce: self.announce | ||
@@ -96,0 +106,0 @@ } |
{ | ||
"name": "torrent-discovery", | ||
"description": "Discover BitTorrent and WebTorrent peers", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10987
173