Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Feature: WebTorrent Integration #3256

Closed
mikeal opened this issue Aug 18, 2016 · 18 comments
Closed

Feature: WebTorrent Integration #3256

mikeal opened this issue Aug 18, 2016 · 18 comments

Comments

@mikeal
Copy link

mikeal commented Aug 18, 2016

It would be great if magnet links downloaded right in the browser. The code to integrate is already quite accessible via WebTorrent.

If you aren't familiar WebTorrent:

  • Works in-browser over WebRTC
  • Works in Node.js over WebRTC and standard Bittorrent protocols and will even act as a bridge node.
  • The desktop client is written for Electron so if you're looking for a place to start it's pretty accessible.

/cc @feross

@feross
Copy link
Contributor

feross commented Aug 19, 2016

Nice idea, @mikeal. This would definitely set Brave apart from other browsers. Built-in torrent support would be really cool, and not that hard to implement with webtorrent.

Here's how this could work:

  • When a magnet link or .torrent file is clicked, initialize a WebTorrent instance add the link.

    var client = new WebTorrent()
    var torrent = client.add(magnetLink)
  • Once the metadata is loaded (usually takes ~2 seconds), list the files in the torrent.

    torrent.once('metadata', function () {
      torrent.files.forEach(function (file) {
        console.log(file.name, file.length) // render the files in the UI
      })
    }
  • When a file is selected, stream that specific file only.

    // Get a Node.js style Readable stream with file data and render it.
    // Pieces needed by the stream will be prioritized highly and fetched from the network.
    file.createReadStream()
  • When the user navigates away, destroy the torrent and (optionally) the WebTorrent client to close all connections and reclaim all resources.

    torrent.destroy()
    client.destroy()

It also probably makes sense to warn the user before starting a torrent on their behalf so they can make an informed decision about whether they wish to join the swarm.

@feross
Copy link
Contributor

feross commented Aug 19, 2016

If you don't want to implement any custom UI, you can actually hack this together really quickly using the torrent.createServer() feature in WebTorrent.

 // create HTTP server for this torrent
var server = torrent.createServer()

// start the server listening to a port
server.listen(port, function () {
  // Navigate the user to http://localhost:<port>/ to see a list of files.

  // Access individual files at http://localhost:<port>/<index> where index is the
  // index in the torrent.files array.

  // As the local http server receives requests for pieces of the file, webtorrent
  // fetches them from the torrent network.
})

More info: https://webtorrent.io/docs

@MylesBorins
Copy link

how hard would it be to make it pipe through a VPN?

@feross
Copy link
Contributor

feross commented Aug 19, 2016

@thealphanerd There is an open PR on WebTorrent to add SOCKS proxy support. Not sure what's required for VPN support.

@MylesBorins
Copy link

MylesBorins commented Aug 19, 2016

@feross I think we will be at some of the same events in the next couple months. maybe we can find time to hack on it ??

[--- Commented from Asana.com
#commenter brad richter
---[aa]

@feross
Copy link
Contributor

feross commented Aug 19, 2016

@thealphanerd That would be fun!

@DiegoRBaquero
Copy link

DiegoRBaquero commented Aug 19, 2016

This would be awesome!

@thealphanerd If the OS is using a VPN everything WebTorrent does should be behind it already. I don't really know if the browsers SOCKS setting would put WebRTC connections behind it, @feross ?

@luixxiul
Copy link
Contributor

Would it be possible to use this feature while IP address leakage via WebRTC is disabled with the fingerprinting protection? / cc: @diracdeltas

#260

@retrohacker
Copy link

retrohacker commented Aug 19, 2016

We could combine this with serving static files from a webtorrent over a custom protocol:

https://github.com/retrohacker/peerweb/blob/master/index.js#L65-L207

@retrohacker
Copy link

Note: the http fallback there is a nasty hack, when electron/electron#4303 lands, a redirect will solve that.

@feross
Copy link
Contributor

feross commented Aug 19, 2016

@luixxiul Yes, WebTorrent should work just fine with the fingerprinting detection in Brave. With that setting enabled, WebRTC just finds detects fewer ip:port candidates. Specifically, it would just use the ip:port of the default route (public IP, or if a VPN is in use, then the VPN's IP). Normally WebRTC finds additional IPs, including the local IP address, but that's just to increase the chances of a successful connection (more possible routes) and to improve the performance of the connection (local routes will be faster than public routes).

tldr: WebTorrent's WebRTC functionality will operate fine with the reduced list of IPs that Brave's fingerprinting mode returns.

@feross
Copy link
Contributor

feross commented Nov 2, 2016

Hey torrent fans! I'm working on adding WebTorrent to Brave with @dcposch over the next couple weeks. Here's the design doc that explains our current plan.

Feedback and comments welcome!

@dcposch dcposch mentioned this issue Nov 2, 2016
5 tasks
@feross
Copy link
Contributor

feross commented Nov 2, 2016

Initial PR to add WebTorrent support is out! #5342

🎉 🎉 🎉

@luixxiul
Copy link
Contributor

Can we close this?

@luixxiul
Copy link
Contributor

Would someone please specify the steps for QA? They must have been specified somewhere in a PR, but it should be clarified here for reference as the QA work should start from the issue, not a PR.

Thanks in advance!

@feross
Copy link
Contributor

feross commented Jan 16, 2017

@luixxiul There's a design doc here that will probably be helpful: https://docs.google.com/document/d/1d_NXJp05gGcy8kYYDcntIRPQaDrvU3CUF-QjEpf0PLI/edit?usp=sharing

Support the following in the Brave desktop app:

  • Handle navigation to magnet links and torrent files. For example:
    • magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel
  • Show torrent content within Brave, without the need for an external torrent app.

@luixxiul
Copy link
Contributor

luixxiul commented Jan 16, 2017

@feross thanks, I didn't know .torrent files were just planned but not supported yet. I was almost creating an issue for it.

@srirambv
Copy link
Collaborator

QA Steps

  1. Open any magnet torrent link
  2. Torrent should start downloading

QA possible once #5981 is fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants