-
Notifications
You must be signed in to change notification settings - Fork 93
feat: webrtc #264
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
Merged
Merged
feat: webrtc #264
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0dbdd54
init webrtc content
salmad3 a347f48
enhance + edits
salmad3 a0aebe5
Apply suggestions from code review
salmad3 196958d
incorporate PR feedback
salmad3 24e6faa
Apply suggestions from code review
salmad3 79b7f1b
incorporate PR feedback; simplify content and reorg content + edits
salmad3 22e8044
update webtransport comparison + edits
salmad3 4c0634d
edits
salmad3 0cb9683
Apply suggestions from code review
salmad3 5139024
rmv duplicate paragraph
salmad3 7ecf79f
Apply suggestions from code review
salmad3 3671a89
incorporate remaining PR feedback
salmad3 32ebbb3
incorporate feedback and improve NAT bullet point
salmad3 43b654f
incorporate PR feedback + simplify and edits
salmad3 ef5dd1b
Apply suggestions from code review
salmad3 e856b80
Apply suggestions from code review
salmad3 334eca2
incorporate PR feedback; edits, lint, update features with SDP
salmad3 fc9028b
add link to signaling protocol wiki pg
salmad3 68cf4c0
incorporate remaining feedback and polish
salmad3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,131 @@ | ||
--- | ||
title: "WebRTC" | ||
description: "WebRTC is a new specification that uses QUIC to offer an alternative to WebSocket. Conceptually, it can be considered WebSocket over QUIC.Learn about WebTransport and how it is used in libp2p." | ||
description: "WebRTC is a protocol for real-time communication and is used to establish connections between browsers and other nodes." | ||
weight: 110 | ||
aliases: | ||
- "/concepts/transports/webrtc" | ||
--- | ||
|
||
Coming soon! | ||
## What is WebRTC? | ||
|
||
[WebRTC (Web Real-Time Communications)](https://webrtc.org/) is a framework for real-time | ||
communication and in libp2p is used to establish browser-to-server and browser-to-browser | ||
connections between applications. | ||
|
||
WebRTC was originally designed to make audio, video, and data | ||
communication between browsers user-friendly and easy to implement. | ||
It was first developed by [Global IP Solutions (or GIPS)](http://www.gipscorp.com/). | ||
In 2011, GIPS was acquired by Google where the [W3C](https://www.w3.org/) started to work | ||
on a standard for WebRTC. | ||
|
||
It serves as a good choice for applications that need built-in support | ||
for media communication and do not have specific requirements for the underlying | ||
transport protocol. | ||
|
||
## WebRTC in libp2p | ||
|
||
In libp2p, WebRTC is used as a transport protocol to connect from browsers to other nodes. | ||
However, libp2p does not make use of any of WebRTC's multimedia features. | ||
The features employed in libp2p are: | ||
|
||
### Key features | ||
|
||
- Peer connections: WebRTC enables | ||
[direct peer-to-peer connections](https://webrtc.org/getting-started/peer-connections) | ||
between browsers and other nodes. | ||
|
||
- Data channels: WebRTC provides peer-to-peer [data channels](https://developer.mozilla.org/en-US/docs/Games/Techniques/WebRTC_data_channels), | ||
which works on | ||
[SCTP (Stream Control Transmission Protocol)](https://en.wikipedia.org/wiki/Stream_Control_Transmission_Protocol) and use [SDP (Session Description Protocol)](https://en.wikipedia.org/wiki/Session_Description_Protocol) to negotiate the parameters of the data channel. | ||
|
||
A WebRTC data channel allows applications to send a text or binary data over an active connection | ||
to a peer. This means libp2p can utilize data channels as a transport to send raw data to peers and | ||
enables applications to build anything they like. | ||
|
||
- [NAT traversal](../nat/overview): WebRTC includes mechanisms (like | ||
[ICE](https://datatracker.ietf.org/doc/rfc5245/)) to connect to nodes that run behind | ||
NATs and firewalls. In non-decentralized WebRTC, this can be facilitated by a | ||
[TURN server.](https://webrtc.org/getting-started/turn-server), | ||
but other signaling channels, such as WebSocket running on a central server, can also be used. | ||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Using a custom [signaling protocol](https://en.wikipedia.org/wiki/Signaling_protocol) or a | ||
different signaling service is also possible. | ||
|
||
- Security: WebRTC connections are encrypted using | ||
[DTLS](https://en.wikipedia.org/wiki/Datagram_Transport_Layer_Security). DTLS is similar to TLS but is | ||
designed to work on an unreliable transport instead of an ordered byte stream like TCP. | ||
|
||
- API: Browsers expose an API to establish WebRTC connections. The | ||
[`RTCPeerConnection`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) | ||
API allows two applications on different endpoints to communicate. | ||
|
||
### Browser-to-Server | ||
|
||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The first use case supported by a native WebRTC transport in libp2p is browser-to-server | ||
(as described in the [specifications](https://github.com/libp2p/specs/tree/master/webrtc#browser-to-public-server)). | ||
|
||
libp2p WebRTC enables browsers nodes to connect to public server nodes without those | ||
endpoints providing a [TLS certificate](https://aws.amazon.com/what-is/ssl-certificate/) | ||
within the browser's trustchain. | ||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{{< alert icon="" context="info">}} | ||
"When connecting to a WebSocket server, browsers require the server to present a TLS certificate | ||
signed by a trusted certificate authority (CA). Few libp2p nodes meet this requirement, primarily | ||
because it's hard to get a certificate in a decentralized manner. This is the reason that WebSocket | ||
never saw widespread adoption in the libp2p network. WebRTC | ||
(and [WebTransport](#comparing-webrtc-and-webtransport)) supports encrypted communication without | ||
requiring a signed certificate from a trusted CA. | ||
{{< /alert >}} | ||
|
||
In libp2p: | ||
|
||
- WebRTC multiaddresses are composed of a standard UDP multiaddr, | ||
followed by `webrtc` and the `multihash` of the certificate that | ||
the node uses, as such: | ||
`/ip4/1.2.3.4/udp/1234/webrtc/certhash/<hash>/p2p/<peer-id>`; | ||
- WebRTC encrypts connections using DTLS. However, an additional handshake is required to | ||
authenticate a peer's peer ID once the WebRTC connection has been established. | ||
- A browser can connect to a server node without needing a trusted TLS | ||
certificate. | ||
|
||
Contrary to the standard WebRTC handshake process, the browser and server do not | ||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exchange the SDP Offer and Answer. Instead, they employ a technique known as | ||
[SDP munging](https://webrtc.github.io/samples/src/content/peerconnection/munge-sdp/). | ||
This technique allows the browser node to simulate the exchange of an SDP, but in reality, | ||
it constructs it locally using the information provided by the server node's multiaddress. | ||
|
||
When establishing a WebRTC connection, the browser and server perform a standard DTLS | ||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
handshake as part of the connection setup. Of the three primary focuses of information | ||
security, a successful DTLS handshake only provides two: confidentiality and integrity. | ||
Authenticity is achieved by succeeding the | ||
[Noise handshake](../secure-comm/noise) following the DTLS handshake. | ||
|
||
<!-- TO ADD DIAGRAM --> | ||
|
||
### Coming soon: Browser-to-Browser | ||
|
||
Eventually, libp2p will have support for communication between two | ||
browsers. | ||
|
||
The technical specification and initial implementations of WebRTC | ||
Browser-to-Browser connectivity is planned for release in early 2023. | ||
Track the progress [here](https://github.com/libp2p/specs/issues/475). | ||
|
||
<!-- TO ADD DIAGRAM --> | ||
|
||
{{< alert icon="💡" context="note" text="See the WebRTC <a class=\"text-muted\" href=\"https://github.com/libp2p/specs/blob/master/webrtc/README.md\">technical specification</a> for more details." />}} | ||
|
||
## Comparing WebRTC and WebTransport | ||
|
||
In general, WebRTC was primarily built for in-browser audio and video communication, | ||
whereas WebTransport aims to offer a general-purpose bidirectional byte-stream interface | ||
between a browser and a server. | ||
|
||
Regarding connectivity, WebTransport only supports client-server connections, | ||
while WebRTC supports peer-to-peer connections. WebRTC is also more complex, as many | ||
underlying protocols are involved in creating a connection, as opposed to WebTransport, | ||
which only depends on QUIC. | ||
|
||
Check out the | ||
[WebTransport](https://connectivity.libp2p.io/#webtransport) and | ||
[WebRTC](https://connectivity.libp2p.io/#webrtc) sections of the libp2p | ||
connectivity site to learn more. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.