Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

send PORT message if peer supports DHT

  • Loading branch information...
commit 60513a554a2f7537369260d06e3488d8dcd03a42 1 parent 7ef94bb
@feross authored
Showing with 16 additions and 14 deletions.
  1. +2 −1  lib/torrent-manager.js
  2. +11 −10 lib/torrent.js
  3. +3 −3 package.json
View
3  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)
View
21 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) {
View
6 package.json
@@ -27,6 +27,7 @@
"bittorrent-protocol": "0.x",
"bittorrent-swarm": "0.x",
"bncode": "^0.5.2",
+ "brfs": "^0.2.1",
"browserify": "3.x",
"browserify-shim": "^3.2.2",
"chrome-portfinder": "^0.2.4",
@@ -38,8 +39,7 @@
"keymaster": "git://github.com/feross/keymaster",
"magnet-uri": "1.x",
"read-torrent": "^0.2.0",
- "speedometer": "^0.1.2",
- "brfs": "^0.2.1"
+ "speedometer": "^0.1.2"
},
"devDependencies": {
"nib": "^1.0.2",
@@ -75,4 +75,4 @@
"watch-css": "stylus --use nib css/main.styl --out chrome/ --watch",
"watch-js": "watchify --transform brfs index.js --outfile chrome/bundle.js --debug --verbose"
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.