mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 22:38:27 +08:00
move keyspace init function into namesys
This commit is contained in:
@ -10,7 +10,7 @@ import (
|
|||||||
cmds "github.com/jbenet/go-ipfs/commands"
|
cmds "github.com/jbenet/go-ipfs/commands"
|
||||||
core "github.com/jbenet/go-ipfs/core"
|
core "github.com/jbenet/go-ipfs/core"
|
||||||
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
|
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
|
||||||
ipns "github.com/jbenet/go-ipfs/fuse/ipns"
|
namesys "github.com/jbenet/go-ipfs/namesys"
|
||||||
config "github.com/jbenet/go-ipfs/repo/config"
|
config "github.com/jbenet/go-ipfs/repo/config"
|
||||||
fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
|
fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
|
||||||
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
||||||
@ -179,5 +179,5 @@ func initializeIpnsKeyspace(repoRoot string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipns.InitializeKeyspace(nd, nd.PrivateKey)
|
return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,13 @@ import (
|
|||||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
|
|
||||||
|
dag "github.com/jbenet/go-ipfs/merkledag"
|
||||||
pb "github.com/jbenet/go-ipfs/namesys/internal/pb"
|
pb "github.com/jbenet/go-ipfs/namesys/internal/pb"
|
||||||
ci "github.com/jbenet/go-ipfs/p2p/crypto"
|
ci "github.com/jbenet/go-ipfs/p2p/crypto"
|
||||||
|
pin "github.com/jbenet/go-ipfs/pin"
|
||||||
routing "github.com/jbenet/go-ipfs/routing"
|
routing "github.com/jbenet/go-ipfs/routing"
|
||||||
record "github.com/jbenet/go-ipfs/routing/record"
|
record "github.com/jbenet/go-ipfs/routing/record"
|
||||||
|
ft "github.com/jbenet/go-ipfs/unixfs"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,11 +63,9 @@ func (p *ipnsPublisher) Publish(ctx context.Context, k ci.PrivKey, value u.Key)
|
|||||||
nameb := u.Hash(pkbytes)
|
nameb := u.Hash(pkbytes)
|
||||||
namekey := u.Key("/pk/" + string(nameb))
|
namekey := u.Key("/pk/" + string(nameb))
|
||||||
|
|
||||||
timectx, cancel := context.WithDeadline(ctx, time.Now().Add(time.Second*10))
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
log.Debugf("Storing pubkey at: %s", namekey)
|
log.Debugf("Storing pubkey at: %s", namekey)
|
||||||
// Store associated public key
|
// Store associated public key
|
||||||
|
timectx, _ := context.WithDeadline(ctx, time.Now().Add(time.Second*10))
|
||||||
err = p.routing.PutValue(timectx, namekey, pkbytes)
|
err = p.routing.PutValue(timectx, namekey, pkbytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -136,3 +137,31 @@ func ValidateIpnsRecord(k u.Key, val []byte) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
emptyDir := &dag.Node{Data: ft.FolderPBData()}
|
||||||
|
nodek, err := ds.Add(emptyDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pins.Pin(emptyDir, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pins.Flush()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pub.Publish(ctx, key, nodek)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user