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
error handling for duplicate torrents #351
Closed
+56
−2
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
Loading status checks…
error handling for duplicate torrents
- Loading branch information
Tristan Davies
committed
Jun 7, 2015
commit 2cc2ab46195866ac60ef604a98793b53845680cb
| @@ -168,8 +168,17 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) { | ||
| if (ontorrent) self.on('torrent', clientOnTorrent) | ||
|
|
||
| torrent.on('error', function (err) { | ||
| self.emit('error', err, torrent) | ||
| self.remove(torrent) | ||
| var alreadyExistsMessage = 'There is already a swarm with info hash' | ||
| if (ontorrent && err.message && err.message.substr(0, alreadyExistsMessage.length) === alreadyExistsMessage) { | ||
|
||
| self.torrents.splice(self.torrents.indexOf(torrent), 1) | ||
madd512
Author
|
||
| torrent = self.torrents.filter(function (_torrent) { | ||
| return torrent.infoHash === _torrent.infoHash | ||
| })[0] | ||
| process.nextTick(clientOnTorrent.bind(null, torrent)) | ||
|
||
| } else { | ||
| self.emit('error', err, torrent) | ||
| self.remove(torrent) | ||
| } | ||
| }) | ||
|
|
||
| torrent.on('listening', function (port) { | ||
| @@ -0,0 +1,45 @@ | ||
| var fs = require('fs') | ||
| var test = require('tape') | ||
| var WebTorrent = require('../') | ||
|
|
||
| var leavesBook = fs.readFileSync(__dirname + '/content/Leaves of Grass by Walt Whitman.epub') | ||
|
|
||
| test('client.seed followed by duplicate client.add', function (t) { | ||
| t.plan(2) | ||
|
|
||
| var opts = { | ||
| name: 'Leaves of Grass by Walt Whitman.epub' | ||
| } | ||
|
|
||
| var client = new WebTorrent({ dht: false, tracker: false }) | ||
| client.seed(leavesBook, opts, function (torrent1) { | ||
| client.add(torrent1.infoHash, function (torrent2) { | ||
| t.equal(torrent1.infoHash, torrent2.infoHash) | ||
| t.equal(client.torrents.length, 1) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| test('client.seed followed by duplicate client.add, twice', function (t) { | ||
| t.plan(4) | ||
|
|
||
| var opts = { | ||
| name: 'Leaves of Grass by Walt Whitman.epub' | ||
| } | ||
|
|
||
| var client = new WebTorrent({ dht: false, tracker: false }) | ||
|
|
||
| client.seed(leavesBook, opts, function (torrent1) { | ||
| client.add(torrent1.infoHash, function (torrent2) { | ||
| t.equal(torrent1.infoHash, torrent2.infoHash) | ||
| t.equal(client.torrents.length, 1) | ||
| }) | ||
| }) | ||
|
|
||
| client.seed(leavesBook, opts, function (torrent1) { | ||
| client.add(torrent1.infoHash, function (torrent2) { | ||
| t.equal(torrent1.infoHash, torrent2.infoHash) | ||
| t.equal(client.torrents.length, 1) | ||
| }) | ||
| }) | ||
| }) |
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Is it okay for this line to be this long?