Skip to content

Commit

Permalink
Merge branch 'master' into twdragon-ppa
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero authored Aug 7, 2024
2 parents c2bdd61 + fc31f9c commit 9986f7f
Show file tree
Hide file tree
Showing 19 changed files with 222 additions and 178 deletions.
7 changes: 7 additions & 0 deletions config/autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const (
// AutoNATServiceDisabled indicates that the user has disabled the
// AutoNATService.
AutoNATServiceDisabled
// AutoNATServiceEnabledV1Only forces use of V1 and disables V2
// (used for testing)
AutoNATServiceEnabledV1Only
)

func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
Expand All @@ -30,6 +33,8 @@ func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
*m = AutoNATServiceEnabled
case "disabled":
*m = AutoNATServiceDisabled
case "legacy-v1":
*m = AutoNATServiceEnabledV1Only
default:
return fmt.Errorf("unknown autonat mode: %s", string(text))
}
Expand All @@ -44,6 +49,8 @@ func (m AutoNATServiceMode) MarshalText() ([]byte, error) {
return []byte("enabled"), nil
case AutoNATServiceDisabled:
return []byte("disabled"), nil
case AutoNATServiceEnabledV1Only:
return []byte("legacy-v1"), nil
default:
return nil, fmt.Errorf("unknown autonat mode: %d", m)
}
Expand Down
2 changes: 2 additions & 0 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ func addressesConfig() Addresses {
Swarm: []string{
"/ip4/0.0.0.0/tcp/4001",
"/ip6/::/tcp/4001",
"/ip4/0.0.0.0/udp/4001/webrtc-direct",
"/ip4/0.0.0.0/udp/4001/quic-v1",
"/ip4/0.0.0.0/udp/4001/quic-v1/webtransport",
"/ip6/::/udp/4001/webrtc-direct",
"/ip6/::/udp/4001/quic-v1",
"/ip6/::/udp/4001/quic-v1/webtransport",
},
Expand Down
4 changes: 2 additions & 2 deletions core/coreunix/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
bstore "github.com/ipfs/boxo/blockstore"
chunker "github.com/ipfs/boxo/chunker"
offline "github.com/ipfs/boxo/exchange/offline"
u "github.com/ipfs/boxo/util"
cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-test/random"
)

func getDagserv(t *testing.T) ipld.DAGService {
Expand All @@ -35,7 +35,7 @@ func TestMetadata(t *testing.T) {
// Make some random node
ds := getDagserv(t)
data := make([]byte, 1000)
_, err := io.ReadFull(u.NewTimeSeededRand(), data)
_, err := io.ReadFull(random.NewRand(), data)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 3 additions & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
// to dhtclient.
fallthrough
case config.AutoNATServiceEnabled:
autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle))
autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, false))
case config.AutoNATServiceEnabledV1Only:
autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, true))
}

enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(true) // nolint
Expand Down
9 changes: 8 additions & 1 deletion core/node/libp2p/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var NatPortMap = simpleOpt(libp2p.NATPortMap())

func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
func AutoNATService(throttle *config.AutoNATThrottleConfig, v1only bool) func() Libp2pOpts {
return func() (opts Libp2pOpts) {
opts.Opts = append(opts.Opts, libp2p.EnableNATService())
if throttle != nil {
Expand All @@ -21,6 +21,13 @@ func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
),
)
}

