Skip to content

Commit 8a72aa0

Browse files
committed
refactor(config): cleanup relay handling
1 parent e395f42 commit 8a72aa0

File tree

2 files changed

+34
-52
lines changed

2 files changed

+34
-52
lines changed

core/node/groups.go

+24-23
Original file line numberDiff line numberDiff line change
@@ -113,37 +113,39 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
113113
autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle))
114114
}
115115

116-
// If `cfg.Swarm.DisableRelay` is set and `Network.RelayTransport` isn't, use the former.
117-
enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(!cfg.Swarm.DisableRelay) // nolint
116+
enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(true) // nolint
117+
enableRelayService := cfg.Swarm.RelayService.Enabled.WithDefault(enableRelayTransport)
118+
enableRelayClient := cfg.Swarm.RelayClient.Enabled.WithDefault(enableRelayTransport)
119+
120+
// Log error when relay subsystem could not be initialized due to missing dependency
121+
if !enableRelayTransport {
122+
if enableRelayService {
123+
logger.Fatal("Failed to enable `Swarm.RelayService`, it requires `Swarm.Transports.Network.Relay` to be true.")
124+
}
125+
if enableRelayClient {
126+
logger.Fatal("Failed to enable `Swarm.RelayClient`, it requires `Swarm.Transports.Network.Relay` to be true.")
127+
}
128+
}
118129

119-
// Warn about a deprecated option.
130+
// Force users to migrate old config.
120131
// nolint
121132
if cfg.Swarm.DisableRelay {
122-
logger.Error("The 'Swarm.DisableRelay' config field is deprecated.")
123-
if enableRelayTransport {
124-
logger.Error("'Swarm.DisableRelay' has been overridden by 'Swarm.Transports.Network.Relay'")
125-
} else {
126-
logger.Error("Use the 'Swarm.Transports.Network.Relay' config field instead")
127-
}
133+
logger.Fatal("The 'Swarm.DisableRelay' config field was removed." +
134+
"Use the 'Swarm.Transports.Network.Relay' instead.")
128135
}
129136
// nolint
130137
if cfg.Swarm.EnableAutoRelay {
131-
logger.Error("The 'Swarm.EnableAutoRelay' config field is deprecated.")
132-
if cfg.Swarm.RelayClient.Enabled == config.Default {
133-
logger.Error("Use the 'Swarm.AutoRelay.Enabled' config field instead")
134-
} else {
135-
logger.Error("'Swarm.EnableAutoRelay' has been overridden by 'Swarm.AutoRelay.Enabled'")
136-
}
138+
logger.Fatal("The 'Swarm.EnableAutoRelay' config field was removed." +
139+
"Use the 'Swarm.RelayClient.Enabled' instead.")
137140
}
138141
// nolint
139142
if cfg.Swarm.EnableRelayHop {
140-
logger.Fatal("The `Swarm.EnableRelayHop` config field is ignored.\n" +
143+
logger.Fatal("The `Swarm.EnableRelayHop` config field was removed.\n" +
141144
"Use `Swarm.RelayService` to configure the circuit v2 relay.\n" +
142-
"If you want to continue running a circuit v1 relay, please use the standalone relay daemon: https://github.com/libp2p/go-libp2p-relay-daemon (with RelayV1.Enabled: true)")
145+
"If you want to continue running a circuit v1 relay, please use the standalone relay daemon: https://dist.ipfs.io/#libp2p-relay-daemon (with RelayV1.Enabled: true)")
143146
}
144147

145148
peerChan := make(chan peer.AddrInfo)
146-
usesRelayClient := cfg.Swarm.RelayClient.Enabled.WithDefault(true)
147149
// Gather all the options
148150
opts := fx.Options(
149151
BaseLibP2P,
@@ -156,12 +158,12 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
156158
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
157159
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
158160
fx.Provide(libp2p.RelayTransport(enableRelayTransport)),
159-
fx.Provide(libp2p.RelayService(cfg.Swarm.RelayService.Enabled.WithDefault(true), cfg.Swarm.RelayService)),
161+
fx.Provide(libp2p.RelayService(enableRelayService, cfg.Swarm.RelayService)),
160162
fx.Provide(libp2p.Transports(cfg.Swarm.Transports)),
161163
fx.Invoke(libp2p.StartListening(cfg.Addresses.Swarm)),
162164
fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled, cfg.Discovery.MDNS.Interval)),
163165
fx.Provide(libp2p.ForceReachability(cfg.Internal.Libp2pForceReachability)),
164-
fx.Provide(libp2p.HolePunching(cfg.Swarm.EnableHolePunching, cfg.Swarm.RelayClient.Enabled.WithDefault(false))),
166+
fx.Provide(libp2p.HolePunching(cfg.Swarm.EnableHolePunching, enableRelayClient)),
165167

166168
fx.Provide(libp2p.Security(!bcfg.DisableEncryptedConnections, cfg.Swarm.Transports)),
167169

@@ -171,9 +173,8 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
171173

