nostr-protocol / nips

Nostr Implementation Possibilities
2.21k stars 523 forks source link

Support Webtorrent for NIP-94 #471

Open heri16 opened 1 year ago

heri16 commented 1 year ago

Support Webtorrent.io flag for NIP-94 so that clients know to use the webtorrent protocol to find peers using the magnet url.

Otherwise a full BitTorrent node is required to proxy to Webtorrent peers (Bittorrent nodes running only on WebRTC).

This greatly reduces centralization for browser-based clients. And saves bandwidth for web-based nostr client operators and hosts.

See: https://webtorrent.io/intro

heri16 commented 1 year ago

What is WebTorrent?

WebTorrent is the first torrent client that works in the browser. YEP, THAT'S RIGHT. THE BROWSER.

It's written completely in JavaScript – the language of the web – and uses WebRTC for true peer-to-peer transport. No browser plugin, extension, or installation is required.

Browser-to-browser communication cuts out the middle-man and lets people communicate on their own terms. No more client/server – just a network of peers, all equal. WebTorrent is the first step in the journey to redecentralize the Web.

See: https://webtorrent.io/faq

heri16 commented 1 year ago

How does WebTorrent work?

The WebTorrent protocol works just like BitTorrent protocol, except it uses WebRTC instead of TCP/uTP as the transport protocol.

In order to support WebRTC's connection model, we made a few changes to the tracker protocol. Therefore, a browser-based WebTorrent client or "web peer" can only connect to other clients that support WebTorrent/WebRTC.

heri16 commented 1 year ago

Why wasn't WebTorrent designed as an entirely-new, modern protocol?

BitTorrent is the most successful, most widely-deployed P2P protocol in existence. It works really well. Our goal with WebTorrent was to bring BitTorrent to the web in a way that interoperates with the existing torrent network.

Re-inventing the protocol would have made WebTorrent fundamentally incompatible with existing clients and prevented adoption. The way we've done it is better. The wire protocol is exactly the same, but there's now a new way to connect to peers: WebRTC, in addition to the existing TCP and uTP.

fiatjaf commented 1 year ago

It's already supported.

heri16 commented 1 year ago

There are three types of Bittorrent Trackers:

If the tracker is not specified in the magnet URI, BEP9 says Bitcoin's DHT SHOULD be used, which requires UDP.

Are all NIP94 nostr clients expected to support HTTP, UDP, WS and DHT?

What is the expected behaviour for nostr web clients that do not support UDP, when they encounter a magnet link requiring UDP?

Also, what is the expected behaviour for nostr desktop/mobile clients that do not support WS tracker, when they encounter a magnet link requiring WS tracker support?

heri16 commented 1 year ago

Unsure if NIP-94's language needs to be prescriptive on the expected behavior (if the mandatory NIP94 event url returns a 404, but the magnet link points to a tracker, but the client is unable to connect to confirm that seeders are available).

How would end users differentiate between "Not found" and "Not supported"?

fiatjaf commented 1 year ago

I think the NIP language can be vastly improved, but that it should say it is all a client's choice of what to support and what not to support.

It should also say NIP-94 is not expected to be implemented in "social" clients, only in dedicated filesharing clients.