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
65365192f754d18c00f2411e833b74ff0aee9f3d
6 files changed
+60
-50
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
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
@@ -1695,7 +1701,8 @@ be configured to keep. Kubo currently supports two connection managers:
1701
* none: never close idle connections.
1702
* basic: the default connection manager.
1703
1698
-Default: basic
1704
+By default, this section is empty and the implicit defaults defined below
1705
+are used.
1706
1707
#### `Swarm.ConnMgr.Type`
1708
@@ -1704,8 +1711,7 @@ management) and `"basic"`.
1711
1712
Default: "basic".
1713
1707
-Type: `string` (when unset or `""`, the default connection manager is applied
1708
-and all `ConnMgr` fields are ignored).
1714
+Type: `optionalString` (default when unset or empty)
1715
1716
#### Basic Connection Manager
1717
@@ -1744,7 +1750,7 @@ trim down to.
1750
1751
Default: `600`
1752
1747
-Type: `integer`
1753
+Type: `optionalInteger`
1754
1755
##### `Swarm.ConnMgr.HighWater`
1756
@@ -1754,7 +1760,7 @@ towards this limit.
1760
1761
Default: `900`
1762
1757
-Type: `integer`
1763
+Type: `optionalInteger`
1764
1765
##### `Swarm.ConnMgr.GracePeriod`
1766
@@ -1763,7 +1769,7 @@ by the connection manager.
1769
1770
Default: `"20s"`
1771
1766
-Type: `duration`
1772
+Type: `optionalDuration`
1773
1774
### `Swarm.ResourceMgr`
1775