Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skip changelog]Fix issue in ResourceManager and nopfsPlugin about repo path #10492

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +26 to +27
Copy link
Member

@lidel lidel Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about in-memory or remote / virtual repos?

my understanding is that reading path from config makes more sense, because we know that the config file in filesystem somewhere, and resourcemanager or nopfs files could live there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently only FSRepo is provided. For the other kind of repo implementations, there should be design to be compatible with resourcemanager or nopfs.

func (r *FSRepo) Path() string {


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