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>2014-02-24 05:23:44 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-02-24 05:23:44 +0400
commit60513a554a2f7537369260d06e3488d8dcd03a42 (patch)
tree0d7687693c7b689ca55400b0b1d47a9454de906c /lib
parent7ef94bbd04cac03a956e8cc4fced16664f193d52 (diff)
send PORT message if peer supports DHT
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent-manager.js3
-rw-r--r--lib/torrent.js21
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) {