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

torrent: throw on use after destroy #546

Merged
merged 1 commit into from Dec 29, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

torrent: throw on use after destroy

  • Loading branch information
feross committed Dec 28, 2015
commit 5194e8bfc03db491e53df51b993bfd06200a94bc
@@ -448,6 +448,7 @@ Torrent.prototype.destroy = function (cb) {
*/
Torrent.prototype.addPeer = function (peer) {
var self = this
if (self.destroyed) throw new Error('torrent is destroyed')

function addPeer () {
self.swarm.addPeer(peer)
@@ -472,9 +473,9 @@ Torrent.prototype.addPeer = function (peer) {
* @param {string} url web seed url
*/
Torrent.prototype.addWebSeed = function (url) {
var self = this
if (this.destroyed) throw new Error('torrent is destroyed')
debug('add web seed %s', url)
self.swarm.addWebSeed(url, self)
this.swarm.addWebSeed(url, this)
}

/**
@@ -487,6 +488,8 @@ Torrent.prototype.addWebSeed = function (url) {
*/
Torrent.prototype.select = function (start, end, priority, notify) {
var self = this
if (self.destroyed) throw new Error('torrent is destroyed')

if (start > end || start < 0 || end >= self.pieces.length) {
throw new Error('invalid selection ', start, ':', end)
}
@@ -518,6 +521,8 @@ Torrent.prototype.select = function (start, end, priority, notify) {
*/
Torrent.prototype.deselect = function (start, end, priority) {
var self = this
if (self.destroyed) throw new Error('torrent is destroyed')

priority = Number(priority) || 0
debug('deselect %s-%s (priority %s)', start, end, priority)

@@ -540,6 +545,8 @@ Torrent.prototype.deselect = function (start, end, priority) {
*/
Torrent.prototype.critical = function (start, end) {
var self = this
if (self.destroyed) throw new Error('torrent is destroyed')

debug('critical %s-%s', start, end)

for (var i = start; i <= end; ++i) {
@@ -1179,6 +1186,8 @@ Torrent.prototype._checkDone = function () {

Torrent.prototype.load = function (streams, cb) {
var self = this
if (self.destroyed) throw new Error('torrent is destroyed')

if (!Array.isArray(streams)) streams = [ streams ]
if (!cb) cb = noop

@@ -1198,10 +1207,11 @@ Torrent.prototype.load = function (streams, cb) {
}

Torrent.prototype.createServer = function (opts) {
var self = this
if (this.destroyed) throw new Error('torrent is destroyed')

if (typeof Server !== 'function') throw new Error('node.js-only method')
var server = new Server(self, opts)
self._servers.push(server)
var server = new Server(this, opts)
this._servers.push(server)
return server
}

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