Skip to content

Commit

Permalink
Fix issue in ResourceManager and nopfsPlugin about repo path (#10492)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzie authored Sep 29, 2024
1 parent 9577527 commit a178307
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
fx.Provide(libp2p.UserAgent()),

// Services (resource management)
fx.Provide(libp2p.ResourceManager(cfg.Swarm, userResourceOverrides)),
fx.Provide(libp2p.ResourceManager(bcfg.Repo.Path(), cfg.Swarm, userResourceOverrides)),
fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
Expand Down
7 changes: 1 addition & 6 deletions core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const NetLimitTraceFilename = "rcmgr.json.gz"

var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")

func ResourceManager(cfg config.SwarmConfig, userResourceOverrides rcmgr.PartialLimitConfig) interface{} {
func ResourceManager(repoPath string, cfg config.SwarmConfig, userResourceOverrides rcmgr.PartialLimitConfig) interface{} {
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) {
var manager network.ResourceManager
var opts Libp2pOpts
Expand All @@ -46,11 +46,6 @@ func ResourceManager(cfg config.SwarmConfig, userResourceOverrides rcmgr.Partial
if enabled {
log.Debug("libp2p resource manager is enabled")

repoPath, err := config.PathRoot()
if err != nil {
return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err)
}

limitConfig, msg, err := LimitConfig(cfg, userResourceOverrides)
if err != nil {
return nil, opts, fmt.Errorf("creating final Resource Manager config: %w", err)
Expand Down
39 changes: 20 additions & 19 deletions plugin/plugins/nopfs/nopfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/ipfs-shipyard/nopfs"
"github.com/ipfs-shipyard/nopfs/ipfs"
"github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/core"
"github.com/ipfs/kubo/core/node"
"github.com/ipfs/kubo/plugin"
Expand All @@ -20,7 +19,10 @@ var Plugins = []plugin.Plugin{

// fxtestPlugin is used for testing the fx plugin.
// It merely adds an fx option that logs a debug statement, so we can verify that it works in tests.
type nopfsPlugin struct{}
type nopfsPlugin struct {
// Path to the IPFS repo.
repo string
}

var _ plugin.PluginFx = (*nopfsPlugin)(nil)

Expand All @@ -33,29 +35,28 @@ func (p *nopfsPlugin) Version() string {
}

func (p *nopfsPlugin) Init(env *plugin.Environment) error {
p.repo = env.Repo

return nil
}

// MakeBlocker is a factory for the blocker so that it can be provided with Fx.
func MakeBlocker() (*nopfs.Blocker, error) {
ipfsPath, err := config.PathRoot()
if err != nil {
return nil, err
}
func MakeBlocker(repoPath string) func() (*nopfs.Blocker, error) {
return func() (*nopfs.Blocker, error) {
defaultFiles, err := nopfs.GetDenylistFiles()
if err != nil {
return nil, err
}

defaultFiles, err := nopfs.GetDenylistFiles()
if err != nil {
return nil, err
}
kuboFiles, err := nopfs.GetDenylistFilesInDir(filepath.Join(repoPath, "denylists"))
if err != nil {
return nil, err
}

kuboFiles, err := nopfs.GetDenylistFilesInDir(filepath.Join(ipfsPath, "denylists"))
if err != nil {
return nil, err
}

files := append(defaultFiles, kuboFiles...)
files := append(defaultFiles, kuboFiles...)

return nopfs.NewBlocker(files)
return nopfs.NewBlocker(files)
}
}

// PathResolvers returns wrapped PathResolvers for Kubo.
Expand All @@ -76,7 +77,7 @@ func (p *nopfsPlugin) Options(info core.FXNodeInfo) ([]fx.Option, error) {

opts := append(
info.FXOptions,
fx.Provide(MakeBlocker),
fx.Provide(MakeBlocker(p.repo)),
fx.Decorate(ipfs.WrapBlockService),
fx.Decorate(ipfs.WrapNameSystem),
fx.Decorate(PathResolvers),
Expand Down
4 changes: 4 additions & 0 deletions repo/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (m *Mock) Config() (*config.Config, error) {
return &m.C, nil // FIXME threadsafety
}

func (m *Mock) Path() string {
return ""
}

func (m *Mock) UserResourceOverrides() (rcmgr.PartialLimitConfig, error) {
return rcmgr.PartialLimitConfig{}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Repo interface {
// to the returned config are not automatically persisted.
Config() (*config.Config, error)

// Path is the repo file-system path
Path() string

// UserResourceOverrides returns optional user resource overrides for the
// libp2p resource manager.
UserResourceOverrides() (rcmgr.PartialLimitConfig, error)
Expand Down

0 comments on commit a178307

Please sign in to comment.