Skip to content

Commit

Permalink
Update with latest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro committed Feb 3, 2023
1 parent 4eb9701 commit d9bb868
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Changes made via command line are persisted in the Swarm.ResourceMgr.Limits fiel

// set scope limit to new values (when limit.json is passed as a second arg)
if req.Files != nil {
var newLimit *rcmgr.ResourceLimits
var newLimit rcmgr.ResourceLimits
it := req.Files.Entries()
if it.Next() {
file := files.FileFromEntry(it)
Expand Down
40 changes: 20 additions & 20 deletions core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,21 +333,21 @@ func NetLimitAll(mgr network.ResourceManager) (*NetStatOut, error) {
if err != nil {
return nil, err
}
result.System = s
result.System = &s
case config.ResourceMgrTransientScope:
s, err := NetLimit(mgr, config.ResourceMgrSystemScope)
if err != nil {
return nil, err
}
result.Transient = s
result.Transient = &s
case config.ResourceMgrServiceScopePrefix:
result.Services = make(map[string]rcmgr.ResourceLimits)
for _, serv := range lister.ListServices() {
s, err := NetLimit(mgr, config.ResourceMgrServiceScopePrefix+serv)
if err != nil {
return nil, err
}
result.Services[serv] = *s
result.Services[serv] = s
}
case config.ResourceMgrProtocolScopePrefix:
result.Protocols = make(map[string]rcmgr.ResourceLimits)
Expand All @@ -357,7 +357,7 @@ func NetLimitAll(mgr network.ResourceManager) (*NetStatOut, error) {
if err != nil {
return nil, err
}
result.Protocols[ps] = *s
result.Protocols[ps] = s
}
case config.ResourceMgrPeerScopePrefix:
result.Peers = make(map[string]rcmgr.ResourceLimits)
Expand All @@ -367,16 +367,16 @@ func NetLimitAll(mgr network.ResourceManager) (*NetStatOut, error) {
if err != nil {
return nil, err
}
result.Peers[ps] = *s
result.Peers[ps] = s
}
}
}

return result, nil
}

