Skip to content

Commit d2f3fd9

Browse files
schomatislidel
authored andcommitted
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.
1 parent 1d5e46a commit d2f3fd9

File tree

7 files changed

+60
-57
lines changed

7 files changed

+60
-57
lines changed

config/init.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ func InitWithIdentity(identity Identity) (*Config, error) {
7979
Interval: "12h",
8080
Strategy: "all",
8181
},
82-
Swarm: SwarmConfig{
83-
ConnMgr: ConnMgr{
84-
LowWater: DefaultConnMgrLowWater,
85-
HighWater: DefaultConnMgrHighWater,
86-
GracePeriod: DefaultConnMgrGracePeriod.String(),
87-
Type: "basic",
88-
},
89-
},
9082
Pinning: Pinning{
9183
RemoteServices: map[string]RemotePinningService{},
9284
},
@@ -114,6 +106,10 @@ const DefaultConnMgrLowWater = 600
114106
// grace period
115107
const DefaultConnMgrGracePeriod = time.Second * 20
116108

109+
// DefaultConnMgrType is the default value for the connection managers
110+
// type.
111+
const DefaultConnMgrType = "basic"
112+
117113
func addressesConfig() Addresses {
118114
return Addresses{
119115
Swarm: []string{

config/profile.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ fetching may be degraded.
178178
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
179179
c.Reprovider.Interval = "0"
180180

181-
c.Swarm.ConnMgr.LowWater = 20
182-
c.Swarm.ConnMgr.HighWater = 40
183-
c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
181+
lowWater := int64(20)
182+
highWater := int64(40)
183+
gracePeriod := time.Minute
184+
c.Swarm.ConnMgr.Type = NewOptionalString("basic")
185+
c.Swarm.ConnMgr.LowWater = &OptionalInteger{value: &lowWater}
186+
c.Swarm.ConnMgr.HighWater = &OptionalInteger{value: &highWater}
187+
c.Swarm.ConnMgr.GracePeriod = &OptionalDuration{&gracePeriod}
184188
return nil
185189
},
186190
},

config/swarm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ type Transports struct {
131131

132132
// ConnMgr defines configuration options for the libp2p connection manager
133133
type ConnMgr struct {
134-
Type string
135-
LowWater int
136-
HighWater int
137-
GracePeriod string
134+
Type *OptionalString `json:",omitempty"`
135+
LowWater *OptionalInteger `json:",omitempty"`
136+
HighWater *OptionalInteger `json:",omitempty"`
137+
GracePeriod *OptionalDuration `json:",omitempty"`
138138
}
139139

140140
// ResourceMgr defines configuration options for the libp2p Network Resource Manager

core/node/groups.go

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,20 @@ var BaseLibP2P = fx.Options(
3838
)
3939

4040
func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
41-
// parse ConnMgr config
42-
43-
grace := config.DefaultConnMgrGracePeriod
44-
low := config.DefaultConnMgrLowWater
45-
high := config.DefaultConnMgrHighWater
46-
47-
connmgr := fx.Options()
48-
49-
if cfg.Swarm.ConnMgr.Type != "none" {
50-
switch cfg.Swarm.ConnMgr.Type {
51-
case "":
52-
// 'default' value is the basic connection manager
53-
break
54-
case "basic":
55-
var err error
56-
grace, err = time.ParseDuration(cfg.Swarm.ConnMgr.GracePeriod)
57-
if err != nil {
58-
return fx.Error(fmt.Errorf("parsing Swarm.ConnMgr.GracePeriod: %s", err))
59-
}
60-
61-
low = cfg.Swarm.ConnMgr.LowWater
62-
high = cfg.Swarm.ConnMgr.HighWater
63-
default:
64-
return fx.Error(fmt.Errorf("unrecognized ConnMgr.Type: %q", cfg.Swarm.ConnMgr.Type))
65-
}
66-
41+
var connmgr fx.Option
42+
43+
// set connmgr based on Swarm.ConnMgr.Type
44+
connMgrType := cfg.Swarm.ConnMgr.Type.WithDefault(config.DefaultConnMgrType)
45+
switch connMgrType {
46+
case "none":
47+
connmgr = fx.Options() // noop
48+
case "", "basic":
49+
grace := cfg.Swarm.ConnMgr.GracePeriod.WithDefault(config.DefaultConnMgrGracePeriod)
50+
low := int(cfg.Swarm.ConnMgr.LowWater.WithDefault(config.DefaultConnMgrLowWater))
51+
high := int(cfg.Swarm.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater))
6752
connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace))
53+
default:
54+
return fx.Error(fmt.Errorf("unrecognized Swarm.ConnMgr.Type: %q", connMgrType))
6855
}
6956

