Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions config/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
7 changes: 5 additions & 2 deletions core/node/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions docs/changelogs/v0.36.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ The `ipfs files cp` command has a `--force` option to allow it to overwrite exis

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)
Expand Down
17 changes: 14 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,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)
Expand Down Expand Up @@ -2294,8 +2295,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:

Expand All @@ -2314,7 +2316,8 @@ The connection manager considers a connection idle if:
"Type": "basic",
"LowWater": 100,
"HighWater": 200,
"GracePeriod": "30s"
"GracePeriod": "30s",
"SilencePeriod": "10s"
}
}
}
Expand Down Expand Up @@ -2348,6 +2351,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
Expand Down
Loading