Skip to content

Commit

Permalink
chore(config): remove Swarm.ConnMgr defaults from user config
Browse files Browse the repository at this point in the history
  • Loading branch information
schomatis committed Apr 27, 2022
1 parent d4879a4 commit c1c92db
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
12 changes: 4 additions & 8 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ func InitWithIdentity(identity Identity) (*Config, error) {
Interval: "12h",
Strategy: "all",
},
Swarm: SwarmConfig{
ConnMgr: ConnMgr{
LowWater: DefaultConnMgrLowWater,
HighWater: DefaultConnMgrHighWater,
GracePeriod: DefaultConnMgrGracePeriod.String(),
Type: "basic",
},
},
Pinning: Pinning{
RemoteServices: map[string]RemotePinningService{},
},
Expand Down Expand Up @@ -113,6 +105,10 @@ const DefaultConnMgrLowWater = 600
// grace period
const DefaultConnMgrGracePeriod = time.Second * 20

// DefaultConnMgrType is the default value for the connection managers
// type.
const DefaultConnMgrType = "basic"

func addressesConfig() Addresses {
return Addresses{
Swarm: []string{
Expand Down
9 changes: 6 additions & 3 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ fetching may be degraded.
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
c.Reprovider.Interval = "0"

c.Swarm.ConnMgr.LowWater = 20
c.Swarm.ConnMgr.HighWater = 40
c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
lowWater := int64(20)
highWater := int64(40)
gracePeriod := time.Minute
c.Swarm.ConnMgr.LowWater = &OptionalInteger{value: &lowWater}
c.Swarm.ConnMgr.HighWater = &OptionalInteger{value: &highWater}
c.Swarm.ConnMgr.GracePeriod = &OptionalDuration{&gracePeriod}
return nil
},
},
Expand Down
8 changes: 4 additions & 4 deletions config/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ type Transports struct {

// ConnMgr defines configuration options for the libp2p connection manager
type ConnMgr struct {
Type string
LowWater int
HighWater int
GracePeriod string
Type *OptionalString `json:",omitempty"`
LowWater *OptionalInteger `json:",omitempty"`
HighWater *OptionalInteger `json:",omitempty"`
GracePeriod *OptionalDuration `json:",omitempty"`
}

// ResourceMgr defines configuration options for the libp2p Network Resource Manager
Expand Down
19 changes: 8 additions & 11 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,19 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {

connmgr := fx.Options()

if cfg.Swarm.ConnMgr.Type != "none" {
switch cfg.Swarm.ConnMgr.Type {
connMgrType := cfg.Swarm.ConnMgr.Type.WithDefault(config.DefaultConnMgrType)
if connMgrType != "none" {
switch connMgrType {
case "":
// 'default' value is the basic connection manager
break
case "basic":
var err error
grace, err = time.ParseDuration(cfg.Swarm.ConnMgr.GracePeriod)
if err != nil {
return fx.Error(fmt.Errorf("parsing Swarm.ConnMgr.GracePeriod: %s", err))
}

low = cfg.Swarm.ConnMgr.LowWater
high = cfg.Swarm.ConnMgr.HighWater
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))
default:
return fx.Error(fmt.Errorf("unrecognized ConnMgr.Type: %q", cfg.Swarm.ConnMgr.Type))
return fx.Error(fmt.Errorf("unrecognized ConnMgr.Type: %q", connMgrType))
}

connmgr = fx.Provide(libp2p.ConnectionManager(low, high, grace))
Expand Down
4 changes: 2 additions & 2 deletions core/node/libp2p/rcmgr_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func adjustedDefaultLimits(cfg config.SwarmConfig) rcmgr.DefaultLimitConfig {
defaultLimits := rcmgr.DefaultLimits.WithSystemMemory(.125, 1<<30, 4<<30)

// Do we need to adjust due to Swarm.ConnMgr.HighWater?
if cfg.ConnMgr.Type == "basic" {
maxconns := cfg.ConnMgr.HighWater
if cfg.ConnMgr.Type.WithDefault(config.DefaultConnMgrType) == config.DefaultConnMgrType {
maxconns := int(cfg.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater))
if 2*maxconns > defaultLimits.SystemBaseLimit.ConnsInbound {
// adjust conns to 2x to allow for two conns per peer (TCP+QUIC)
defaultLimits.SystemBaseLimit.ConnsInbound = logScale(2 * maxconns)
Expand Down

0 comments on commit c1c92db

Please sign in to comment.