refactor(config): remove Swarm.ConnMgr defaults

This moves defaults to Kubo code, cleaning up config.
If value is in config, we assume it is an explicit choice made by user.
Makes migrations easier.
This commit is contained in:
Lucas Molas 2022-04-26 20:49:14 -03:00 committed by Marcin Rataj
parent 81e6b1d5bc
commit e34c0da2b5
7 changed files with 59 additions and 56 deletions

View File

@ -79,14 +79,6 @@ func InitWithIdentity(identity Identity) (*Config, error) {
Interval: "12h",
Strategy: "all",
},
Swarm: SwarmConfig{
ConnMgr: ConnMgr{
LowWater: DefaultConnMgrLowWater,
HighWater: DefaultConnMgrHighWater,
GracePeriod: DefaultConnMgrGracePeriod.String(),
Type: "basic",
},
},
Pinning: Pinning{
RemoteServices: map[string]RemotePinningService{},
},
@ -114,6 +106,10 @@ const DefaultConnMgrLowWater = 600
// grace period
const DefaultConnMgrGracePeriod = time.Second * 20
// DefaultConnMgrType is the default value for the connection managers
// type.
const DefaultConnMgrType = "basic"
func addressesConfig() Addresses {
return Addresses{
Swarm: []string{

View File

@ -178,9 +178,13 @@ fetching may be degraded.
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
c.Reprovider.Interval = "0"
c.Swarm.ConnMgr.LowWater = 20
c.Swarm.ConnMgr.HighWater = 40
c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
lowWater := int64(20)
highWater := int64(40)
gracePeriod := time.Minute
c.Swarm.ConnMgr.Type = NewOptionalString("basic")
c.Swarm.ConnMgr.LowWater = &OptionalInteger{value: &lowWater}
c.Swarm.ConnMgr.HighWater = &OptionalInteger{value: &highWater}
c.Swarm.ConnMgr.GracePeriod = &OptionalDuration{&gracePeriod}
return nil
},
},

View File

@ -131,10 +131,10 @@ type Transports struct {
// ConnMgr defines configuration options for the libp2p connection manager
type ConnMgr struct {
Type string
LowWater int
HighWater int
GracePeriod string
Type *OptionalString `json:",omitempty"`
LowWater *OptionalInteger `json:",omitempty"`
HighWater *OptionalInteger `json:",omitempty"`
GracePeriod *OptionalDuration `json:",omitempty"`
}
// ResourceMgr defines configuration options for the libp2p Network Resource Manager

View File

@ -38,33 +38,20 @@ var BaseLibP2P = fx.Options(
)
func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
// parse ConnMgr config
grace := config.DefaultConnMgrGracePeriod
low := config.DefaultConnMgrLowWater
high := config.DefaultConnMgrHighWater
connmgr := fx.Options()
if cfg.Swarm.ConnMgr.Type != "none" {
switch cfg.Swarm.ConnMgr.Type {
case "":
// 'default' value is the basic connection manager
break
case "basic":
var err error
grace, err = time.ParseDuration(cfg.Swarm.ConnMgr.GracePeriod)
if err != nil {
return fx.Error(fmt.Errorf("parsing Swarm.ConnMgr.GracePeriod: %s", err))
}
low = cfg.Swarm.ConnMgr.LowWater
high = cfg.Swarm.ConnMgr.HighWater
default:
return fx.Error(fmt.Errorf("unrecognized ConnMgr.Type: %q", cfg.Swarm.ConnMgr.Type))
}
var connmgr fx.Option
// set connmgr based on Swarm.ConnMgr.Type
connMgrType := cfg.Swarm.ConnMgr.Type.WithDefault(config.DefaultConnMgrType)
switch connMgrType {
case "none":
connmgr = fx.Options() // noop
case "", "basic":
grace := cfg.Swarm.ConnMgr.GracePeriod.WithDefault(config.DefaultConnMgrGracePeriod)
low := int(cfg.Swarm.ConnMgr.LowWater.WithDefault(config.DefaultConnMgrLowWater))
high := int(cfg.Swarm.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater))
connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace))
default:
return fx.Error(fmt.Errorf("unrecognized Swarm.ConnMgr.Type: %q", connMgrType))
}
// parse PubSub config