func NetLimit(mgr network.ResourceManager, scope string) (*rcmgr.ResourceLimits, error) {
var result *rcmgr.ResourceLimits
func NetLimit(mgr network.ResourceManager, scope string) (rcmgr.ResourceLimits, error) {
var result rcmgr.ResourceLimits
getLimit := func(s network.ResourceScope) error {
limiter, ok := s.(rcmgr.ResourceScopeLimiter)
if !ok { // NullResourceManager
Expand Down Expand Up @@ -417,7 +417,7 @@ func NetLimit(mgr network.ResourceManager, scope string) (*rcmgr.ResourceLimits,
}

// NetSetLimit sets new ResourceManager limits for the given scope. The limits take effect immediately, and are also persisted to the repo config.
func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limit *rcmgr.ResourceLimits) error {
func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limit rcmgr.ResourceLimits) error {
setLimit := func(s network.ResourceScope) error {
limiter, ok := s.(rcmgr.ResourceScopeLimiter)
if !ok { // NullResourceManager
Expand Down Expand Up @@ -454,7 +454,7 @@ func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limi
if configLimits.Service == nil {
configLimits.Service = map[string]rcmgr.ResourceLimits{}
}
configLimits.Service[svc] = *limit
configLimits.Service[svc] = limit
}
case strings.HasPrefix(scope, config.ResourceMgrProtocolScopePrefix):
proto := strings.TrimPrefix(scope, config.ResourceMgrProtocolScopePrefix)
Expand All @@ -463,7 +463,7 @@ func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limi
if configLimits.Protocol == nil {
configLimits.Protocol = map[protocol.ID]rcmgr.ResourceLimits{}
}
configLimits.Protocol[protocol.ID(proto)] = *limit
configLimits.Protocol[protocol.ID(proto)] = limit
}
case strings.HasPrefix(scope, config.ResourceMgrPeerScopePrefix):
p := strings.TrimPrefix(scope, config.ResourceMgrPeerScopePrefix)
Expand All @@ -477,7 +477,7 @@ func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limi
if configLimits.Peer == nil {
configLimits.Peer = map[peer.ID]rcmgr.ResourceLimits{}
}
configLimits.Peer[pid] = *limit
configLimits.Peer[pid] = limit
}
default:
return fmt.Errorf("invalid scope %q", scope)
Expand All @@ -500,10 +500,10 @@ func NetSetLimit(mgr network.ResourceManager, repo repo.Repo, scope string, limi
}

// 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.ResourceLimits, error) {
var result *rcmgr.ResourceLimits
func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (rcmgr.ResourceLimits, error) {
var result rcmgr.ResourceLimits

setLimit := func(s network.ResourceScope, limit *rcmgr.ResourceLimits) error {
setLimit := func(s network.ResourceScope, limit rcmgr.ResourceLimits) error {
limiter, ok := s.(rcmgr.ResourceScopeLimiter)
if !ok {
return ErrNoResourceMgr
Expand Down Expand Up @@ -535,10 +535,10 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (*
switch {
case scope == config.ResourceMgrSystemScope:
err = mgr.ViewSystem(func(s network.ResourceScope) error { return setLimit(s, defaults.System) })
configLimits.System = nil
configLimits.System = rcmgr.ResourceLimits{}
case scope == config.ResourceMgrTransientScope:
err = mgr.ViewTransient(func(s network.ResourceScope) error { return setLimit(s, defaults.Transient) })
configLimits.Transient = nil
configLimits.Transient = rcmgr.ResourceLimits{}
case strings.HasPrefix(scope, config.ResourceMgrServiceScopePrefix):
svc := strings.TrimPrefix(scope, config.ResourceMgrServiceScopePrefix)

Expand Down Expand Up @@ -595,30 +595,30 @@ func ensureConnMgrMakeSenseVsResourceMgr(concreteLimits rcmgr.ConcreteLimitConfi
rcm := concreteLimits.ToLimitConfig()

highWater := cmgr.HighWater.WithDefault(config.DefaultConnMgrHighWater)
if rcm.System.ConnsInbound <= rcm.System.Conns {
if rcm.System.ConnsInbound <= rcm.System.Conns && rcm.System.ConnsInbound != rcmgr.Unlimited {
if int64(rcm.System.ConnsInbound) <= highWater {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.ConnsInbound (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.ConnsInbound, highWater)
}
} else if int64(rcm.System.Conns) <= highWater {
} else if int64(rcm.System.Conns) <= highWater && rcm.System.Conns != rcmgr.Unlimited {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.Conns (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.Conns, highWater)
}
if rcm.System.StreamsInbound <= rcm.System.Streams {
if rcm.System.StreamsInbound <= rcm.System.Streams && rcm.System.StreamsInbound != rcmgr.Unlimited {
if int64(rcm.System.StreamsInbound) <= highWater {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.StreamsInbound (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.StreamsInbound, highWater)
}
} else if int64(rcm.System.Streams) <= highWater {
} else if int64(rcm.System.Streams) <= highWater && rcm.System.Streams != rcmgr.Unlimited {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
Expand Down
8 changes: 4 additions & 4 deletions core/node/libp2p/rcmgr_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ipfs/kubo/core/node/libp2p/fd"
)

var infiniteResourceLimit = &rcmgr.ResourceLimits{
var infiniteResourceLimit = rcmgr.ResourceLimits{
Streams: rcmgr.Unlimited,
StreamsInbound: rcmgr.Unlimited,
StreamsOutbound: rcmgr.Unlimited,
Expand Down Expand Up @@ -61,7 +61,7 @@ Run 'ipfs swarm limit all' to see the resulting limits.
systemConnsInbound := int(1 * maxMemoryMB)

partialLimits := rcmgr.PartialLimitConfig{
System: &rcmgr.ResourceLimits{
System: rcmgr.ResourceLimits{
Memory: rcmgr.LimitVal64(maxMemory),
FD: rcmgr.LimitVal(maxFD),

Expand All @@ -78,7 +78,7 @@ Run 'ipfs swarm limit all' to see the resulting limits.
// Only established connections do.
// As a result, we can't rely on System.Memory to protect us from a bunch of transient connection being opened.
// We limit the same values as the System scope, but only allow the Transient scope to take 25% of what is allowed for the System scope.
Transient: &rcmgr.ResourceLimits{
Transient: rcmgr.ResourceLimits{
Memory: rcmgr.LimitVal64(maxMemory / 4),
FD: rcmgr.LimitVal(maxFD / 4),

Expand Down Expand Up @@ -115,7 +115,7 @@ Run 'ipfs swarm limit all' to see the resulting limits.
// We specify this limit against unintentional DoS attacks (e.g., a peer has a bug and is sending too much traffic intentionally).
// In that case we want to keep that peer's resource consumption contained.
// To keep this simple, we only constrain inbound connections and streams.
PeerDefault: &rcmgr.ResourceLimits{
PeerDefault: rcmgr.ResourceLimits{
Memory: rcmgr.Unlimited64,
FD: rcmgr.Unlimited,
Conns: rcmgr.Unlimited,
Expand Down
2 changes: 1 addition & 1 deletion core/node/libp2p/rcmgr_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func TestLoggingResourceManager(t *testing.T) {
clock := clock.NewMock()
partialLimits := rcmgr.PartialLimitConfig{
System: &rcmgr.ResourceLimits{
System: rcmgr.ResourceLimits{
Conns: 1,
ConnsInbound: 1,
ConnsOutbound: 1,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-doh-resolver v0.4.0
github.com/libp2p/go-libp2p v0.24.3-0.20230120204155-c68e24ccd286
github.com/libp2p/go-libp2p v0.24.3-0.20230131210643-75c0b1418e10
github.com/libp2p/go-libp2p-http v0.4.0
github.com/libp2p/go-libp2p-kad-dht v0.20.0
github.com/libp2p/go-libp2p-kbucket v0.5.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ github.com/libp2p/go-libp2p v0.8.1/go.mod h1:QRNH9pwdbEBpx5DTJYg+qxcVaDMAz3Ee/qD
github.com/libp2p/go-libp2p v0.14.3/go.mod h1:d12V4PdKbpL0T1/gsUNN8DfgMuRPDX8bS2QxCZlwRH0=
github.com/libp2p/go-libp2p v0.24.3-0.20230120204155-c68e24ccd286 h1:wgKtjGrXdLm1OqPAwgZzt6JpfCs383lF8Qa5brUUezo=
github.com/libp2p/go-libp2p v0.24.3-0.20230120204155-c68e24ccd286/go.mod h1:ZqQXmVB7kTkKtm+LoPODTqgKE/j/nMPpRWDgw5Lcvog=
github.com/libp2p/go-libp2p v0.24.3-0.20230131210643-75c0b1418e10 h1:bfe8H5Tj/N6yNl2LfN8Lv7k7ESJ12xDh3x1LVrrStII=
github.com/libp2p/go-libp2p v0.24.3-0.20230131210643-75c0b1418e10/go.mod h1:ZqQXmVB7kTkKtm+LoPODTqgKE/j/nMPpRWDgw5Lcvog=
github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw=
github.com/libp2p/go-libp2p-asn-util v0.2.0/go.mod h1:WoaWxbHKBymSN41hWSq/lGKJEca7TNm58+gGJi2WsLI=
github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8=
Expand Down

0 comments on commit d9bb868

Please sign in to comment.