@cryptotaxi247 / kubo / commits / 9327ee64c

fix: clarity: no user supplied rcmgr limits of 0 (#9563)

Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com> Co-authored-by: Marcin Rataj <lidel@lidel.org>

Steve Loeppky committed Jan 22, 2023 at 11:04 UTC 9327ee64ce96ca6da29bb2a099e0e0930b0d9e09
2 files changed +14 -5
core/node/libp2p/rcmgr.go
+11 -5
@@ -52,7 +52,8 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
52 return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err)
53 }
54
55 - limitConfig, err := createDefaultLimitConfig(cfg)
55 + var limitConfig rcmgr.LimitConfig
56 + defaultComputedLimitConfig, err := createDefaultLimitConfig(cfg)
57 if err != nil {
58 return nil, opts, err
59 }
@@ -61,10 +62,15 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
62 // is documented in docs/config.md.
63 // Any changes here should be reflected there.
64 if cfg.ResourceMgr.Limits != nil {
64 - l := *cfg.ResourceMgr.Limits
65 - // This effectively overrides the computed default LimitConfig with any vlues from cfg.ResourceMgr.Limits
66 - l.Apply(limitConfig)
67 - limitConfig = l
65 + userSuppliedOverrideLimitConfig := *cfg.ResourceMgr.Limits
66 + // This effectively overrides the computed default LimitConfig with any non-zero values from cfg.ResourceMgr.Limits.
67 + // Because of how how Apply works, any 0 value for a user supplied override
68 + // will be overriden with a computed default value.
69 + // There currently isn't a way for a user to supply a 0-value override.
70 + userSuppliedOverrideLimitConfig.Apply(defaultComputedLimitConfig)
71 + limitConfig = userSuppliedOverrideLimitConfig
72 + } else {
73 + limitConfig = defaultComputedLimitConfig
74 }
75
76 if err := ensureConnMgrMakeSenseVsResourceMgr(limitConfig, cfg.ConnMgr); err != nil {
docs/config.md
+3
@@ -1844,6 +1844,9 @@ The `Swarm.ResourceMgr.Limits` override the default limits described above.
1844 Any override `BaseLimits` or limit <key,value>s from `Swarm.ResourceMgr.Limits`
1845 that aren't specified will use the [computed default limits](./libp2p-resource-management.md#computed-default-limits).
1846
1847 +Until [ipfs/kubo#9564](https://github.com/ipfs/kubo/issues/9564) is addressed, there isn't a way to set an override limit of zero.
1848 +0 is currently ignored. 0 currently means use to use the [computed default limits](./libp2p-resource-management.md#computed-default-limits).
1849 +
1850 Example #1: setting limits for a specific scope
1851 ```json
1852 {