From 98d342b0621abe264dc7a782f874225b83ae9a99 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 26 Sep 2022 00:35:04 +0200 Subject: [PATCH 1/2] Override checkPublishAllowed when the IPNS Fuse mount writes changes Fixes #2168 --- core/coreapi/coreapi.go | 6 +++--- core/coreapi/name.go | 7 ++++--- fuse/ipns/ipns_unix.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index 515da6930fa..4f59ced92d9 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -73,7 +73,7 @@ type CoreAPI struct { pubSub *pubsub.PubSub - checkPublishAllowed func() error + checkPublishAllowed func(allowWhileMounted bool) error checkOnline func(allowOffline bool) error // ONLY for re-applying options in WithOptions, DO NOT USE ANYWHERE ELSE @@ -197,8 +197,8 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e return nil } - subApi.checkPublishAllowed = func() error { - if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() { + subApi.checkPublishAllowed = func(allowWhileMounted bool) error { + if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() && !allowWhileMounted { return errors.New("cannot manually publish while IPNS is mounted") } return nil diff --git a/core/coreapi/name.go b/core/coreapi/name.go index 69dc1137bf0..d77dcc393db 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -44,14 +44,15 @@ func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.Nam ctx, span := tracing.Span(ctx, "CoreAPI.NameAPI", "Publish", trace.WithAttributes(attribute.String("path", p.String()))) defer span.End() - if err := api.checkPublishAllowed(); err != nil { + options, err := caopts.NamePublishOptions(opts...) + if err != nil { return nil, err } - options, err := caopts.NamePublishOptions(opts...) - if err != nil { + if err := api.checkPublishAllowed(options.AllowWhileMounted); err != nil { return nil, err } + span.SetAttributes( attribute.Bool("allowoffline", options.AllowOffline), attribute.String("key", options.Key), diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index e1840d25964..87ec5866927 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -85,7 +85,7 @@ type Root struct { func ipnsPubFunc(ipfs iface.CoreAPI, key iface.Key) mfs.PubFunc { return func(ctx context.Context, c cid.Cid) error { - _, err := ipfs.Name().Publish(ctx, path.IpfsPath(c), options.Name.Key(key.Name())) + _, err := ipfs.Name().Publish(ctx, path.IpfsPath(c), options.Name.Key(key.Name()), options.Name.AllowWhileMounted(true)) return err } } From f617d51a288606794406eedeacab95c3f9628896 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 26 Sep 2022 09:23:08 +0200 Subject: [PATCH 2/2] IPNS mount: add all keys pointing to valid protobuf data Locally I have some raw DAG nodes on other keys, which would cause a fatal error if they were not skipped. Since we have no defined way to map IPLD/CBOR to a virtual filesystem yet, skip them for now. --- fuse/ipns/ipns_unix.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index 87ec5866927..1fb4bd79e86 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -44,11 +44,28 @@ type FileSystem struct { // NewFileSystem constructs new fs using given core.IpfsNode instance. func NewFileSystem(ctx context.Context, ipfs iface.CoreAPI, ipfspath, ipnspath string) (*FileSystem, error) { - key, err := ipfs.Key().Self(ctx) + + keys, err := ipfs.Key().List(ctx) + if err != nil { + return nil, err + } + + selfkey, err := ipfs.Key().Self(ctx) if err != nil { return nil, err } - root, err := CreateRoot(ctx, ipfs, map[string]iface.Key{"local": key}, ipfspath, ipnspath) + + var keymap = make(map[string]iface.Key) + keymap["local"] = selfkey + for _, k := range keys { + if k.ID() == selfkey.ID() { + continue + } + keymap[k.Name()] = k + } + + fmt.Println(keymap) + root, err := CreateRoot(ctx, ipfs, keymap, ipfspath, ipnspath) if err != nil { return nil, err } @@ -120,6 +137,11 @@ func CreateRoot(ctx context.Context, ipfs iface.CoreAPI, keys map[string]iface.K links := make(map[string]*Link) for alias, k := range keys { root, fsn, err := loadRoot(ctx, ipfs, k) + if err == dag.ErrNotProtobuf { + log.Errorf("skipping non-protobuf key %s: %s", alias, k.Path()) + delete(keys, alias) + continue + } if err != nil { return nil, err }