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>2016-04-21 12:50:16 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-04-21 12:50:16 +0300
commit19617ba502210de4135c2cb1e40c22564d7ee838 (patch)
tree5f38e51907ebf7e2616f5e9289414a57bff023f5 /lib
parent1d51b5b428b791f4766c1d3cb49b5bc457a00656 (diff)
Fix exceptions
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js29
1 files changed, 10 insertions, 19 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index ec1c422..8eb31d0 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -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,7 +1555,7 @@ 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
)
@@ -1572,7 +1563,7 @@ Torrent.prototype._drain = function () {
}
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
)