Skip to content

Commit

Permalink
refactor: apply config changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored and marten-seemann committed Nov 12, 2021
1 parent 61d93d9 commit 3aa2cfd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 74 deletions.
2 changes: 1 addition & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.NoAnnounce)),
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
fx.Provide(libp2p.RelayTransport(enableRelayTransport)),
fx.Provide(libp2p.RelayService(!cfg.Swarm.DisableRelayService, cfg.Swarm.RelayServiceOpts)),
fx.Provide(libp2p.RelayService(cfg.Swarm.RelayService.Enabled.WithDefault(true), cfg.Swarm.RelayService)),
fx.Provide(libp2p.Transports(cfg.Swarm.Transports)),
fx.Invoke(libp2p.StartListening(cfg.Addresses.Swarm)),
fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled, cfg.Discovery.MDNS.Interval)),
Expand Down
38 changes: 21 additions & 17 deletions core/node/libp2p/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,40 @@ func RelayTransport(enableRelay bool) func() (opts Libp2pOpts, err error) {
}
}

func RelayService(enable bool, relayOpts config.RelayResources) func() (opts Libp2pOpts, err error) {
func RelayService(enable bool, relayOpts config.RelayService) func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) {
if enable {
r := relay.DefaultResources()
if relayOpts.Limit.Data > 0 {
r.Limit.Data = relayOpts.Limit.Data
if i := int64(relayOpts.Limit.Data.WithDefault(0)); i > 0 {
r.Limit.Data = i
}
if relayOpts.Limit.Duration > 0 {
/* TODO: swap when https://github.com/ipfs/go-ipfs-config/pull/148 lands
if i := int(relayOpts.Limit.Duration.WithDefault(0)); i > 0 { */
if i := int(relayOpts.Limit.Duration); i > 0 {
r.Limit.Duration = time.Duration(relayOpts.Limit.Duration)
}
if relayOpts.MaxCircuits > 0 {
r.MaxCircuits = relayOpts.MaxCircuits
if i := int(relayOpts.MaxCircuits.WithDefault(0)); i > 0 {
r.MaxCircuits = i
}
if relayOpts.BufferSize > 0 {
r.BufferSize = relayOpts.BufferSize
if i := int(relayOpts.BufferSize.WithDefault(0)); i > 0 {
r.BufferSize = i
}
if relayOpts.ReservationTTL > 0 {
/* TODO: swap when https://github.com/ipfs/go-ipfs-config/pull/148 lands
if i := int(relayOpts.ReservationTTL.WithDefault(0)); i > 0 { */
if i := int(relayOpts.ReservationTTL); i > 0 {
r.ReservationTTL = time.Duration(relayOpts.ReservationTTL)
}
if relayOpts.MaxReservations > 0 {
r.MaxReservations = relayOpts.MaxReservations
if i := int(relayOpts.MaxReservations.WithDefault(0)); i > 0 {
r.MaxReservations = i
}
if relayOpts.MaxReservationsPerIP > 0 {
r.MaxReservationsPerIP = relayOpts.MaxReservationsPerIP
if i := int(relayOpts.MaxReservationsPerIP.WithDefault(0)); i > 0 {
r.MaxReservationsPerIP = i
}
if relayOpts.MaxReservationsPerPeer > 0 {
r.MaxReservationsPerPeer = relayOpts.MaxReservationsPerPeer
if i := int(relayOpts.MaxReservationsPerPeer.WithDefault(0)); i > 0 {
r.MaxReservationsPerPeer = i
}
if relayOpts.MaxReservationsPerASN > 0 {
r.MaxReservationsPerASN = relayOpts.MaxReservationsPerASN
if i := int(relayOpts.MaxReservationsPerASN.WithDefault(0)); i > 0 {
r.MaxReservationsPerASN = i
}
opts.Opts = append(opts.Opts, libp2p.EnableRelayService(relay.WithResources(r)))
}
Expand Down
104 changes: 51 additions & 53 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ config file at runtime.
- [`Swarm.DisableBandwidthMetrics`](#swarmdisablebandwidthmetrics)
- [`Swarm.DisableNatPortMap`](#swarmdisablenatportmap)
- [`Swarm.DisableRelay`](#swarmdisablerelay)
- [`Swarm.DisableRelayService`](#swarmdisablerelayservice)
- [`Swarm.RelayServiceOpts`](#swarmrelayserviceopts)
- [`Swarm.RelayServiceOpts.Limit`](#swarmrelayserviceoptslimit)
- [`Swarm.RelayServiceOpts.Limit.Duration`](#swarmrelayserviceoptslimitduration)
- [`Swarm.RelayServiceOpts.Limit.Data`](#swarmrelayserviceoptslimitdata)
- [`Swarm.RelayServiceOpts.ReservationTTL`](#swarmrelayserviceoptsreservationttl)
- [`Swarm.RelayServiceOpts.MaxReservations`](#swarmrelayserviceoptsmaxreservations)
- [`Swarm.RelayServiceOpts.MaxCircuits`](#swarmrelayserviceoptsmaxcircuits)
- [`Swarm.RelayServiceOpts.BufferSize`](#swarmrelayserviceoptsbuffersize)
- [`Swarm.RelayServiceOpts.MaxReservationsPerPeer`](#swarmrelayserviceoptsmaxreservationsperpeer)
- [`Swarm.RelayServiceOpts.MaxReservationsPerIP`](#swarmrelayserviceoptsmaxreservationsperip)
- [`Swarm.RelayServiceOpts.MaxReservationsPerASN`](#swarmrelayserviceoptsmaxreservationsperasn)
- [`Swarm.RelayService`](#swarmrelayservice)
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled)
- [`Swarm.RelayService.Limit`](#swarmrelayservicelimit)
- [`Swarm.RelayService.Limit.Duration`](#swarmrelayservicelimitduration)
- [`Swarm.RelayService.Limit.Data`](#swarmrelayservicelimitdata)
- [`Swarm.RelayService.ReservationTTL`](#swarmrelayservicereservationttl)
- [`Swarm.RelayService.MaxReservations`](#swarmrelayservicemaxreservations)
- [`Swarm.RelayService.MaxCircuits`](#swarmrelayservicemaxcircuits)
- [`Swarm.RelayService.BufferSize`](#swarmrelayservicebuffersize)
- [`Swarm.RelayService.MaxReservationsPerPeer`](#swarmrelayservicemaxreservationsperpeer)
- [`Swarm.RelayService.MaxReservationsPerIP`](#swarmrelayservicemaxreservationsperip)
- [`Swarm.RelayService.MaxReservationsPerASN`](#swarmrelayservicemaxreservationsperasn)
- [`Swarm.EnableAutoRelay`](#swarmenableautorelay)
- [Mode 1: `EnableRelayHop` is `false`](#mode-1-enablerelayhop-is-false)
- [Mode 2: `EnableRelayHop` is `true`](#mode-2-enablerelayhop-is-true)
- [`Swarm.EnableAutoNATService`](#swarmenableautonatservice)
- [`Swarm.ConnMgr`](#swarmconnmgr)
- [`Swarm.ConnMgr.Type`](#swarmconnmgrtype)
Expand Down Expand Up @@ -1291,133 +1289,133 @@ Default: `false`

Type: `bool`

### `Swarm.DisableRelayService`
### `Swarm.RelayService`

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

Default: `false`
Default: `{}`

Type: `bool`
Type: `object`

### `Swarm.RelayServiceOpts`
### `Swarm.RelayService.Enabled`

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

Default: `{}`
Default: Enabled

Type: `object`
Type: `flag`

#### `Swarm.RelayServiceOpts.Limit`
#### `Swarm.RelayService.Limit`

Limits applied to every relayed connection.

Default: `{}`

Type: `object[string -> string]`

##### `Swarm.RelayServiceOpts.Limit.Duration`
##### `Swarm.RelayService.Limit.Duration`

Time limit before a relayed connection is reset.

Default: `"2m"`

Type: `string`

Type: `duration`

##### `Swarm.RelayServiceOpts.Limit.Data`
##### `Swarm.RelayService.Limit.Data`

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

Default: `131072` (128 kb)

Type: `integer`
Type: `optionalInteger`


#### `Swarm.RelayServiceOpts.ReservationTTL`
#### `Swarm.RelayService.ReservationTTL`

Duration of a new or refreshed reservation.

Default: `"1h"`

Type: `string`
Type: `duration`


#### `Swarm.RelayServiceOpts.MaxReservations`
#### `Swarm.RelayService.MaxReservations`

Maximum number of active relay slots.

Default: `128`

Type: `integer`
Type: `optionalInteger`


#### `Swarm.RelayServiceOpts.MaxReservations`
#### `Swarm.RelayService.MaxReservations`

Maximum number of open relay connections for each peer.

Default: `16`

Type: `integer`
Type: `optionalInteger`


#### `Swarm.RelayServiceOpts.BufferSize`
#### `Swarm.RelayService.BufferSize`

Size of the relayed connection buffers.

Default: `2048`

Type: `integer`
Type: `optionalInteger`


#### `Swarm.RelayServiceOpts.MaxReservationsPerPeer`
#### `Swarm.RelayService.MaxReservationsPerPeer`

Maximum number of reservations originating from the same peer.

Default: `4`

Type: `integer`
Type: `optionalInteger`


#### `Swarm.RelayServiceOpts.MaxReservationsPerIP`
#### `Swarm.RelayService.MaxReservationsPerIP`

Maximum number of reservations originating from the same IP.

Default: `8`

Type: `integer`

Type: `optionalInteger`

#### `Swarm.RelayServiceOpts.MaxReservationsPerASN`
#### `Swarm.RelayService.MaxReservationsPerASN`

Maximum number of reservations originating from the same ASN.

Default: `32`

Type: `integer`

Type: `optionalInteger`

### `Swarm.EnableRelayHop`

**REMOVED**

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


### `Swarm.EnableAutoRelay`

Enables "automatic relay" mode for this node. This option does two _very_
different things based on the `Swarm.EnableRelayHop`. See
[#7228](https://github.com/ipfs/go-ipfs/issues/7228) for context.

Default: `false`

Type: `bool`
Enables "automatic relay" mode for this node.

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

See also:

- [`Swarm.Transports.Network.Relay`](#swarmtransportsnetworkrelay) to control
relay transport (as a client)
- [`Swarm.RelayService.Enabled`](#swarmrelayserviceenabled) to control if your
node should act as a limited relay when possible

Default: `false`

Type: `bool`

### `Swarm.EnableAutoNATService`

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/ipfs/go-ipfs-blockstore v0.1.6
github.com/ipfs/go-ipfs-chunker v0.0.5
github.com/ipfs/go-ipfs-cmds v0.6.0
github.com/ipfs/go-ipfs-config v0.16.1-0.20211018130411-0226122eaf22
github.com/ipfs/go-ipfs-config v0.16.1-0.20211026210306-0fb5b58a4e11
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
github.com/ipfs/go-ipfs-files v0.0.9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7Na
github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8=
github.com/ipfs/go-ipfs-cmds v0.6.0 h1:yAxdowQZzoFKjcLI08sXVNnqVj3jnABbf9smrPQmBsw=
github.com/ipfs/go-ipfs-cmds v0.6.0/go.mod h1:ZgYiWVnCk43ChwoH8hAmI1IRbuVtq3GSTHwtRB/Kqhk=
github.com/ipfs/go-ipfs-config v0.16.1-0.20211018130411-0226122eaf22 h1:oaJFYaZpyJ3U6GSnn3+M3yH/++78jrns2xSZp4kWWe4=
github.com/ipfs/go-ipfs-config v0.16.1-0.20211018130411-0226122eaf22/go.mod h1:wz2lKzOjgJeYJa6zx8W9VT7mz+iSd0laBMqS/9wmX6A=
github.com/ipfs/go-ipfs-config v0.16.1-0.20211026210306-0fb5b58a4e11 h1:2dQQwVI/WAmmWBJc8SkEQsQOTw99vMFqcfMw0PnNbJ0=
github.com/ipfs/go-ipfs-config v0.16.1-0.20211026210306-0fb5b58a4e11/go.mod h1:wz2lKzOjgJeYJa6zx8W9VT7mz+iSd0laBMqS/9wmX6A=
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ=
github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
Expand Down

0 comments on commit 3aa2cfd

Please sign in to comment.