Commit 924b2a0a authored by Steven Allen's avatar Steven Allen

don't add nodes to DAG twice.

Now that we add nodes to the DAG when pinning, don't bother adding them twice.

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 953b6104
......@@ -80,11 +80,6 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
return nil, err
}
dcid, err := nd.DAG.Add(dir)
if err != nil {
return nil, fmt.Errorf("assets: DAG.Add(dir) failed: %s", err)
}
if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil {
return nil, fmt.Errorf("assets: Pinning on init-docu failed: %s", err)
}
......@@ -93,5 +88,5 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
return nil, fmt.Errorf("assets: Pinning flush failed: %s", err)
}
return dcid, nil
return dir.Cid(), nil
}
......@@ -260,5 +260,5 @@ func initializeIpnsKeyspace(repoRoot string) error {
return err
}
return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
return namesys.InitializeKeyspace(ctx, nd.Namesys, nd.Pinning, nd.PrivateKey)
}
......@@ -13,16 +13,12 @@ import (
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
emptyDir := ft.EmptyDirNode()
nodek, err := n.DAG.Add(emptyDir)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(n.Context())
defer cancel()
err = n.Pinning.Pin(ctx, emptyDir, false)
emptyDir := ft.EmptyDirNode()
err := n.Pinning.Pin(ctx, emptyDir, false)
if err != nil {
return err
}
......@@ -34,5 +30,5 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore())
return pub.Publish(ctx, key, path.FromCid(nodek))
return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}
......@@ -7,7 +7,6 @@ import (
"fmt"
"time"
dag "github.com/ipfs/go-ipfs/merkledag"
pb "github.com/ipfs/go-ipfs/namesys/pb"
path "github.com/ipfs/go-ipfs/path"
pin "github.com/ipfs/go-ipfs/pin"
......@@ -321,16 +320,12 @@ func ValidateIpnsRecord(k string, val []byte) error {
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
// TODO: this doesnt feel like it belongs here
func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
func InitializeKeyspace(ctx context.Context, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
emptyDir := ft.EmptyDirNode()
nodek, err := ds.Add(emptyDir)
if err != nil {
return err
}
// pin recursively because this might already be pinned
// and doing a direct pin would throw an error in that case
err = pins.Pin(ctx, emptyDir, true)
err := pins.Pin(ctx, emptyDir, true)
if err != nil {
return err
}
......@@ -340,7 +335,7 @@ func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, p
return err
}
return pub.Publish(ctx, key, path.FromCid(nodek))
return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}
func IpnsKeysForID(id peer.ID) (name, ipns string) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment