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

Implement exact source (xs) for magnet URIs #799

Merged
merged 1 commit into from May 19, 2016

Conversation

@Sebmaster
Copy link
Contributor

Sebmaster commented May 13, 2016

Since I saw #714 stalled a bit, I wanted to check in if no one's working on this and started off with a minimal working prototype.

I know I still need to move the fixture over (also don't rely on webtorrent.io, but create a local server instead) to the other repo, but does this look okay / is anyone else working on this?

@Sebmaster Sebmaster force-pushed the Sebmaster:feature/magnet-xs branch 3 times, most recently from 1bfa128 to 0b814ae May 13, 2016
try {
this._xsRequest = get.concat(opts, function (err, res, torrent) {
if (err || !torrent.length) return

This comment has been minimized.

Copy link
@feross

feross May 13, 2016

Member

Should check that res.statusCode === 200

@feross

This comment has been minimized.

Copy link
Member

feross commented May 13, 2016

Just took a quick look. Looks pretty good to me. I don't think we to/can easily support ftp:// so I would remove that test case.

@Sebmaster Sebmaster force-pushed the Sebmaster:feature/magnet-xs branch from 0b814ae to fc3c472 May 13, 2016
@Sebmaster

This comment has been minimized.

Copy link
Contributor Author

Sebmaster commented May 13, 2016

Fixed.

I don't think we to/can easily support ftp:// so I would remove that test case.

I added that mainly to check if unsupported protocols would crash the process, since the spec says to silently ignore.

@feross

This comment has been minimized.

Copy link
Member

feross commented May 13, 2016

I think we should check for http:// https:// explicitly before passing into simple-get. That would be more reliable and we could get rid of the try-catch around simple-get, right?

@Sebmaster Sebmaster force-pushed the Sebmaster:feature/magnet-xs branch from fc3c472 to 7d5383c May 13, 2016
@Sebmaster

This comment has been minimized.

Copy link
Contributor Author

Sebmaster commented May 13, 2016

Done.

That would be more reliable and we could get rid of the try-catch around simple-get, right?

For the protocol case yeah, just hope there's nothing else http will throw on...

@Sebmaster Sebmaster force-pushed the Sebmaster:feature/magnet-xs branch 4 times, most recently from ef86e35 to 8288c3b May 13, 2016
@Sebmaster

This comment has been minimized.

Copy link
Contributor Author

Sebmaster commented May 13, 2016

Okay, also migrated the tests over to a local server and reused the fixtures from webtorrent-fixtures. Should be ready (for xs, at least).

@Sebmaster Sebmaster force-pushed the Sebmaster:feature/magnet-xs branch 2 times, most recently from 2162641 to 9b2335a May 14, 2016
@Sebmaster Sebmaster force-pushed the Sebmaster:feature/magnet-xs branch from 9b2335a to d498f11 May 17, 2016
@feross

This comment has been minimized.

Copy link
Member

feross commented May 18, 2016

Thanks -- will take a look after getting WebTorrent Desktop v0.5 out.

@Sebmaster

This comment has been minimized.

Copy link
Contributor Author

Sebmaster commented May 18, 2016

I just checked the malformed URL case some more - a URL like http://example.org:2455665555/ would now crash, which isn't great, so I'm thinking leaving the try / catch there would be better (either instead, or in addition to the protocol check).


if (parsedTorrent.xs && !self.info) {
// TODO: Could try multiple in parallel here
var src = parsedTorrent.xs instanceof Array ? parsedTorrent.xs[0] : parsedTorrent.xs

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

Array.isArray() is the right way to check if something is an Array.

}
}
this._xsRequest = get.concat(opts, function (err, res, torrent) {
if (err || res.statusCode !== 200 || !torrent.length) return

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

No need to check for !torrent.length since that will make parseTorrent throw below anyway.

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

Would be nice to add a log here with debug for debugging purposes.


if (parsedTorrent) {
if (parsedTorrent.infoHash !== self.infoHash) {
return

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

Debug log here too

if (self._xsRequest) {
self._xsRequest.abort()
self._xsRequest = null
}

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

This should go after the next line.


createServer(fixtures.leaves.torrent, function (url, next) {
client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent(url), function (torrent) {
t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub')

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

The name is also in the magnet URI as the &dn parameter. Might be better to check for another parameter.

var client = new WebTorrent({ dht: false, tracker: false })
client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'))
setTimeout(function () {
t.ok(true, 'no crash')

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

No need for this. The tests will fail if there's a thrown exception. We should add listeners for 'error' and 'warning' events to all these tests though.

This comment has been minimized.

Copy link
@feross

feross May 19, 2016

Member

Nevermind, I see what you were doing.

@feross feross merged commit 3894024 into webtorrent:master May 19, 2016
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Sebmaster

This comment has been minimized.

Copy link
Contributor Author

Sebmaster commented May 19, 2016

I totally fixed all of those just now 😄

Also what about the try-catch situation with malformed urls?

@feross

This comment has been minimized.

Copy link
Member

feross commented May 19, 2016

Ah, thanks. I'm fixing all that up too. Sorry, should have communicated that better.

@feross

This comment has been minimized.

Copy link
Member

feross commented May 19, 2016

I'm adding support for multiple &xs= params too.

feross added a commit that referenced this pull request May 19, 2016
- Support multiple &xs= params in parallel
- Fail on 'error' 'warning' events
@feross

This comment has been minimized.

Copy link
Member

feross commented May 19, 2016

feross added a commit that referenced this pull request May 19, 2016
Fixes for PR #799
@lock

This comment has been minimized.

Copy link

lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.