Skip to content

Commit

Permalink
feat: enable /webrtc-direct listener
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jul 30, 2024
1 parent 749a61b commit 0e0f585
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
2 changes: 2 additions & 0 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 1 addition & 1 deletion core/node/libp2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions docs/changelogs/v0.30.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
40 changes: 25 additions & 15 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 6 additions & 2 deletions test/cli/transports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,27 @@ 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)
nodes.StartDaemons().Connect()
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)
Expand Down

0 comments on commit 0e0f585

Please sign in to comment.