@@ -218,6 +218,90 @@ two nodes using QUIC only takes a single RTT.
218
218
Following the multiaddress format described earlier, a standard QUIC connection will
219
219
look like: ` /ip4/127.0.0.1/udp/65432/quic/ ` .
220
220
221
+ ## WebTransport
222
+
223
+ While browsers perform HTTP request using HTTP/3, so far they don't offer an API to allow applications
224
+ to gain access to the underlying QUIC stream.
225
+ WebTransport is a new specification that uses QUIC to offer an alternative to
226
+ WebSocket. Conceptually, it can be considered WebSocket over QUIC.
227
+ It allows browsers to establish a stream-multiplexed and bidirectional connection
228
+ to servers, and use streams to send and receive application data.
229
+
230
+ While WebSocket provides a single bidirectional, full-duplex communication between a
231
+ browser and a server over a TCP connection, WebTransport exposes allows the endpoints to use multiple
232
+ streams in parallel.
233
+
234
+ When connecting to a WebSocket server, browsers require the server to present a
235
+ TLS certificate signed by a trusted CA (certificate authority). Few nodes have such
236
+ a certificate, which is the reason that WebSocket never saw widespread adoption in the
237
+ libp2p network. libp2p WebTransport offers a browser API that includes a way to
238
+ accept the server's certificate by checking the (SHA-256) hash of the certificate
239
+ (using the
240
+ [ ` serverCertificateHashes ` option] ( https://www.w3.org/TR/webtransport/#dom-webtransportoptions-servercertificatehashes ) ),
241
+ even if the certificate is "just" a self-signed certificate. This allows us to connect
242
+ any browser node to any server node, as long as the browser knows the certificate hash in
243
+ advance (see [ WebTransport in libp2p] ( #webtransport-in-libp2p ) for how WebTransport addresses
244
+ achieve this).
245
+
246
+ Therefore, WebTransport exhibits all the advantages of QUIC over TCP, that being
247
+ faster handshakes, no HoL blocking, and being future-proof.
248
+
249
+ {{% notice "caution" %}}
250
+
251
+ There is an experimental WebTransport transport in go-libp2p that is part
252
+ of the [ v0.23 release] ( https://github.com/libp2p/go-libp2p/releases/tag/v0.23.0 ) .
253
+ The implementation should be used experimentally and is not recommended for production
254
+ environments.
255
+
256
+ js-libp2p also plans to release
257
+ [ WebTransport support] ( https://github.com/libp2p/js-libp2p-webtransport ) very soon.
258
+
259
+ There are currently no concrete plans to support WebTransport beyond the Go and JS
260
+ implementations.
261
+
262
+ {{% /notice %}}
263
+
264
+ For network stacks like libp2p, WebTransport is a pluggable
265
+ protocol that fits well with a modular network design.
266
+
267
+ For a standard WebSocket connection, the roundtrips required are as follows:
268
+
269
+ - 1 RTT for TCP handshake
270
+ - 1 RTT for TLS 1.3 handshake
271
+ - 1 RTT for WebSocket upgrade
272
+ - 1 RTT for multistream security negotiation (Noise or TLS 1.3)
273
+ - 1 RTT for security handshake (Noise or TLS 1.3)
274
+ - 1 RTT for multistream muxer negotiation (mplex or yamux)
275
+
276
+ In total, 6 RTTs.
277
+
278
+ WebTransport running over QUIC only requires 3 RTTs, as:
279
+
280
+ - 1 RTT for QUIC handshake
281
+ - 1 RTT for WebTransport handshake
282
+ - 1 RTT for libp2p handshake; one for multistream and one for authentication
283
+ (with a Noise handshake)
284
+
285
+ In principle, the WebTransport protocol would even allow running the WebTransport
286
+ handshake and the Noise handshake in parallel. However, this is currently not
287
+ possible since the [ browser API doesn't allow that yet] ( https://github.com/w3c/webtransport/issues/409 ) .
288
+
289
+ ### WebTransport in libp2p
290
+
291
+ WebTransport multiaddresses are composed of a QUIC multiaddr, followed
292
+ by ` /webtransport ` and a list of multihashes of the node certificates that the server uses.
293
+
294
+ For instance, for multiaddress ` /ip4/127.0.0.1/udp/123/quic/webtransport/certhash/<hash1> ` ,
295
+ a standard local QUIC connection is defined up until and including ` /quic. `
296
+ Then, ` /webtransport/ ` runs over QUIC. The self-signed certificate hash that the
297
+ server will use to verify the connection.
298
+
299
+ The WebTransport CONNECT request is sent to an HTTPS endpoint. libp2p WebTransport server use
300
+ ` /.well-known/libp2p-webtransport ` . For instance, the WebTransport URL of a WebTransport
301
+ server advertising ` /ip4/1.2.3.4/udp/1234/quic/webtransport/ ` would be
302
+ ` https://1.2.3.4:1234/.well-known/libp2p-webtransport?type=noise `
303
+ (the ?type=noise refers to the authentication scheme using Noise).
304
+
221
305
## References
222
306
223
307
[ 1] [ What is HTTP/3 by Cloudspoint] ( https://cloudspoint.xyz/what-is-http3/ )
0 commit comments