@cryptotaxi247 / kubo / commits / eb6cc02c0

feat(config): connmgr: expose silence period (#10827)

Hector Sanjuan committed Jun 17, 2025 at 15:55 UTC eb6cc02c06abc1f081f72491dca6fb7595690038
6 files changed +34 -10
config/init.go
+3
@@ -95,6 +95,9 @@ const DefaultConnMgrLowWater = 32
95 // grace period.
96 const DefaultConnMgrGracePeriod = time.Second * 20
97
98 +// DefaultConnMgrSilencePeriod controls how often the connection manager enforces the limits.
99 +const DefaultConnMgrSilencePeriod = time.Second * 10
100 +
101 // DefaultConnMgrType is the default value for the connection managers
102 // type.
103 const DefaultConnMgrType = "basic"
config/swarm.go
+5 -4
@@ -104,10 +104,11 @@ type Transports struct {
104
105 // ConnMgr defines configuration options for the libp2p connection manager.
106 type ConnMgr struct {
107 - Type *OptionalString `json:",omitempty"`
108 - LowWater *OptionalInteger `json:",omitempty"`
109 - HighWater *OptionalInteger `json:",omitempty"`
110 - GracePeriod *OptionalDuration `json:",omitempty"`
107 + Type *OptionalString `json:",omitempty"`
108 + LowWater *OptionalInteger `json:",omitempty"`
109 + HighWater *OptionalInteger `json:",omitempty"`
110 + GracePeriod *OptionalDuration `json:",omitempty"`
111 + SilencePeriod *OptionalDuration `json:",omitempty"`
112 }
113
114 // ResourceMgr defines configuration options for the libp2p Network Resource Manager
core/node/groups.go
+3 -1
@@ -49,7 +49,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
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))
52 + silence := cfg.Swarm.ConnMgr.SilencePeriod.WithDefault(config.DefaultConnMgrSilencePeriod)
53 + connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace, silence))
54 +
55 default:
56 return fx.Error(fmt.Errorf("unrecognized Swarm.ConnMgr.Type: %q", connMgrType))
57 }
core/node/libp2p/libp2p.go
+5 -2
@@ -25,9 +25,12 @@ type Libp2pOpts struct {
25 Opts []libp2p.Option `group:"libp2p"`
26 }
27
28 -func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) {
28 +func ConnectionManager(low, high int, grace, silence time.Duration) func() (opts Libp2pOpts, err error) {
29 return func() (opts Libp2pOpts, err error) {
30 - cm, err := connmgr.NewConnManager(low, high, connmgr.WithGracePeriod(grace))
30 + cm, err := connmgr.NewConnManager(low, high,
31 + connmgr.WithGracePeriod(grace),
32 + connmgr.WithSilencePeriod(silence),
33 + )
34 if err != nil {
35 return opts, err
36 }
docs/changelogs/v0.36.md
+4
@@ -88,6 +88,10 @@ To revert to the previous behavior for A/B testing, set `Internal.Bitswap.Broadc
88
89 The `filestore` command has a new option, `--remove-bad-blocks`, to verify objects in the filestore and remove those that fail verification.
90
91 +#### ConnMgr.SilencePeriod configuration setting exposed
92 +
93 +This connection manager option controls how often connections are swept and potentially terminated. See the [ConnMgr documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#swarmconnmgrsilenceperiod).
94 +
95 #### 📦️ Important dependency updates
96
97 - update `go-libp2p-kad-dht` to [v0.33.0](https://github.com/libp2p/go-libp2p-kad-dht/releases/tag/v0.33.0)
docs/config.md
+14 -3
@@ -171,6 +171,7 @@ config file at runtime.
171 - [`Swarm.ConnMgr.LowWater`](#swarmconnmgrlowwater)
172 - [`Swarm.ConnMgr.HighWater`](#swarmconnmgrhighwater)
173 - [`Swarm.ConnMgr.GracePeriod`](#swarmconnmgrgraceperiod)
174 + - [`Swarm.ConnMgr.SilencePeriod`](#swarmconnmgrsilenceperiod)
175 - [`Swarm.ResourceMgr`](#swarmresourcemgr)
176 - [`Swarm.ResourceMgr.Enabled`](#swarmresourcemgrenabled)
177 - [`Swarm.ResourceMgr.MaxMemory`](#swarmresourcemgrmaxmemory)
@@ -2357,8 +2358,9 @@ Type: `optionalString` (default when unset or empty)
2358
2359 The basic connection manager uses a "high water", a "low water", and internal
2360 scoring to periodically close connections to free up resources. When a node
2360 -using the basic connection manager reaches `HighWater` idle connections, it will
2361 -close the least useful ones until it reaches `LowWater` idle connections.
2361 +using the basic connection manager reaches `HighWater` idle connections, it
2362 +will close the least useful ones until it reaches `LowWater` idle
2363 +connections. The process of closing connections happens every `SilencePeriod`.
2364
2365 The connection manager considers a connection idle if:
2366
@@ -2377,7 +2379,8 @@ The connection manager considers a connection idle if:
2379 "Type": "basic",
2380 "LowWater": 100,
2381 "HighWater": 200,
2380 - "GracePeriod": "30s"
2382 + "GracePeriod": "30s",
2383 + "SilencePeriod": "10s"
2384 }
2385 }
2386 }
@@ -2411,6 +2414,14 @@ Default: `"20s"`
2414
2415 Type: `optionalDuration`
2416
2417 +##### `Swarm.ConnMgr.SilencePeriod`
2418 +
2419 +SilencePeriod is the time duration between connection manager runs, when connections that are idle are closed.
2420 +
2421 +Default: `"10s"`
2422 +
2423 +Type: `optionalDuration`
2424 +
2425 ### `Swarm.ResourceMgr`
2426
2427 Learn more about Kubo's usage of libp2p Network Resource Manager