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
Prev

fix more bugs

  • Loading branch information
feross committed Apr 21, 2016
commit fa2a6c541849853ded575b95ee424ab94c0936a4
@@ -278,21 +278,24 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
else cb(null, item)
}
}), function (err, input) {
if (err) return torrent._destroy(err)
if (self.destroyed) return
if (err) return torrent._destroy(err)

createTorrent.parseInput(input, opts, function (err, files) {
if (err) return torrent._destroy(err)
if (self.destroyed) return
streams = files.map(function (file) { return file.getStream })
if (err) return torrent._destroy(err)

streams = files.map(function (file) {
return file.getStream
})

createTorrent(input, opts, function (err, torrentBuf) {
if (err) return torrent._destroy(err)
if (self.destroyed) return
if (err) return torrent._destroy(err)

var existingTorrent = self.get(torrentBuf)
if (existingTorrent) {
torrent._destroy(new Error('Cannot add duplicate torrent ' + torrent.infoHash))
_onseed(existingTorrent)
torrent._destroy(new Error('Cannot add duplicate torrent ' + existingTorrent.infoHash))
} else {
torrent._onTorrentId(torrentBuf)
}
@@ -1,5 +1,3 @@
// TODO: cleanup event listeners

/* global URL, Blob */

module.exports = Torrent
@@ -315,25 +313,34 @@ Torrent.prototype._onListening = function () {
tracker: self.client.tracker && trackerOpts,
port: self.client.torrentPort
})
self.discovery.on('error', function (err) {

self.discovery.on('error', onError)
self.discovery.on('peer', onPeer)
self.discovery.on('trackerAnnounce', onTrackerAnnounce)
self.discovery.on('dhtAnnounce', onDHTAnnounce)
self.discovery.on('warning', onWarning)

function onError (err) {
self._destroy(err)
})
self.discovery.on('peer', function (peer) {
}

function onPeer (peer) {
// Don't create new outgoing TCP connections when torrent is done
if (typeof peer === 'string' && self.done) return
self.addPeer(peer)
})
}

// expose discovery events
self.discovery.on('trackerAnnounce', function () {
function onTrackerAnnounce () {
self.emit('trackerAnnounce')
})
self.discovery.on('dhtAnnounce', function () {
}

function onDHTAnnounce () {
self.emit('dhtAnnounce')
})
self.discovery.on('warning', function (err) {
}

function onWarning (err) {
self.emit('warning', err)
})
}

// if full metadata was included in initial torrent id, use it immediately. Otherwise,
// wait for torrent-discovery to find peers and ut_metadata to get the metadata.
@@ -611,7 +618,7 @@ Torrent.prototype.addPeer = function (peer) {

if (host && self.client.blocked.contains(host)) {
self._debug('ignoring peer: blocked %s', peer)
if (typeof peer === 'string') peer.destroy()
if (typeof peer !== 'string') peer.destroy()
self.emit('blockedPeer', peer)
return false
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.