@cryptotaxi247 / kubo / commits / a17830754

Fix issue in ResourceManager and nopfsPlugin about repo path (#10492)

fengzie committed Sep 29, 2024 at 11:58 UTC a17830754ccb22ef1ae8a63f30643c41eb35f01d
5 files changed +29 -26
core/node/groups.go
+1 -1
@@ -132,7 +132,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
132 fx.Provide(libp2p.UserAgent()),
133
134 // Services (resource management)
135 - fx.Provide(libp2p.ResourceManager(cfg.Swarm, userResourceOverrides)),
135 + fx.Provide(libp2p.ResourceManager(bcfg.Repo.Path(), cfg.Swarm, userResourceOverrides)),
136 fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
137 fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
138 fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
core/node/libp2p/rcmgr.go
+1 -6
@@ -28,7 +28,7 @@ const NetLimitTraceFilename = "rcmgr.json.gz"
28
29 var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")
30
31 -func ResourceManager(cfg config.SwarmConfig, userResourceOverrides rcmgr.PartialLimitConfig) interface{} {
31 +func ResourceManager(repoPath string, cfg config.SwarmConfig, userResourceOverrides rcmgr.PartialLimitConfig) interface{} {
32 return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) {
33 var manager network.ResourceManager
34 var opts Libp2pOpts
@@ -46,11 +46,6 @@ func ResourceManager(cfg config.SwarmConfig, userResourceOverrides rcmgr.Partial
46 if enabled {
47 log.Debug("libp2p resource manager is enabled")
48
49 - repoPath, err := config.PathRoot()
50 - if err != nil {
51 - return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err)
52 - }
53 -
49 limitConfig, msg, err := LimitConfig(cfg, userResourceOverrides)
50 if err != nil {
51 return nil, opts, fmt.Errorf("creating final Resource Manager config: %w", err)
plugin/plugins/nopfs/nopfs.go
+20 -19
@@ -6,7 +6,6 @@ import (
6
7 "github.com/ipfs-shipyard/nopfs"
8 "github.com/ipfs-shipyard/nopfs/ipfs"
9 - "github.com/ipfs/kubo/config"
9 "github.com/ipfs/kubo/core"
10 "github.com/ipfs/kubo/core/node"
11 "github.com/ipfs/kubo/plugin"
@@ -20,7 +19,10 @@ var Plugins = []plugin.Plugin{
19
20 // fxtestPlugin is used for testing the fx plugin.
21 // It merely adds an fx option that logs a debug statement, so we can verify that it works in tests.
23 -type nopfsPlugin struct{}
22 +type nopfsPlugin struct {
23 + // Path to the IPFS repo.
24 + repo string
25 +}
26
27 var _ plugin.PluginFx = (*nopfsPlugin)(nil)
28
@@ -33,29 +35,28 @@ func (p *nopfsPlugin) Version() string {
35 }
36
37 func (p *nopfsPlugin) Init(env *plugin.Environment) error {
38 + p.repo = env.Repo
39 +
40 return nil
41 }
42
43 // MakeBlocker is a factory for the blocker so that it can be provided with Fx.
40 -func MakeBlocker() (*nopfs.Blocker, error) {
41 - ipfsPath, err := config.PathRoot()
42 - if err != nil {
43 - return nil, err
44 - }
44 +func MakeBlocker(repoPath string) func() (*nopfs.Blocker, error) {
45 + return func() (*nopfs.Blocker, error) {
46 + defaultFiles, err := nopfs.GetDenylistFiles()
47 + if err != nil {
48 + return nil, err
49 + }
50
46 - defaultFiles, err := nopfs.GetDenylistFiles()
47 - if err != nil {
48 - return nil, err
49 - }
51 + kuboFiles, err := nopfs.GetDenylistFilesInDir(filepath.Join(repoPath, "denylists"))
52 + if err != nil {
53 + return nil, err
54 + }
55
51 - kuboFiles, err := nopfs.GetDenylistFilesInDir(filepath.Join(ipfsPath, "denylists"))
52 - if err != nil {
53 - return nil, err
54 - }
55 -
56 - files := append(defaultFiles, kuboFiles...)
56 + files := append(defaultFiles, kuboFiles...)
57
58 - return nopfs.NewBlocker(files)
58 + return nopfs.NewBlocker(files)
59 + }
60 }
61
62 // PathResolvers returns wrapped PathResolvers for Kubo.
@@ -76,7 +77,7 @@ func (p *nopfsPlugin) Options(info core.FXNodeInfo) ([]fx.Option, error) {
77
78 opts := append(
79 info.FXOptions,
79 - fx.Provide(MakeBlocker),
80 + fx.Provide(MakeBlocker(p.repo)),
81 fx.Decorate(ipfs.WrapBlockService),
82 fx.Decorate(ipfs.WrapNameSystem),
83 fx.Decorate(PathResolvers),
repo/mock.go
+4
@@ -27,6 +27,10 @@ func (m *Mock) Config() (*config.Config, error) {
27 return &m.C, nil // FIXME threadsafety
28 }
29
30 +func (m *Mock) Path() string {
31 + return ""
32 +}
33 +
34 func (m *Mock) UserResourceOverrides() (rcmgr.PartialLimitConfig, error) {
35 return rcmgr.PartialLimitConfig{}, nil
36 }
repo/repo.go
+3
@@ -23,6 +23,9 @@ type Repo interface {
23 // to the returned config are not automatically persisted.
24 Config() (*config.Config, error)
25
26 + // Path is the repo file-system path
27 + Path() string
28 +
29 // UserResourceOverrides returns optional user resource overrides for the
30 // libp2p resource manager.
31 UserResourceOverrides() (rcmgr.PartialLimitConfig, error)