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

Fix exceptions

  • Loading branch information
feross committed Apr 21, 2016
commit 19617ba502210de4135c2cb1e40c22564d7ee838
@@ -628,11 +628,8 @@ Torrent.prototype.addPeer = function (peer) {
Torrent.prototype._addPeer = function (peer) {
var self = this
if (self.destroyed) {
if (typeof peer === 'string') {
self._debug('ignoring peer: torrent is destroyed')
} else {
peer.destroy(new Error('torrent is destroyed'))
}
self._debug('ignoring peer: torrent is destroyed')
if (typeof peer !== 'string') peer.destroy()
return null
}
if (typeof peer === 'string' && !self._validAddr(peer)) {
@@ -642,20 +639,14 @@ Torrent.prototype._addPeer = function (peer) {

var id = (peer && peer.id) || peer
if (self._peers[id]) {
if (typeof peer === 'string') {
self._debug('ignoring peer: duplicate (%s)', id)
} else {
peer.destroy(new Error('duplicate peer ' + id))
}
self._debug('ignoring peer: duplicate (%s)', id)
if (typeof peer !== 'string') peer.destroy()
return null
}

if (self.paused) {
if (typeof peer === 'string') {
self._debug('ignoring peer: torrent is paused')
} else {
peer.destroy(new Error('torrent is paused'))
}
self._debug('ignoring peer: torrent is paused')
if (typeof peer !== 'string') peer.destroy()
return null
}

@@ -712,8 +703,8 @@ Torrent.prototype.addWebSeed = function (url) {
*/
Torrent.prototype._addIncomingPeer = function (peer) {
var self = this
if (self.destroyed) return peer.destroy(new Error('torrent is destroyed'))
if (self.paused) return peer.destroy(new Error('torrent is paused'))
if (self.destroyed) return peer._destroy(new Error('torrent is destroyed'))
if (self.paused) return peer._destroy(new Error('torrent is paused'))

this._debug('add incoming peer %s', peer.id)

@@ -1564,15 +1555,15 @@ Torrent.prototype._drain = function () {
// TODO: If torrent is done, do not try to reconnect after a timeout

if (peer.retries >= RECONNECT_WAIT.length) {
this._debug(
self._debug(
'conn %s closed: will not re-add (max %s attempts)',
peer.addr, RECONNECT_WAIT.length
)
return
}

var ms = RECONNECT_WAIT[peer.retries]
this._debug(
self._debug(
'conn %s closed: will re-add to queue in %sms (attempt %s)',
peer.addr, ms, peer.retries + 1
)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.