diff --git a/core/node/libp2p/rcmgr.go b/core/node/libp2p/rcmgr.go index 05018630575..64f225f30ae 100644 --- a/core/node/libp2p/rcmgr.go +++ b/core/node/libp2p/rcmgr.go @@ -348,7 +348,7 @@ func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limi return nil } -// NetSetLimit sets new ResourceManager limits for the given scope. The limits take effect immediately, and are also persisted to the repo config. +// NetResetLimit resets ResourceManager limits to defaults. The limits take effect immediately, and are also persisted to the repo config. func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (rcmgr.BaseLimit, error) { var result rcmgr.BaseLimit @@ -373,21 +373,19 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r cfg.Swarm.ResourceMgr.Limits = &rcmgr.LimitConfig{} } configLimits := cfg.Swarm.ResourceMgr.Limits - var empty rcmgr.BaseLimit var setConfigFunc func() rcmgr.BaseLimit switch { case scope == config.ResourceMgrSystemScope: err = mgr.ViewSystem(func(s network.ResourceScope) error { return setLimit(s, &defaults.System) }) setConfigFunc = func() rcmgr.BaseLimit { - configLimits.System = empty - + configLimits.System = defaults.System return defaults.System } case scope == config.ResourceMgrTransientScope: err = mgr.ViewTransient(func(s network.ResourceScope) error { return setLimit(s, &defaults.Transient) }) setConfigFunc = func() rcmgr.BaseLimit { - configLimits.Transient = empty + configLimits.Transient = defaults.Transient return defaults.Transient } case strings.HasPrefix(scope, config.ResourceMgrServiceScopePrefix): @@ -397,21 +395,19 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r // reset defaults err = mgr.ViewSystem(func(s network.ResourceScope) error { return setLimit(s, &defaults.ServiceDefault) }) setConfigFunc = func() rcmgr.BaseLimit { - configLimits.ServiceDefault = empty + configLimits.ServiceDefault = defaults.ServiceDefault return defaults.ServiceDefault } break } - ds := defaults.Service[svc] - - err = mgr.ViewService(svc, func(s network.ServiceScope) error { return setLimit(s, &ds) }) + err = mgr.ViewService(svc, func(s network.ServiceScope) error { return setLimit(s, &defaults.ServiceDefault) }) setConfigFunc = func() rcmgr.BaseLimit { if configLimits.Service == nil { configLimits.Service = map[string]rcmgr.BaseLimit{} } - configLimits.Service[svc] = empty - return ds + configLimits.Service[svc] = defaults.ServiceDefault + return defaults.ServiceDefault } case strings.HasPrefix(scope, config.ResourceMgrProtocolScopePrefix): proto := strings.TrimPrefix(scope, config.ResourceMgrProtocolScopePrefix) @@ -420,23 +416,21 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r // reset defaults err = mgr.ViewSystem(func(s network.ResourceScope) error { return setLimit(s, &defaults.ProtocolDefault) }) setConfigFunc = func() rcmgr.BaseLimit { - configLimits.ProtocolDefault = empty + configLimits.ProtocolDefault = defaults.ProtocolDefault return defaults.ProtocolDefault } break } - dp := defaults.Protocol[protocol.ID(proto)] - - err = mgr.ViewProtocol(protocol.ID(proto), func(s network.ProtocolScope) error { return setLimit(s, &dp) }) + err = mgr.ViewProtocol(protocol.ID(proto), func(s network.ProtocolScope) error { return setLimit(s, &defaults.ProtocolDefault) }) setConfigFunc = func() rcmgr.BaseLimit { if configLimits.Protocol == nil { configLimits.Protocol = map[protocol.ID]rcmgr.BaseLimit{} } - configLimits.Protocol[protocol.ID(proto)] = empty + configLimits.Protocol[protocol.ID(proto)] = defaults.ProtocolDefault - return dp + return defaults.ProtocolDefault } case strings.HasPrefix(scope, config.ResourceMgrPeerScopePrefix): p := strings.TrimPrefix(scope, config.ResourceMgrPeerScopePrefix) @@ -445,7 +439,7 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r // reset defaults err = mgr.ViewSystem(func(s network.ResourceScope) error { return setLimit(s, &defaults.PeerDefault) }) setConfigFunc = func() rcmgr.BaseLimit { - configLimits.PeerDefault = empty + configLimits.PeerDefault = defaults.PeerDefault return defaults.PeerDefault } @@ -458,16 +452,14 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r return result, fmt.Errorf("invalid peer ID: %q: %w", p, err) } - dp := defaults.Peer[pid] - - err = mgr.ViewPeer(pid, func(s network.PeerScope) error { return setLimit(s, &dp) }) + err = mgr.ViewPeer(pid, func(s network.PeerScope) error { return setLimit(s, &defaults.PeerDefault) }) setConfigFunc = func() rcmgr.BaseLimit { if configLimits.Peer == nil { configLimits.Peer = map[peer.ID]rcmgr.BaseLimit{} } - configLimits.Peer[pid] = empty + configLimits.Peer[pid] = defaults.PeerDefault - return dp + return defaults.PeerDefault } default: return result, fmt.Errorf("invalid scope %q", scope)