Skip to content

Commit 3aa2cfd

Browse files
lidelmarten-seemann
authored andcommitted
refactor: apply config changes from review
See ipfs/go-ipfs-config#146 and ipfs/go-ipfs-config@0fb5b58
1 parent 61d93d9 commit 3aa2cfd

File tree

5 files changed

+76
-74
lines changed

5 files changed

+76
-74
lines changed

core/node/groups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
131131
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.NoAnnounce)),
132132
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
133133
fx.Provide(libp2p.RelayTransport(enableRelayTransport)),
134-
fx.Provide(libp2p.RelayService(!cfg.Swarm.DisableRelayService, cfg.Swarm.RelayServiceOpts)),
134+
fx.Provide(libp2p.RelayService(cfg.Swarm.RelayService.Enabled.WithDefault(true), cfg.Swarm.RelayService)),
135135
fx.Provide(libp2p.Transports(cfg.Swarm.Transports)),
136136
fx.Invoke(libp2p.StartListening(cfg.Addresses.Swarm)),
137137
fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled, cfg.Discovery.MDNS.Interval)),

core/node/libp2p/relay.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,40 @@ func RelayTransport(enableRelay bool) func() (opts Libp2pOpts, err error) {
2020
}
2121
}
2222

23-
func RelayService(enable bool, relayOpts config.RelayResources) func() (opts Libp2pOpts, err error) {
23+
func RelayService(enable bool, relayOpts config.RelayService) func() (opts Libp2pOpts, err error) {
2424
return func() (opts Libp2pOpts, err error) {
2525
if enable {
2626
r := relay.DefaultResources()
27-
if relayOpts.Limit.Data > 0 {
28-
r.Limit.Data = relayOpts.Limit.Data
27+
if i := int64(relayOpts.Limit.Data.WithDefault(0)); i > 0 {
28+
r.Limit.Data = i
2929
}
30-
if relayOpts.Limit.Duration > 0 {
30+
/* TODO: swap when https://github.com/ipfs/go-ipfs-config/pull/148 lands
31+
if i := int(relayOpts.Limit.Duration.WithDefault(0)); i > 0 { */
32+
if i := int(relayOpts.Limit.Duration); i > 0 {
3133
r.Limit.Duration = time.Duration(relayOpts.Limit.Duration)
3234
}
33-
if relayOpts.MaxCircuits > 0 {
34-
r.MaxCircuits = relayOpts.MaxCircuits
35+
if i := int(relayOpts.MaxCircuits.WithDefault(0)); i > 0 {
36+
r.MaxCircuits = i
3537
}
36-
if relayOpts.BufferSize > 0 {
37-
r.BufferSize = relayOpts.BufferSize
38+
if i := int(relayOpts.BufferSize.WithDefault(0)); i > 0 {
39+
r.BufferSize = i
3840
}
39-
if relayOpts.ReservationTTL > 0 {
41+
/* TODO: swap when https://github.com/ipfs/go-ipfs-config/pull/148 lands
42+
if i := int(relayOpts.ReservationTTL.WithDefault(0)); i > 0 { */
43+
if i := int(relayOpts.ReservationTTL); i > 0 {
4044
r.ReservationTTL = time.Duration(relayOpts.ReservationTTL)
4145
}
42-
if relayOpts.MaxReservations > 0 {
43-
r.MaxReservations = relayOpts.MaxReservations
46+
if i := int(relayOpts.MaxReservations.WithDefault(0)); i > 0 {
47+
r.MaxReservations = i
4448
}
45-
if relayOpts.MaxReservationsPerIP > 0 {
46-
r.MaxReservationsPerIP = relayOpts.MaxReservationsPerIP
49+
if i := int(relayOpts.MaxReservationsPerIP.WithDefault(0)); i > 0 {
50+
r.MaxReservationsPerIP = i
4751
}
48-
if relayOpts.MaxReservationsPerPeer > 0 {
49-
r.MaxReservationsPerPeer = relayOpts.MaxReservationsPerPeer
52+
if i := int(relayOpts.MaxReservationsPerPeer.WithDefault(0)); i > 0 {
53+
r.MaxReservationsPerPeer = i
5054
}
51-
if relayOpts.MaxReservationsPerASN > 0 {
52-
r.MaxReservationsPerASN = relayOpts.MaxReservationsPerASN
55+
if i := int(relayOpts.MaxReservationsPerASN.WithDefault(0)); i > 0 {
56+
r.MaxReservationsPerASN = i
5357
}
5458
opts.Opts = append(opts.Opts, libp2p.EnableRelayService(relay.WithResources(r)))
5559
}

docs/config.md

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,19 @@ config file at runtime.
100100
- [`Swarm.DisableBandwidthMetrics`](#swarmdisablebandwidthmetrics)
101101
- [`Swarm.DisableNatPortMap`](#swarmdisablenatportmap)
102102
- [`Swarm.DisableRelay`](#swarmdisablerelay)
103-
- [`Swarm.DisableRelayService`](#swarmdisablerelayservice)
104-
- [`Swarm.RelayServiceOpts`](#swarmrelayserviceopts)
105-
- [`Swarm.RelayServiceOpts.Limit`](#swarmrelayserviceoptslimit)
106-
- [`Swarm.RelayServiceOpts.Limit.Duration`](#swarmrelayserviceoptslimitduration)
107-
- [`Swarm.RelayServiceOpts.Limit.Data`](#swarmrelayserviceoptslimitdata)
108-
- [`Swarm.RelayServiceOpts.ReservationTTL`](#swarmrelayserviceoptsreservationttl)
109-
- [`Swarm.RelayServiceOpts.MaxReservations`](#swarmrelayserviceoptsmaxreservations)
110-
- [`Swarm.RelayServiceOpts.MaxCircuits`](#swarmrelayserviceoptsmaxcircuits)
111-
- [`Swarm.RelayServiceOpts.BufferSize`](#swarmrelayserviceoptsbuffersize)
112-
- [`Swarm.RelayServiceOpts.MaxReservationsPerPeer`](#swarmrelayserviceoptsmaxreservationsperpeer)
113-
- [`Swarm.RelayServiceOpts.MaxReservationsPerIP`](#swarmrelayserviceoptsmaxreservationsperip)
114-
- [`Swarm.RelayServiceOpts.MaxReservationsPerASN`](#swarmrelayserviceoptsmaxreservationsperasn)
103+
- [`Swarm.RelayService`](#swarmrelayservice)
104+
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled)
105+
- [`Swarm.RelayService.Limit`](#swarmrelayservicelimit)
106+
- [`Swarm.RelayService.Limit.Duration`](#swarmrelayservicelimitduration)
107+
- [`Swarm.RelayService.Limit.Data`](#swarmrelayservicelimitdata)
108+
- [`Swarm.RelayService.ReservationTTL`](#swarmrelayservicereservationttl)
109+
- [`Swarm.RelayService.MaxReservations`](#swarmrelayservicemaxreservations)
110+
- [`Swarm.RelayService.MaxCircuits`](#swarmrelayservicemaxcircuits)
111+
- [`Swarm.RelayService.BufferSize`](#swarmrelayservicebuffersize)
112+
- [`Swarm.RelayService.MaxReservationsPerPeer`](#swarmrelayservicemaxreservationsperpeer)
113+
- [`Swarm.RelayService.MaxReservationsPerIP`](#swarmrelayservicemaxreservationsperip)
114+
- [`Swarm.RelayService.MaxReservationsPerASN`](#swarmrelayservicemaxreservationsperasn)
115115
- [`Swarm.EnableAutoRelay`](#swarmenableautorelay)
116-
- [Mode 1: `EnableRelayHop` is `false`](#mode-1-enablerelayhop-is-false)
117-
- [Mode 2: `EnableRelayHop` is `true`](#mode-2-enablerelayhop-is-true)
118116
- [`Swarm.EnableAutoNATService`](#swarmenableautonatservice)
119117
- [`Swarm.ConnMgr`](#swarmconnmgr)
120118
- [`Swarm.ConnMgr.Type`](#swarmconnmgrtype)
@@ -1291,133 +1289,133 @@ Default: `false`
12911289

12921290
Type: `bool`
12931291

1294-
### `Swarm.DisableRelayService`
1292+
### `Swarm.RelayService`
12951293

1296-
Disables the p2p-circuit v2 relay service. This will prevent this node from
1297-
running as a relay server.
1294+
Configuration options for the relay service.
12981295

1299-
Default: `false`
1296+
Default: `{}`
13001297

1301-
Type: `bool`
1298+
Type: `object`
13021299

1303-
### `Swarm.RelayServiceOpts`
1300+
### `Swarm.RelayService.Enabled`
13041301

1305-
Configuration options for the relay service.
1302+
Enables the p2p-circuit v2 relay service. Disabling this will prevent this node
1303+
from running as a relay server.
13061304

1307-
Default: `{}`
1305+
Default: Enabled
13081306

1309-
Type: `object`
1307+
Type: `flag`
13101308

1311-
#### `Swarm.RelayServiceOpts.Limit`
1309+
#### `Swarm.RelayService.Limit`
13121310

13131311
Limits applied to every relayed connection.
13141312

13151313
Default: `{}`
13161314

13171315
Type: `object[string -> string]`
13181316

1319-
##### `Swarm.RelayServiceOpts.Limit.Duration`
1317+
##### `Swarm.RelayService.Limit.Duration`
13201318

13211319
Time limit before a relayed connection is reset.
13221320

13231321
Default: `"2m"`
13241322

1325-
Type: `string`
1326-
1323+
Type: `duration`
13271324

1328-
##### `Swarm.RelayServiceOpts.Limit.Data`
1325+
##### `Swarm.RelayService.Limit.Data`
13291326

13301327
Limit of data relayed (in each direction) before a relayed connection is reset.
13311328

13321329
Default: `131072` (128 kb)
13331330

1334-
Type: `integer`
1331+
Type: `optionalInteger`
13351332

13361333

1337-
#### `Swarm.RelayServiceOpts.ReservationTTL`
1334+
#### `Swarm.RelayService.ReservationTTL`
13381335

13391336
Duration of a new or refreshed reservation.
13401337

13411338
Default: `"1h"`
13421339

1343-
Type: `string`
1340+
Type: `duration`
13441341

13451342

1346-
#### `Swarm.RelayServiceOpts.MaxReservations`
1343+
#### `Swarm.RelayService.MaxReservations`
13471344

13481345
Maximum number of active relay slots.
13491346

13501347
Default: `128`
13511348

1352-
Type: `integer`
1349+
Type: `optionalInteger`
13531350

13541351

1355-
#### `Swarm.RelayServiceOpts.MaxReservations`
1352+
#### `Swarm.RelayService.MaxReservations`
13561353

13571354
Maximum number of open relay connections for each peer.
13581355

13591356
Default: `16`
13601357

1361-
Type: `integer`
1358+
Type: `optionalInteger`
13621359

13631360

1364-
#### `Swarm.RelayServiceOpts.BufferSize`
1361+
#### `Swarm.RelayService.BufferSize`
13651362

13661363
Size of the relayed connection buffers.
13671364

13681365
Default: `2048`
13691366

1370-
Type: `integer`
1367+
Type: `optionalInteger`
13711368

13721369

1373-
#### `Swarm.RelayServiceOpts.MaxReservationsPerPeer`
1370+
#### `Swarm.RelayService.MaxReservationsPerPeer`
13741371

13751372
Maximum number of reservations originating from the same peer.
13761373

13771374
Default: `4`
13781375

1379-
Type: `integer`
1376+
Type: `optionalInteger`
13801377

13811378

1382-
#### `Swarm.RelayServiceOpts.MaxReservationsPerIP`
1379+
#### `Swarm.RelayService.MaxReservationsPerIP`
13831380

13841381
Maximum number of reservations originating from the same IP.
13851382

13861383
Default: `8`
13871384

1388-
Type: `integer`
1389-
1385+
Type: `optionalInteger`
13901386

1391-
#### `Swarm.RelayServiceOpts.MaxReservationsPerASN`
1387+
#### `Swarm.RelayService.MaxReservationsPerASN`
13921388

13931389
Maximum number of reservations originating from the same ASN.
13941390

13951391
Default: `32`
13961392

1397-
Type: `integer`
1398-
1393+
Type: `optionalInteger`
13991394

14001395
### `Swarm.EnableRelayHop`
14011396

14021397
**REMOVED**
14031398

14041399
Please use [`Swarm.DisableRelayService`][].
14051400

1406-
14071401
### `Swarm.EnableAutoRelay`
14081402

1409-
Enables "automatic relay" mode for this node. This option does two _very_
1410-
different things based on the `Swarm.EnableRelayHop`. See
1411-
[#7228](https://github.com/ipfs/go-ipfs/issues/7228) for context.
1412-
1413-
Default: `false`
1414-
1415-
Type: `bool`
1403+
Enables "automatic relay" mode for this node.
14161404

14171405
Your node will automatically _use_ public relays from the network if it detects
14181406
that it cannot be reached from the public internet (e.g., it's behind a
14191407
firewall). This is likely the feature you're looking for.
14201408

1409+
See also:
1410+
1411+
- [`Swarm.Transports.Network.Relay`](#swarmtransportsnetworkrelay) to control
1412+
relay transport (as a client)
1413+
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled) to control if your
1414+
node should act as a limited relay when possible
1415+
1416+
Default: `false`
1417+
1418+
Type: `bool`
14211419

14221420
### `Swarm.EnableAutoNATService`
14231421

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/ipfs/go-ipfs-blockstore v0.1.6
3131
github.com/ipfs/go-ipfs-chunker v0.0.5
3232
github.com/ipfs/go-ipfs-cmds v0.6.0
33-
github.com/ipfs/go-ipfs-config v0.16.1-0.20211018130411-0226122eaf22
33+
github.com/ipfs/go-ipfs-config v0.16.1-0.20211026210306-0fb5b58a4e11
3434
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
3535
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
3636
github.com/ipfs/go-ipfs-files v0.0.9

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7Na
463463
github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8=
464464
github.com/ipfs/go-ipfs-cmds v0.6.0 h1:yAxdowQZzoFKjcLI08sXVNnqVj3jnABbf9smrPQmBsw=
465465
github.com/ipfs/go-ipfs-cmds v0.6.0/go.mod h1:ZgYiWVnCk43ChwoH8hAmI1IRbuVtq3GSTHwtRB/Kqhk=
466-
github.com/ipfs/go-ipfs-config v0.16.1-0.20211018130411-0226122eaf22 h1:oaJFYaZpyJ3U6GSnn3+M3yH/++78jrns2xSZp4kWWe4=
467-
github.com/ipfs/go-ipfs-config v0.16.1-0.20211018130411-0226122eaf22/go.mod h1:wz2lKzOjgJeYJa6zx8W9VT7mz+iSd0laBMqS/9wmX6A=
466+
github.com/ipfs/go-ipfs-config v0.16.1-0.20211026210306-0fb5b58a4e11 h1:2dQQwVI/WAmmWBJc8SkEQsQOTw99vMFqcfMw0PnNbJ0=
467+
github.com/ipfs/go-ipfs-config v0.16.1-0.20211026210306-0fb5b58a4e11/go.mod h1:wz2lKzOjgJeYJa6zx8W9VT7mz+iSd0laBMqS/9wmX6A=
468468
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
469469
github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ=
470470
github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=

0 commit comments

Comments
 (0)