kubo/fuse/ipns/common.go
Jakub Sztandera 42e191c017 gx: unrewrite
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
2019-03-05 18:33:56 +01:00

35 lines
735 B
Go

package ipns
import (
"context"
"github.com/ipfs/go-ipfs/core"
nsys "github.com/ipfs/go-ipfs/namesys"
path "github.com/ipfs/go-path"
ft "github.com/ipfs/go-unixfs"
ci "github.com/libp2p/go-libp2p-crypto"
)
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
ctx, cancel := context.WithCancel(n.Context())
defer cancel()
emptyDir := ft.EmptyDirNode()
err := n.Pinning.Pin(ctx, emptyDir, false)
if err != nil {
return err
}
err = n.Pinning.Flush()
if err != nil {
return err
}
pub := nsys.NewIpnsPublisher(n.Routing, n.Repo.Datastore())
return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}