172174
maybeProvide(libp2p.BandwidthCounter, !cfg.Swarm.DisableBandwidthMetrics),
173175
maybeProvide(libp2p.NatPortMap, !cfg.Swarm.DisableNatPortMap),
174-
maybeProvide(libp2p.AutoRelay(cfg.Swarm.RelayClient.StaticRelays, peerChan), usesRelayClient),
175-
176-
maybeInvoke(libp2p.AutoRelayFeeder, usesRelayClient),
176+
maybeProvide(libp2p.AutoRelay(cfg.Swarm.RelayClient.StaticRelays, peerChan), enableRelayClient),
177+
maybeInvoke(libp2p.AutoRelayFeeder, enableRelayClient),
177178
autonat,
178179
connmgr,
179180
ps,

docs/config.md

+10-29
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ config file at runtime.
107107
- [`Swarm.DisableBandwidthMetrics`](#swarmdisablebandwidthmetrics)
108108
- [`Swarm.DisableNatPortMap`](#swarmdisablenatportmap)
109109
- [`Swarm.EnableHolePunching`](#swarmenableholepunching)
110-
- [`Swarm.EnableAutoRelay`](#swarmenableautorelay)
111110
- [`Swarm.RelayClient`](#swarmrelayclient)
112111
- [`Swarm.RelayClient.Enabled`](#swarmrelayclientenabled)
113112
- [`Swarm.RelayClient.StaticRelays`](#swarmrelayclientstaticrelays)
@@ -122,7 +121,6 @@ config file at runtime.
122121
- [`Swarm.RelayService.MaxReservationsPerPeer`](#swarmrelayservicemaxreservationsperpeer)
123122
- [`Swarm.RelayService.MaxReservationsPerIP`](#swarmrelayservicemaxreservationsperip)
124123
- [`Swarm.RelayService.MaxReservationsPerASN`](#swarmrelayservicemaxreservationsperasn)
125-
- [`Swarm.DisableRelay`](#swarmdisablerelay)
126124
- [`Swarm.EnableAutoNATService`](#swarmenableautonatservice)
127125
- [`Swarm.ConnMgr`](#swarmconnmgr)
128126
- [`Swarm.ConnMgr.Type`](#swarmconnmgrtype)
@@ -1370,27 +1368,15 @@ to [upgrade to a direct connection](https://github.com/libp2p/specs/blob/master/
13701368
through a NAT/firewall whenever possible.
13711369
This feature requires `Swarm.RelayClient.Enabled` to be set to `true`.
13721370

1373-
Default: `false`
1371+
Default: `true`
13741372

13751373
Type: `flag`
13761374

13771375
### `Swarm.EnableAutoRelay`
13781376

1379-
Deprecated: Set `Swarm.RelayClient.Enabled` to `true`.
1380-
1381-
Enables "automatic relay user" mode for this node.
1382-
1383-
Your node will automatically _use_ public relays from the network if it detects
1384-
that it cannot be reached from the public internet (e.g., it's behind a
1385-
firewall) and get a `/p2p-circuit` address from a public relay.
1386-
1387-
This is likely the feature you're looking for, but see also:
1388-
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled) if your node should act as a limited relay for other peers
1389-
- Docs: [Libp2p Circuit Relay](https://docs.libp2p.io/concepts/circuit-relay/)
1377+
**REMOVED**
13901378

1391-
Default: `true`
1392-
1393-
Type: `bool`
1379+
See `Swarm.RelayClient` instead.
13941380

13951381
### `Swarm.RelayClient`
13961382

@@ -1414,8 +1400,8 @@ Type: `bool`
14141400

14151401
#### `Swarm.RelayClient.StaticRelays`
14161402

1417-
Your node will use these statically configured relay servers instead of
1418-
discovering public relays from the network.
1403+
Your node will use these statically configured relay servers (V1 or V2)
1404+
instead of discovering public relays V2 from the network.
14191405

14201406
Default: `[]`
14211407

@@ -1536,15 +1522,9 @@ Replaced with [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled).
15361522

15371523
### `Swarm.DisableRelay`
15381524

1539-
Deprecated: Set `Swarm.Transports.Network.Relay` to `false`.
1540-
1541-
Disables the p2p-circuit relay transport. This will prevent this node from
1542-
connecting to nodes behind relays, or accepting connections from nodes behind
1543-
relays.
1544-
1545-
Default: `false`
1525+
**REMOVED**
15461526

1547-
Type: `bool`
1527+
Set `Swarm.Transports.Network.Relay` to `false` instead.
15481528

15491529
### `Swarm.EnableAutoNATService`
15501530

@@ -1765,8 +1745,9 @@ NATs.
17651745

17661746
See also:
17671747
- Docs: [Libp2p Circuit Relay](https://docs.libp2p.io/concepts/circuit-relay/)
1768-
- [`Swarm.EnableAutoRelay`](#swarmenableautorelay) for getting a public
1769-
`/p2p-circuit` address when behind a firewall.
1748+
- [`Swarm.RelayClient.Enabled`](#swarmrelayclientenabled) for getting a public
1749+
- `/p2p-circuit` address when behind a firewall.
1750+
- [`Swarm.EnableHolePunching`](#swarmenableholepunching) for direct connection upgrade through relay
17701751
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled) for becoming a
17711752
limited relay for other peers
17721753

0 commit comments

Comments
 (0)