From eb6cc02c06abc1f081f72491dca6fb7595690038 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 17 Jun 2025 15:55:57 +0200 Subject: [PATCH] feat(config): connmgr: expose silence period (#10827) --- config/init.go | 3 +++ config/swarm.go | 9 +++++---- core/node/groups.go | 4 +++- core/node/libp2p/libp2p.go | 7 +++++-- docs/changelogs/v0.36.md | 4 ++++ docs/config.md | 17 ++++++++++++++--- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/config/init.go b/config/init.go index 40c24bd25..373d744d4 100644 --- a/config/init.go +++ b/config/init.go @@ -95,6 +95,9 @@ const DefaultConnMgrLowWater = 32 // grace period. const DefaultConnMgrGracePeriod = time.Second * 20 +// DefaultConnMgrSilencePeriod controls how often the connection manager enforces the limits. +const DefaultConnMgrSilencePeriod = time.Second * 10 + // DefaultConnMgrType is the default value for the connection managers // type. const DefaultConnMgrType = "basic" diff --git a/config/swarm.go b/config/swarm.go index 4a04a0054..0faa4d25d 100644 --- a/config/swarm.go +++ b/config/swarm.go @@ -104,10 +104,11 @@ type Transports struct { // ConnMgr defines configuration options for the libp2p connection manager. type ConnMgr struct { - Type *OptionalString `json:",omitempty"` - LowWater *OptionalInteger `json:",omitempty"` - HighWater *OptionalInteger `json:",omitempty"` - GracePeriod *OptionalDuration `json:",omitempty"` + Type *OptionalString `json:",omitempty"` + LowWater *OptionalInteger `json:",omitempty"` + HighWater *OptionalInteger `json:",omitempty"` + GracePeriod *OptionalDuration `json:",omitempty"` + SilencePeriod *OptionalDuration `json:",omitempty"` } // ResourceMgr defines configuration options for the libp2p Network Resource Manager diff --git a/core/node/groups.go b/core/node/groups.go index 1794b74c3..9d53aeef5 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -49,7 +49,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part grace := cfg.Swarm.ConnMgr.GracePeriod.WithDefault(config.DefaultConnMgrGracePeriod) low := int(cfg.Swarm.ConnMgr.LowWater.WithDefault(config.DefaultConnMgrLowWater)) high := int(cfg.Swarm.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater)) - connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace)) + silence := cfg.Swarm.ConnMgr.SilencePeriod.WithDefault(config.DefaultConnMgrSilencePeriod) + connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace, silence)) + default: return fx.Error(fmt.Errorf("unrecognized Swarm.ConnMgr.Type: %q", connMgrType)) } diff --git a/core/node/libp2p/libp2p.go b/core/node/libp2p/libp2p.go index 1adced34f..da6991b1f 100644 --- a/core/node/libp2p/libp2p.go +++ b/core/node/libp2p/libp2p.go @@ -25,9 +25,12 @@ type Libp2pOpts struct { Opts []libp2p.Option `group:"libp2p"` } -func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) { +func ConnectionManager(low, high int, grace, silence time.Duration) func() (opts Libp2pOpts, err error) { return func() (opts Libp2pOpts, err error) { - cm, err := connmgr.NewConnManager(low, high, connmgr.WithGracePeriod(grace)) + cm, err := connmgr.NewConnManager(low, high, + connmgr.WithGracePeriod(grace), + connmgr.WithSilencePeriod(silence), + ) if err != nil { return opts, err } diff --git a/docs/changelogs/v0.36.md b/docs/changelogs/v0.36.md index bbe2fdf96..5287d8760 100644 --- a/docs/changelogs/v0.36.md +++ b/docs/changelogs/v0.36.md @@ -88,6 +88,10 @@ To revert to the previous behavior for A/B testing, set `Internal.Bitswap.Broadc The `filestore` command has a new option, `--remove-bad-blocks`, to verify objects in the filestore and remove those that fail verification. +#### ConnMgr.SilencePeriod configuration setting exposed + +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). + #### 📦️ Important dependency updates - update `go-libp2p-kad-dht` to [v0.33.0](https://github.com/libp2p/go-libp2p-kad-dht/releases/tag/v0.33.0) diff --git a/docs/config.md b/docs/config.md index c3636da3d..64e555984 100644 --- a/docs/config.md +++ b/docs/config.md @@ -171,6 +171,7 @@ config file at runtime. - [`Swarm.ConnMgr.LowWater`](#swarmconnmgrlowwater) - [`Swarm.ConnMgr.HighWater`](#swarmconnmgrhighwater) - [`Swarm.ConnMgr.GracePeriod`](#swarmconnmgrgraceperiod) + - [`Swarm.ConnMgr.SilencePeriod`](#swarmconnmgrsilenceperiod) - [`Swarm.ResourceMgr`](#swarmresourcemgr) - [`Swarm.ResourceMgr.Enabled`](#swarmresourcemgrenabled) - [`Swarm.ResourceMgr.MaxMemory`](#swarmresourcemgrmaxmemory) @@ -2357,8 +2358,9 @@ Type: `optionalString` (default when unset or empty) The basic connection manager uses a "high water", a "low water", and internal scoring to periodically close connections to free up resources. When a node -using the basic connection manager reaches `HighWater` idle connections, it will -close the least useful ones until it reaches `LowWater` idle connections. +using the basic connection manager reaches `HighWater` idle connections, it +will close the least useful ones until it reaches `LowWater` idle +connections. The process of closing connections happens every `SilencePeriod`. The connection manager considers a connection idle if: @@ -2377,7 +2379,8 @@ The connection manager considers a connection idle if: "Type": "basic", "LowWater": 100, "HighWater": 200, - "GracePeriod": "30s" + "GracePeriod": "30s", + "SilencePeriod": "10s" } } } @@ -2411,6 +2414,14 @@ Default: `"20s"` Type: `optionalDuration` +##### `Swarm.ConnMgr.SilencePeriod` + +SilencePeriod is the time duration between connection manager runs, when connections that are idle are closed. + +Default: `"10s"` + +Type: `optionalDuration` + ### `Swarm.ResourceMgr` Learn more about Kubo's usage of libp2p Network Resource Manager