From 0e0f585cc96b555287268b786d103a7165eec833 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 26 Jul 2024 18:59:58 +0200 Subject: [PATCH] feat: enable /webrtc-direct listener --- config/init.go | 2 ++ core/node/libp2p/transport.go | 2 +- docs/changelogs/v0.30.md | 9 ++++++++ docs/config.md | 40 ++++++++++++++++++++++------------- go.mod | 4 ++-- go.sum | 8 +++---- test/cli/transports_test.go | 8 +++++-- 7 files changed, 49 insertions(+), 24 deletions(-) diff --git a/config/init.go b/config/init.go index e3d0af30d9e..7b653409899 100644 --- a/config/init.go +++ b/config/init.go @@ -114,8 +114,10 @@ func addressesConfig() Addresses { "/ip6/::/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1", "/ip4/0.0.0.0/udp/4001/quic-v1/webtransport", + "/ip4/0.0.0.0/udp/4002/webrtc-direct", "/ip6/::/udp/4001/quic-v1", "/ip6/::/udp/4001/quic-v1/webtransport", + "/ip6/::/udp/4002/webrtc-direct", }, Announce: []string{}, AppendAnnounce: []string{}, diff --git a/core/node/libp2p/transport.go b/core/node/libp2p/transport.go index 797917b72cb..6628adc3268 100644 --- a/core/node/libp2p/transport.go +++ b/core/node/libp2p/transport.go @@ -50,7 +50,7 @@ func Transports(tptConfig config.Transports) interface{} { opts.Opts = append(opts.Opts, libp2p.Transport(webtransport.New)) } - if tptConfig.Network.WebRTCDirect.WithDefault(false) { + if tptConfig.Network.WebRTCDirect.WithDefault(!privateNetworkEnabled) { if privateNetworkEnabled { return opts, fmt.Errorf( "WebRTC Direct transport does not support private networks, please disable Swarm.Transports.Network.WebRTCDirect", diff --git a/docs/changelogs/v0.30.md b/docs/changelogs/v0.30.md index 8457662bf84..b66e5e22aee 100644 --- a/docs/changelogs/v0.30.md +++ b/docs/changelogs/v0.30.md @@ -6,6 +6,7 @@ - [Overview](#overview) - [🔦 Highlights](#-highlights) + - [WebRTC-Direct Transport enabled by default](#webrtc-direct-transport-enabled-by-default) - [Automated `ipfs version check`](#automated-ipfs-version-check) - [Version Suffix Configuration](#version-suffix-configuration) - [📝 Changelog](#-changelog) @@ -15,6 +16,14 @@ ### 🔦 Highlights +#### WebRTC-Direct Transport enabled by default + +Kubo now ships with `/udp/4002/webrtc-direct` listener enabled by default. + +WebRTC Direct complements existing `/wss` (Secure WebSockets) and `/webtransport` transports. Unlike `/wss`, which requires a domain name and a CA-issued TLS certificate, WebRTC Direct works with IPs and can be enabled by default on all Kubo nodes. + +Learn more: [`Swarm.Transports.Network.WebRTCDirect`](https://github.com/ipfs/kubo/blob/master/docs/config.md#swarmtransportsnetworkwebrtcdirect) + #### Automated `ipfs version check` Kubo now performs privacy-preserving version checks using the [libp2p identify protocol](https://github.com/libp2p/specs/blob/master/identify/README.md) on peers detected by the Amino DHT client. diff --git a/docs/config.md b/docs/config.md index c7355072d4b..8ccd4b139a7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -2144,7 +2144,7 @@ Configuration section for libp2p _network_ transports. Transports enabled in this section will be used for dialing. However, to receive connections on these transports, multiaddrs for these transports must be added to `Addresses.Swarm`. -Supported transports are: QUIC, TCP, WS, Relay and WebTransport. +Supported transports are: QUIC, TCP, WS, Relay, WebTransport and WebRTCDirect. Each field in this section is a `flag`. @@ -2195,8 +2195,8 @@ Default: Enabled Type: `flag` Listen Addresses: -* /ip4/0.0.0.0/udp/4001/quic-v1 (default) -* /ip6/::/udp/4001/quic-v1 (default) +- `/ip4/0.0.0.0/udp/4001/quic-v1` (default) +- `/ip6/::/udp/4001/quic-v1` (default) #### `Swarm.Transports.Network.Relay` @@ -2243,33 +2243,43 @@ Default: Enabled Type: `flag` -#### `Swarm.Transports.Network.WebRTCDirect` +Listen Addresses: +- `/ip4/0.0.0.0/udp/4001/quic-v1/webtransport` (default) +- `/ip6/::/udp/4001/quic-v1/webtransport` (default) -**Experimental:** the support for WebRTC Direct is currently experimental. -This feature was introduced in [`go-libp2p@v0.32.0`](https://github.com/libp2p/go-libp2p/releases/tag/v0.32.0). +#### `Swarm.Transports.Network.WebRTCDirect` [WebRTC Direct](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md) is a transport protocol that provides another way for browsers to connect to the rest of the libp2p network. WebRTC Direct allows for browser nodes to connect to other nodes without special configuration, such as TLS certificates. This can be useful for browser nodes that do not yet support -[WebTransport](https://blog.libp2p.io/2022-12-19-libp2p-webtransport/). +[WebTransport](https://blog.libp2p.io/2022-12-19-libp2p-webtransport/), +which is still relatively new and has [known issues](https://github.com/libp2p/js-libp2p/issues/2572). Enabling this transport allows Kubo node to act on `/udp/4002/webrtc-direct` listeners defined in `Addresses.Swarm`, `Addresses.Announce` or -`Addresses.AppendAnnounce`. At the moment, WebRTC Direct doesn't support listening on the same port as a QUIC or WebTransport listener +`Addresses.AppendAnnounce`. + +> [!IMPORTANT] +> At the moment, WebRTC Direct doesn't support listening on the same port as a QUIC or WebTransport listener, and Kubo uses 4002 for it. -**NOTE:** at the moment, WebRTC Direct cannot be used to connect to a browser -node to a node that is behind a NAT or firewall. -This requires using normal -[WebRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md), -which is currently being worked on in -[go-libp2p#2009](https://github.com/libp2p/go-libp2p/issues/2009). +> [!NOTE] +> WebRTC Direct is browser-to-node. It cannot be used to connect a browser +> node to a node that is behind a NAT or firewall. +> This requires using normal +> [WebRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md), +> which is currently being worked on in +> [go-libp2p#2009](https://github.com/libp2p/go-libp2p/issues/2009). -Default: Disabled +Default: Enabled Type: `flag` +Listen Addresses: +- `/ip4/0.0.0.0/udp/4002/webrtc-direct` (default) +- `/ip6/::/udp/4001/webrtc-direct` (default) + ### `Swarm.Transports.Security` Configuration section for libp2p _security_ transports. Transports enabled in diff --git a/go.mod b/go.mod index 1492b46eb0f..7a837a15c10 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/ipfs-shipyard/nopfs v0.0.12 github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c - github.com/ipfs/boxo v0.21.1-0.20240730141506-8e51658f8a1b + github.com/ipfs/boxo v0.20.0 github.com/ipfs/go-block-format v0.2.0 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-cidutil v0.1.0 @@ -48,7 +48,7 @@ require ( github.com/jbenet/goprocess v0.1.4 github.com/julienschmidt/httprouter v1.3.0 github.com/libp2p/go-doh-resolver v0.4.0 - github.com/libp2p/go-libp2p v0.35.4 + github.com/libp2p/go-libp2p v0.35.1-0.20240726083353-205f7be11544 github.com/libp2p/go-libp2p-http v0.5.0 github.com/libp2p/go-libp2p-kad-dht v0.25.2 github.com/libp2p/go-libp2p-kbucket v0.6.3 diff --git a/go.sum b/go.sum index 8f76df20a6c..e261a66be45 100644 --- a/go.sum +++ b/go.sum @@ -330,8 +330,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.21.1-0.20240730141506-8e51658f8a1b h1:vH+ly+ghScnm4fDTsFnRkWIqZ0Vux6U3aOzPc3bQsOM= -github.com/ipfs/boxo v0.21.1-0.20240730141506-8e51658f8a1b/go.mod h1:NmweAYeY1USOaJJxouy7DLr/Y5M8UBSsCI2KRivO+TY= +github.com/ipfs/boxo v0.20.0 h1:umUl7q1v5g5AX8FPLTnZBvvagLmT+V0Tt61EigP81ec= +github.com/ipfs/boxo v0.20.0/go.mod h1:mwttn53Eibgska2DhVIj7ln3UViq7MVHRxOMb+ehSDM= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ= @@ -508,8 +508,8 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.35.4 h1:FDiBUYLkueFwsuNJUZaxKRdpKvBOWU64qQPL768bSeg= -github.com/libp2p/go-libp2p v0.35.4/go.mod h1:RKCDNt30IkFipGL0tl8wQW/3zVWEGFUZo8g2gAKxwjU= +github.com/libp2p/go-libp2p v0.35.1-0.20240726083353-205f7be11544 h1:2ivyU6vXAsqOZ0+V54CibsXoxXJ43F8G4r+FfWEHx5Q= +github.com/libp2p/go-libp2p v0.35.1-0.20240726083353-205f7be11544/go.mod h1:M/fCHPPkWjectocXCOUua4Z2lSr2cjQNByVVuxWPwXI= github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= diff --git a/test/cli/transports_test.go b/test/cli/transports_test.go index a523351816d..cbef5c57da0 100644 --- a/test/cli/transports_test.go +++ b/test/cli/transports_test.go @@ -90,8 +90,10 @@ func TestTransports(t *testing.T) { nodes.ForEachPar(func(n *harness.Node) { n.UpdateConfig(func(cfg *config.Config) { cfg.Addresses.Swarm = []string{"/ip4/127.0.0.1/udp/0/quic-v1"} - cfg.Swarm.Transports.Network.QUIC = config.True cfg.Swarm.Transports.Network.TCP = config.False + cfg.Swarm.Transports.Network.QUIC = config.True + cfg.Swarm.Transports.Network.WebTransport = config.False + cfg.Swarm.Transports.Network.WebRTCDirect = config.False }) }) disableRouting(nodes) @@ -99,14 +101,16 @@ func TestTransports(t *testing.T) { runTests(nodes) }) - t.Run("QUIC", func(t *testing.T) { + t.Run("QUIC+Webtransport", func(t *testing.T) { t.Parallel() nodes := harness.NewT(t).NewNodes(5).Init() nodes.ForEachPar(func(n *harness.Node) { n.UpdateConfig(func(cfg *config.Config) { cfg.Addresses.Swarm = []string{"/ip4/127.0.0.1/udp/0/quic-v1/webtransport"} + cfg.Swarm.Transports.Network.TCP = config.False cfg.Swarm.Transports.Network.QUIC = config.True cfg.Swarm.Transports.Network.WebTransport = config.True + cfg.Swarm.Transports.Network.WebRTCDirect = config.False }) }) disableRouting(nodes)