Skip to content

Commit

Permalink
fix: update rcmgr for go-libp2p v0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Feb 14, 2023
1 parent f0db906 commit c1dbbba
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 366 deletions.
4 changes: 2 additions & 2 deletions config/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ type ConnMgr struct {
// <https://github.com/libp2p/go-libp2p/tree/master/p2p/host/resource-manager#readme>
type ResourceMgr struct {
// Enables the Network Resource Manager feature, default to on.
Enabled Flag `json:",omitempty"`
Limits *rcmgr.LimitConfig `json:",omitempty"`
Enabled Flag `json:",omitempty"`
Limits *rcmgr.PartialLimitConfig `json:",omitempty"`

MaxMemory *OptionalString `json:",omitempty"`
MaxFileDescriptors *OptionalInteger `json:",omitempty"`
Expand Down
19 changes: 11 additions & 8 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ var swarmPeeringCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Modify the peering subsystem.",
ShortDescription: `
'ipfs swarm peering' manages the peering subsystem.
Peers in the peering subsystem are maintained to be connected, reconnected
'ipfs swarm peering' manages the peering subsystem.
Peers in the peering subsystem are maintained to be connected, reconnected
on disconnect with a back-off.
The changes are not saved to the config.
`,
Expand Down 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.BaseLimit
var newLimit rcmgr.ResourceLimits
it := req.Files.Entries()
if it.Next() {
file := files.FileFromEntry(it)
Expand All @@ -451,20 +451,23 @@ Changes made via command line are persisted in the Swarm.ResourceMgr.Limits fiel
}

var result interface{}
_, reset := req.Options[swarmResetLimitsOptionName]
if reset {
switch _, reset := req.Options[swarmResetLimitsOptionName]; {
case reset:
result, err = libp2p.NetResetLimit(node.ResourceManager, node.Repo, scope)
} else if scope == "all" {
case scope == "all":
result, err = libp2p.NetLimitAll(node.ResourceManager)
} else {
default:
// get scope limit
result, err = libp2p.NetLimit(node.ResourceManager, scope)
}

if err != nil {
return err
}

if base, ok := result.(rcmgr.BaseLimit); ok {
result = base.ToResourceLimits()
}

b := new(bytes.Buffer)
enc := json.NewEncoder(b)
err = enc.Encode(result)
Expand Down
Loading

0 comments on commit c1dbbba

Please sign in to comment.