View File

@ -197,12 +197,5 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))
// If a high water mark is set:
if cfg.ConnMgr.Type == "basic" {
// set the connection limit higher than high water mark so that the ConnMgr has "space and time" to close "least useful" connections.
defaultLimitConfig.System.Conns = 2 * cfg.ConnMgr.HighWater
log.Info("adjusted default resource manager System.Conns limits to match ConnMgr.HighWater value of %s", cfg.ConnMgr.HighWater)
}
return defaultLimitConfig, nil
}

View File

@ -9,8 +9,8 @@ Below is an outline of all that is in this release, so you get a sense of all th
- [Kubo changelog v0.17](#kubo-changelog-v017)
- [v0.17.0](#v0170)
- [Overview](#overview)
- [TOC](#toc)
- [🔦 Highlights](#-highlights)
- [Implicit connection manager limits](#implicit-connection-manager-limits)
- [TAR Response Format on Gateways](#tar-response-format-on-gateways)
- [Changelog](#changelog)
- [Contributors](#contributors)
@ -19,6 +19,23 @@ Below is an outline of all that is in this release, so you get a sense of all th
<!-- TODO -->
#### Implicit connection manager limits
Starting with this release, `ipfs init` will no longer store the default
[Connection Manager](https://github.com/ipfs/kubo/blob/master/docs/config.md#swarmconnmgr)
limits in the user config under `Swarm.ConnMgr`.
Users are still free to use this setting to set custom values, but for most use
cases, the defaults provided with the latest Kubo release should be sufficient.
To remove any custom limits and switch to the implicit defaults managed by Kubo:
```console
$ ipfs config --json Swarm.ConnMgr '{}'
```
We will be adjusting defaults in the future releases.
#### TAR Response Format on Gateways
Implemented [IPIP-288](https://github.com/ipfs/specs/pull/288) which adds

View File

@ -243,9 +243,15 @@ documented in `ipfs config profile --help`.
- `lowpower`
Reduces daemon overhead on the system. May affect node
Reduces daemon overhead on the system. Affects node
functionality - performance of content discovery and data
fetching may be degraded.
fetching may be degraded. Local data won't be announced on routing systems like DHT.
- `Swarm.ConnMgr` set to maintain minimum number of p2p connections at a time.
- Disables [`Reprovider`](#reprovider) service → no CID will be announced on DHT and other routing systems(!)
- Disables AutoNAT.
Use this profile with caution.
## Types
@ -1730,7 +1736,8 @@ be configured to keep. Kubo currently supports two connection managers:
* none: never close idle connections.
* basic: the default connection manager.
Default: basic
By default, this section is empty and the implicit defaults defined below
are used.
#### `Swarm.ConnMgr.Type`
@ -1739,8 +1746,7 @@ management) and `"basic"`.
Default: "basic".
Type: `string` (when unset or `""`, the default connection manager is applied
and all `ConnMgr` fields are ignored).
Type: `optionalString` (default when unset or empty)
#### Basic Connection Manager
@ -1779,7 +1785,7 @@ trim down to.
Default: `600`
Type: `integer`
Type: `optionalInteger`
##### `Swarm.ConnMgr.HighWater`
@ -1789,7 +1795,7 @@ towards this limit.
Default: `900`
Type: `integer`
Type: `optionalInteger`
##### `Swarm.ConnMgr.GracePeriod`
@ -1798,7 +1804,7 @@ by the connection manager.
Default: `"20s"`
Type: `duration`
Type: `optionalDuration`
### `Swarm.ResourceMgr`