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

Implements BEP53 to allow file selection using &so in magnetURIs #1396

Merged
merged 2 commits into from May 18, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Implements BEP53 to allow file selection using &so in magnetURI.

  • Loading branch information
SilentBot1 committed May 18, 2018
commit abc2051b886d3ea64408574327ff63792796789f
@@ -30,6 +30,7 @@ var speedometer = require('speedometer')
var uniq = require('uniq')
var utMetadata = require('ut_metadata')
var utPex = require('ut_pex') // browser exclude
var parseRange = require('parse-numeric-range')

var File = require('./file')
var Peer = require('./peer')
@@ -482,11 +483,6 @@ Torrent.prototype._onMetadata = function (metadata) {
})
}

// start off selecting the entire torrent with low priority
if (self.pieces.length !== 0) {
self.select(0, self.pieces.length - 1, false)
}

self._rarityMap = new RarityMap(self)

self.store = new ImmediateChunkStore(
@@ -509,6 +505,22 @@ Torrent.prototype._onMetadata = function (metadata) {
return new File(self, file)
})

// Only select specified files (BEP53)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

Can you add an actual link to the BEP in this comment?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

Can do, included in next commit.

if (self.so) {
var specificFiles = parseRange.parse(self.so)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

Can we name this variable selectOnlyFiles, since "so" stands for "select only"?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

Of course, that would also make it more clear for people searching the code.

// https://github.com/webtorrent/webtorrent/issues/164
self.deselect(0, self.pieces.length - 1, false)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

I believe that this line should not be necessary since you moved the self.select(0, self.pieces.length - 1, false) call to an else block below. So, what is this actually deselecting?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

Initially I had the if (self.so) statement under self.select all without the else statement, this is leftover code from that which can be removed, removed in next commit.


self.files.forEach(function (v, i) {
specificFiles.indexOf(i) === -1 ? self.files[i].deselect() : self.files[i].select(true)

This comment has been minimized.

Copy link
@feross

feross May 18, 2018

Member

Unless I'm missing something, it shouldn't be necessary to call deselect() since all files start out deselected. Can we change this to just call select()?

Also, can you using array.includes() instead of array.indexOf() since it's clearer?

This comment has been minimized.

Copy link
@SilentBot1

SilentBot1 May 18, 2018

Author Member

You're correct, the self.files[i].deselect() serves no purpose as pieces start out deselected, this will be removed in the next commit.

Replacing specificFiles.indexOf(i) with selectOnlyFiles.includes(i) for clarity will also be in the next commit.

Thank you for the review :)

})
} else {
// start off selecting the entire torrent with low priority
if (self.pieces.length !== 0) {
self.select(0, self.pieces.length - 1, false)
}
}

self._hashes = self.pieces

self.pieces = self.pieces.map(function (hash, i) {
@@ -42,6 +42,7 @@
"mime": "^2.2.0",
"multistream": "^2.0.5",
"package-json-versionify": "^1.0.2",
"parse-numeric-range": "^0.0.2",
"parse-torrent": "^6.0.0",
"pump": "^3.0.0",
"random-iterate": "^1.0.1",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.