Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Many fixes; all leaks fixed #762

Merged
merged 12 commits into from Apr 22, 2016

set dhtPort to correct port after listening

  • Loading branch information
feross committed Apr 21, 2016
commit 08baee2ddd7a194d44fc797e704b7a6b71304423
@@ -7,6 +7,9 @@
- `client.listening` property to signal whether TCP server is listening for incoming
connections.

- `client.dhtPort` property reflects the actual DHT port when user doesn't specify one
(this is parallel to `client.torrentPort` for the TCP torrent listening server)

### Changed

- Merged `Swarm` class into `Torrent` object. Properties on `torrent.swarm` (like
@@ -1,5 +1,4 @@
// TODO: cleanup event listeners
// TODO: set dhtPort to correct port

module.exports = WebTorrent

@@ -70,6 +69,7 @@ function WebTorrent (opts) {
self.destroyed = false
self.listening = false
self.torrentPort = opts.torrentPort || 0
self.dhtPort = opts.dhtPort || 0
self.tracker = opts.tracker !== undefined ? opts.tracker : true
self.torrents = []
self.maxConns = Number(opts.maxConns) || 55
@@ -95,11 +95,15 @@ function WebTorrent (opts) {
self.dht.once('error', function (err) {
self._destroy(err)
})
self.dht.once('listening', function () {
var address = self.dht.address()
if (address) self.dhtPort = address.port
})

// Ignore warning when there are > 10 torrents in the client
self.dht.setMaxListeners(0)

self.dht.listen(opts.dhtPort)
self.dht.listen(self.dhtPort)
} else {
self.dht = false
}
@@ -387,7 +391,8 @@ WebTorrent.prototype._onListening = function () {
if (this._tcpPool) {
// Sometimes server.address() returns `null` in Docker.
// WebTorrent issue: https://github.com/feross/bittorrent-swarm/pull/18
this.torrentPort = (this._tcpPool.server.address() || { port: 0 }).port
var address = this._tcpPool.server.address()
if (address) this.torrentPort = address.port
}

this.emit('listening')
@@ -7,7 +7,7 @@ var test = require('tape')
var WebTorrent = require('../../')

test('Download using DHT (via magnet uri)', function (t) {
t.plan(11)
t.plan(12)

var dhtServer = new DHT({ bootstrap: false })

@@ -27,6 +27,10 @@ test('Download using DHT (via magnet uri)', function (t) {
dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port, host: networkAddress.ipv4() }
})

client1.dht.on('listening', function () {
t.equal(client1.dhtPort, client1.dht.address().port)
})

client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

@@ -6,7 +6,7 @@ var test = require('tape')
var WebTorrent = require('../../')

test('Download using DHT (via .torrent file)', function (t) {
t.plan(8)
t.plan(9)

var dhtServer = new DHT({ bootstrap: false })

@@ -26,6 +26,10 @@ test('Download using DHT (via .torrent file)', function (t) {
dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
})

client1.dht.on('listening', function () {
t.equal(client1.dhtPort, client1.dht.address().port)
})

client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.