diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-02-24 05:23:44 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-02-24 05:23:44 +0400 |
commit | 60513a554a2f7537369260d06e3488d8dcd03a42 (patch) | |
tree | 0d7687693c7b689ca55400b0b1d47a9454de906c /lib | |
parent | 7ef94bbd04cac03a956e8cc4fced16664f193d52 (diff) |
send PORT message if peer supports DHT
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent-manager.js | 3 | ||||
-rw-r--r-- | lib/torrent.js | 21 |
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/torrent-manager.js b/lib/torrent-manager.js index ffe975c..dec6b29 100644 --- a/lib/torrent-manager.js +++ b/lib/torrent-manager.js @@ -90,7 +90,8 @@ TorrentManager.prototype.add = function (uri) { var torrent = new Torrent(uri, { peerId: self.peerId, - port: self.torrentPort + torrentPort: self.torrentPort, + dhtPort: self.dhtPort }) self.torrents.push(torrent) diff --git a/lib/torrent.js b/lib/torrent.js index be52252..0ba8a1d 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -25,10 +25,14 @@ function Torrent (uri, opts) { self.metadata = null self.file = null - self.swarm = new Swarm(self.infoHash, opts.peerId, { dht: true }) + self.peerId = opts.peerId + self.torrentPort = opts.torrentPort + self.dhtPort = opts.dhtPort - if (opts.port) { - self.swarm.listen(opts.port, function (port) { + self.swarm = new Swarm(self.infoHash, self.peerId, { dht: true }) + + if (self.torrentPort) { + self.swarm.listen(self.torrentPort, function (port) { self.emit('listening', port) }) } @@ -56,16 +60,13 @@ Torrent.prototype.addPeer = function (addr) { } Torrent.prototype._onWire = function (wire) { + var self = this + // Send KEEP-ALIVE (every 60s) so peers will not disconnect the wire wire.setKeepAlive(true) - // If peer supports DHT, send PORT message to report what port our DHT node - // is listening on - if (wire.peerExtensions.dht) { - console.log('peer supports DHT') - // TODO: DHT doesn't support listening yet - // wire.port(dht.port) - } + if (wire.peerExtensions.dht) + wire.port(self.dhtPort) // When peer sends PORT, add them to the routing table wire.on('port', function (port) { |