// While V1 still exists and V2 rollout is in progress
// (https://github.com/ipfs/kubo/issues/10091) we check a flag that
// allows users to disable V2 and run V1-only mode
if !v1only {
opts.Opts = append(opts.Opts, libp2p.EnableAutoNATv2())
}
return opts
}
}
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
19 changes: 19 additions & 0 deletions docs/changelogs/v0.30.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- [Overview](#overview)
- [🔦 Highlights](#-highlights)
- [WebRTC-Direct Transport enabled by default](#webrtc-direct-transport-enabled-by-default)
- [AutoNAT V2 Service Introduced Alongside V1](#autonat-v2-service-introduced-alongside-v1)
- [Automated `ipfs version check`](#automated-ipfs-version-check)
- [Version Suffix Configuration](#version-suffix-configuration)
- [📝 Changelog](#-changelog)
Expand All @@ -15,6 +17,23 @@

### 🔦 Highlights

#### WebRTC-Direct Transport enabled by default

Kubo now ships with `/udp/4001/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)

> [!NOTE]
> Kubo 0.30 includes a migration for existing users that adds `/webrtc-direct` listener on the same UDP port as `/udp/{port}/quic-v1`. This supports the WebRTC-Direct rollout by reusing preexisting UDP firewall settings and port mappings created for QUIC.
#### AutoNAT V2 Service Introduced Alongside V1

The AutoNAT service enables nodes to determine their public reachability on the internet. AutoNAT V2 enhances this protocol with improved features. In this release, Kubo will offer both V1 and V2 services to other peers, although it will continue to use only V1 when acting as a client. Future releases will phase out V1, transitioning clients to utilize V2 exclusively.

For more details, see the [Deployment Plan for AutoNAT V2](https://github.com/ipfs/kubo/issues/10091) and [`AutoNAT`](https://github.com/ipfs/kubo/blob/master/docs/config.md#autonat) configuration options.

#### 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
58 changes: 37 additions & 21 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ Type: `array[string]`

## `AutoNAT`

Contains the configuration options for the AutoNAT service. The AutoNAT service
Contains the configuration options for the libp2p's [AutoNAT](https://github.com/libp2p/specs/tree/master/autonat) service. The AutoNAT service
helps other nodes on the network determine if they're publicly reachable from
the rest of the internet.

Expand All @@ -561,13 +561,22 @@ the rest of the internet.
When unset (default), the AutoNAT service defaults to _enabled_. Otherwise, this
field can take one of two values:

* "enabled" - Enable the service (unless the node determines that it, itself,
isn't reachable by the public internet).
* "disabled" - Disable the service.
* `enabled` - Enable the V1+V2 service (unless the node determines that it,
itself, isn't reachable by the public internet).
* `legacy-v1` - Same as `enabled` but only V1 service is enabled. Used for testing
during as few releases as we [transition to V2](https://github.com/ipfs/kubo/issues/10091), will be removed in the future.
* `disabled` - Disable the service.

Additional modes may be added in the future.

Type: `string` (one of `"enabled"` or `"disabled"`)
> [!IMPORTANT]
> We are in the progress of [rolling out AutoNAT V2](https://github.com/ipfs/kubo/issues/10091).
> Right now, by default, a publicly diallable Kubo provides both V1 and V2 service to other peers,
> but only V1 is used by Kubo as a client. In a future release we will remove V1 and switch client to use V2.
Default: `enabled`

Type: `optionalString`

### `AutoNAT.Throttle`

Expand Down Expand Up @@ -2144,7 +2153,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 +2204,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 +2252,40 @@ 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 [`[email protected]`](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`
Enabling this transport allows Kubo node to act on `/udp/4001/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`.

**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 (without UPnP port mapping).
> The browser-to-private 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/4001/webrtc-direct` (default)
- `/ip6/::/udp/4001/webrtc-direct` (default)

### `Swarm.Transports.Security`

Configuration section for libp2p _security_ transports. Transports enabled in
Expand Down
27 changes: 14 additions & 13 deletions docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ toolchain go1.22.0
replace github.com/ipfs/kubo => ./../../..

require (
github.com/ipfs/boxo v0.21.1-0.20240730141506-8e51658f8a1b
github.com/ipfs/boxo v0.22.0
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
github.com/libp2p/go-libp2p v0.35.4
github.com/libp2p/go-libp2p v0.36.1
github.com/multiformats/go-multiaddr v0.13.0
)

Expand Down Expand Up @@ -54,7 +54,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
Expand Down Expand Up @@ -141,28 +141,28 @@ require (
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.19.0 // indirect
github.com/onsi/ginkgo/v2 v2.19.1 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
github.com/pion/datachannel v1.5.6 // indirect
github.com/pion/dtls/v2 v2.2.11 // indirect
github.com/pion/ice/v2 v2.3.25 // indirect
github.com/pion/datachannel v1.5.8 // indirect
github.com/pion/dtls/v2 v2.2.12 // indirect
github.com/pion/ice/v2 v2.3.32 // indirect
github.com/pion/interceptor v0.1.29 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.12 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.14 // indirect
github.com/pion/rtp v1.8.6 // indirect
github.com/pion/sctp v1.8.16 // indirect
github.com/pion/rtp v1.8.8 // indirect
github.com/pion/sctp v1.8.20 // indirect
github.com/pion/sdp/v3 v3.0.9 // indirect
github.com/pion/srtp/v2 v2.0.18 // indirect
github.com/pion/srtp/v2 v2.0.20 // indirect
github.com/pion/stun v0.6.1 // indirect
github.com/pion/transport/v2 v2.2.5 // indirect
github.com/pion/transport/v2 v2.2.9 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pion/webrtc/v3 v3.2.42 // indirect
github.com/pion/webrtc/v3 v3.2.50 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
Expand All @@ -171,7 +171,7 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.45.0 // indirect
github.com/quic-go/quic-go v0.45.2 // indirect
github.com/quic-go/webtransport-go v0.8.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/samber/lo v1.46.0 // indirect
Expand All @@ -185,6 +185,7 @@ require (
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect
github.com/wlynxg/anet v0.0.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
Expand Down
Loading

0 comments on commit 9986f7f

Please sign in to comment.