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

Get Peers without downloading file #1397

Closed
GooG2e opened this issue May 18, 2018 · 1 comment
Closed

Get Peers without downloading file #1397

GooG2e opened this issue May 18, 2018 · 1 comment
Labels

Comments

@GooG2e
Copy link

@GooG2e GooG2e commented May 18, 2018

Hello!
I have a question - can webtorrent looking for peers without downloading
I think this can speed up init - user opens web page and peer search initialize and when it start playing then we have peers and can instantly use them

@GooG2e GooG2e closed this May 18, 2018
@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented May 18, 2018

Hey @GooG2e,

To search for peers, you must know the infoHash of the torrent you are looking for, because of this the torrent must always be added to the client, but you can disable the downloading of the torrent when it's added to the client, allowing the discovery and connection to peers, but preventing downloading anything till you need it.

You could achieve this two ways, firstly manually deselecting the torrent:

var sintel = 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent'
var torrent = client.add(sintel)
torrent.on('metadata', t=>{
  // Deselect all pieces so nothing is downloaded.
  t.deselect(0, t.pieces.length - 1, false)
})

Secondly this could be achieved with the newly implemented BEP, BEP 53, you could specify the magnetURI parameter &so to &so= and it would have the same affect as the code example above, though is a new feature so would require installing WebTorrent from GitHub while we wait for a new version to be pushed to npm, because of this I would recommend the first method in the meanwhile.

var sintel = 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent'
// Select no files to download
var selectOnly = '&so='
var torrent = client.add(sintel + selectOnly)

Both examples given will start downloading the needed pieces when file.appendTo() or file.renderTo() are called.

All the best :)

@feross feross added the question label May 18, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.