7057
// parse PubSub config

core/node/libp2p/rcmgr_defaults.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,5 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
197197

198198
defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))
199199

200-
// If a high water mark is set:
201-
if cfg.ConnMgr.Type == "basic" {
202-
// set the connection limit higher than high water mark so that the ConnMgr has "space and time" to close "least useful" connections.
203-
defaultLimitConfig.System.Conns = 2 * cfg.ConnMgr.HighWater
204-
log.Info("adjusted default resource manager System.Conns limits to match ConnMgr.HighWater value of %s", cfg.ConnMgr.HighWater)
205-
}
206-
207200
return defaultLimitConfig, nil
208201
}

docs/changelogs/v0.17.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Below is an outline of all that is in this release, so you get a sense of all th
99
- [Kubo changelog v0.17](#kubo-changelog-v017)
1010
- [v0.17.0](#v0170)
1111
- [Overview](#overview)
12-
- [TOC](#toc)
1312
- [🔦 Highlights](#-highlights)
13+
- [Implicit connection manager limits](#implicit-connection-manager-limits)
1414
- [TAR Response Format on Gateways](#tar-response-format-on-gateways)
1515
- [Changelog](#changelog)
1616
- [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
1919

2020
<!-- TODO -->
2121

22+
#### Implicit connection manager limits
23+
24+
Starting with this release, `ipfs init` will no longer store the default
25+
[Connection Manager](https://github.com/ipfs/kubo/blob/master/docs/config.md#swarmconnmgr)
26+
limits in the user config under `Swarm.ConnMgr`.
27+
28+
Users are still free to use this setting to set custom values, but for most use
29+
cases, the defaults provided with the latest Kubo release should be sufficient.
30+
31+
To remove any custom limits and switch to the implicit defaults managed by Kubo:
32+
33+
```console
34+
$ ipfs config --json Swarm.ConnMgr '{}'
35+
```
36+
37+
We will be adjusting defaults in the future releases.
38+
2239
#### TAR Response Format on Gateways
2340

2441
Implemented [IPIP-288](https://github.com/ipfs/specs/pull/288) which adds

docs/config.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,15 @@ documented in `ipfs config profile --help`.
243243

244244
- `lowpower`
245245

246-
Reduces daemon overhead on the system. May affect node
246+
Reduces daemon overhead on the system. Affects node
247247
functionality - performance of content discovery and data
248-
fetching may be degraded.
248+
fetching may be degraded. Local data won't be announced on routing systems like DHT.
249+
250+
- `Swarm.ConnMgr` set to maintain minimum number of p2p connections at a time.
251+
- Disables [`Reprovider`](#reprovider) service → no CID will be announced on DHT and other routing systems(!)
252+
- Disables AutoNAT.
253+
254+
Use this profile with caution.
249255

250256
## Types
251257

@@ -1730,7 +1736,8 @@ be configured to keep. Kubo currently supports two connection managers:
17301736
* none: never close idle connections.
17311737
* basic: the default connection manager.
17321738

1733-
Default: basic
1739+
By default, this section is empty and the implicit defaults defined below
1740+
are used.
17341741

17351742
#### `Swarm.ConnMgr.Type`
17361743

@@ -1739,8 +1746,7 @@ management) and `"basic"`.
17391746

17401747
Default: "basic".
17411748

1742-
Type: `string` (when unset or `""`, the default connection manager is applied
1743-
and all `ConnMgr` fields are ignored).
1749+
Type: `optionalString` (default when unset or empty)
17441750

17451751
#### Basic Connection Manager
17461752

@@ -1779,7 +1785,7 @@ trim down to.
17791785

17801786
Default: `600`
17811787

1782-
Type: `integer`
1788+
Type: `optionalInteger`
17831789

17841790
##### `Swarm.ConnMgr.HighWater`
17851791

@@ -1789,7 +1795,7 @@ towards this limit.
17891795

17901796
Default: `900`
17911797

1792-
Type: `integer`
1798+
Type: `optionalInteger`
17931799

17941800
##### `Swarm.ConnMgr.GracePeriod`
17951801

@@ -1798,7 +1804,7 @@ by the connection manager.
17981804

17991805
Default: `"20s"`
18001806

1801-
Type: `duration`
1807+
Type: `optionalDuration`
18021808

18031809
### `Swarm.ResourceMgr`
18041810

0 commit comments

Comments
 (0)