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.
Lucas Molas committed
Apr 26, 2022 at 20:49 UTC
e34c0da2b54238baa5509b1e4e61b43278036d36
7 files changed
+60
-57
config/init.go
+4
-8
@@ -79,14 +79,6 @@ func InitWithIdentity(identity Identity) (*Config, error) {
79
Interval: "12h",
80
Strategy: "all",
81
},
82
- Swarm: SwarmConfig{
83
- ConnMgr: ConnMgr{
84
- LowWater: DefaultConnMgrLowWater,
85
- HighWater: DefaultConnMgrHighWater,
86
- GracePeriod: DefaultConnMgrGracePeriod.String(),
87
- Type: "basic",
88
- },
89
- },
82
Pinning: Pinning{
83
RemoteServices: map[string]RemotePinningService{},
84
},
@@ -114,6 +106,10 @@ const DefaultConnMgrLowWater = 600
106
// grace period
107
const DefaultConnMgrGracePeriod = time.Second * 20
108
109
+// DefaultConnMgrType is the default value for the connection managers
110
+// type.
111
+const DefaultConnMgrType = "basic"
112
+
113
func addressesConfig() Addresses {
114
return Addresses{
115
Swarm: []string{
config/profile.go
+7
-3
@@ -178,9 +178,13 @@ fetching may be degraded.
178
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
179
c.Reprovider.Interval = "0"
180
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}
188
return nil
189
},
190
},
config/swarm.go
+4
-4
@@ -131,10 +131,10 @@ type Transports struct {
131
132
// ConnMgr defines configuration options for the libp2p connection manager
133
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"`
138
}
139
140
// ResourceMgr defines configuration options for the libp2p Network Resource Manager
core/node/groups.go
+13
-26
@@ -38,33 +38,20 @@ var BaseLibP2P = fx.Options(
38
)
39
40
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))
52
connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace))
53
+ default:
54
+ return fx.Error(fmt.Errorf("unrecognized Swarm.ConnMgr.Type: %q", connMgrType))
55
}
56
57
// parse PubSub config
core/node/libp2p/rcmgr_defaults.go
-7
@@ -197,12 +197,5 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
197
198
defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))
199
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
-
200
return defaultLimitConfig, nil
201
}
docs/changelogs/v0.17.md
+18
-1
@@ -9,8 +9,8 @@ Below is an outline of all that is in this release, so you get a sense of all th
9
- [Kubo changelog v0.17](#kubo-changelog-v017)
10
- [v0.17.0](#v0170)
11
- [Overview](#overview)
12
- - [TOC](#toc)
12
- [🔦 Highlights](#-highlights)
13
+ - [Implicit connection manager limits](#implicit-connection-manager-limits)
14
- [TAR Response Format on Gateways](#tar-response-format-on-gateways)
15
- [Changelog](#changelog)
16
- [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
19
20
<!-- TODO -->
21
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
+
39
#### TAR Response Format on Gateways
40
41
Implemented [IPIP-288](https://github.com/ipfs/specs/pull/288) which adds
docs/config.md
+14
-8
@@ -243,9 +243,15 @@ documented in `ipfs config profile --help`.
243
244
- `lowpower`
245
246
- Reduces daemon overhead on the system. May affect node
246
+ Reduces daemon overhead on the system. Affects node
247
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.
255
256
## Types
257
@@ -1730,7 +1736,8 @@ be configured to keep. Kubo currently supports two connection managers:
1736
* none: never close idle connections.
1737
* basic: the default connection manager.
1738
1733
-Default: basic
1739
+By default, this section is empty and the implicit defaults defined below
1740
+are used.
1741
1742
#### `Swarm.ConnMgr.Type`
1743
@@ -1739,8 +1746,7 @@ management) and `"basic"`.
1746
1747
Default: "basic".
1748
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)
1750
1751
#### Basic Connection Manager
1752
@@ -1779,7 +1785,7 @@ trim down to.
1785
1786
Default: `600`
1787
1782
-Type: `integer`
1788
+Type: `optionalInteger`
1789
1790
##### `Swarm.ConnMgr.HighWater`
1791
@@ -1789,7 +1795,7 @@ towards this limit.
1795
1796
Default: `900`
1797
1792
-Type: `integer`
1798
+Type: `optionalInteger`
1799
1800
##### `Swarm.ConnMgr.GracePeriod`
1801
@@ -1798,7 +1804,7 @@ by the connection manager.
1804
1805
Default: `"20s"`
1806
1801
-Type: `duration`
1807
+Type: `optionalDuration`
1808
1809
### `Swarm.ResourceMgr`
1810