@cryptotaxi247 / kubo / commits / c100b1be0

move keyspace init function into namesys

Jeromy committed Mar 17, 2015 at 15:39 UTC c100b1be04e8213b64dedfa76f103a2dcd30198c
2 files changed +34 -5
cmd/ipfs/init.go
+2 -2
@@ -10,7 +10,7 @@ import (
10 cmds "github.com/jbenet/go-ipfs/commands"
11 core "github.com/jbenet/go-ipfs/core"
12 coreunix "github.com/jbenet/go-ipfs/core/coreunix"
13 - ipns "github.com/jbenet/go-ipfs/fuse/ipns"
13 + namesys "github.com/jbenet/go-ipfs/namesys"
14 config "github.com/jbenet/go-ipfs/repo/config"
15 fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
16 uio "github.com/jbenet/go-ipfs/unixfs/io"
@@ -179,5 +179,5 @@ func initializeIpnsKeyspace(repoRoot string) error {
179 return err
180 }
181
182 - return ipns.InitializeKeyspace(nd, nd.PrivateKey)
182 + return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
183 }
namesys/publisher.go
+32 -3
@@ -10,10 +10,13 @@ import (
10 mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
11 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
12
13 + dag "github.com/jbenet/go-ipfs/merkledag"
14 pb "github.com/jbenet/go-ipfs/namesys/internal/pb"
15 ci "github.com/jbenet/go-ipfs/p2p/crypto"
16 + pin "github.com/jbenet/go-ipfs/pin"
17 routing "github.com/jbenet/go-ipfs/routing"
18 record "github.com/jbenet/go-ipfs/routing/record"
19 + ft "github.com/jbenet/go-ipfs/unixfs"
20 u "github.com/jbenet/go-ipfs/util"
21 )
22
@@ -60,11 +63,9 @@ func (p *ipnsPublisher) Publish(ctx context.Context, k ci.PrivKey, value u.Key)
63 nameb := u.Hash(pkbytes)
64 namekey := u.Key("/pk/" + string(nameb))
65
63 - timectx, cancel := context.WithDeadline(ctx, time.Now().Add(time.Second*10))
64 - defer cancel()
65 -
66 log.Debugf("Storing pubkey at: %s", namekey)
67 // Store associated public key
68 + timectx, _ := context.WithDeadline(ctx, time.Now().Add(time.Second*10))
69 err = p.routing.PutValue(timectx, namekey, pkbytes)
70 if err != nil {
71 return err
@@ -136,3 +137,31 @@ func ValidateIpnsRecord(k u.Key, val []byte) error {
137 }
138 return nil
139 }
140 +
141 +// InitializeKeyspace sets the ipns record for the given key to
142 +// point to an empty directory.
143 +// TODO: this doesnt feel like it belongs here
144 +func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
145 + emptyDir := &dag.Node{Data: ft.FolderPBData()}
146 + nodek, err := ds.Add(emptyDir)
147 + if err != nil {
148 + return err
149 + }
150 +
151 + err = pins.Pin(emptyDir, false)
152 + if err != nil {
153 + return err
154 + }
155 +
156 + err = pins.Flush()
157 + if err != nil {
158 + return err
159 + }
160 +
161 + err = pub.Publish(ctx, key, nodek)
162 + if err != nil {
163 + return err
164 + }
165 +
166 + return nil
167 +}