make the default repo for corebuilder work
Jeromy committed
Jun 1, 2015 at 14:24 UTC
6b16981979c896fa11d81528c8a31474d5fea9dd
1 file changed
+34
-3
core/builder.go
+34
-3
@@ -1,12 +1,17 @@
1
package core
2
3
import (
4
+ "crypto/rand"
5
+ "encoding/base64"
6
"errors"
7
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
9
dsync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
10
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
11
+ key "github.com/ipfs/go-ipfs/blocks/key"
12
+ ci "github.com/ipfs/go-ipfs/p2p/crypto"
13
repo "github.com/ipfs/go-ipfs/repo"
14
+ cfg "github.com/ipfs/go-ipfs/repo/config"
15
)
16
17
var ErrAlreadyBuilt = errors.New("this builder has already been used")
@@ -28,10 +33,32 @@ func NewNodeBuilder() *NodeBuilder {
33
}
34
}
35
31
-func defaultRepo() repo.Repo {
36
+func defaultRepo() (repo.Repo, error) {
37
+ c := cfg.Config{}
38
+ priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, rand.Reader)
39
+ if err != nil {
40
+ return nil, err
41
+ }
42
+
43
+ data, err := pub.Hash()
44
+ if err != nil {
45
+ return nil, err
46
+ }
47
+
48
+ privkeyb, err := priv.Bytes()
49
+ if err != nil {
50
+ return nil, err
51
+ }
52
+
53
+ c.Bootstrap = cfg.DefaultBootstrapAddresses
54
+ c.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001"}
55
+ c.Identity.PeerID = key.Key(data).B58String()
56
+ c.Identity.PrivKey = base64.StdEncoding.EncodeToString(privkeyb)
57
+
58
return &repo.Mock{
59
D: dsync.MutexWrap(ds.NewMapDatastore()),
34
- }
60
+ C: c,
61
+ }, nil
62
}
63
64
func (nb *NodeBuilder) Online() *NodeBuilder {
@@ -65,7 +92,11 @@ func (nb *NodeBuilder) Build(ctx context.Context) (*IpfsNode, error) {
92
}
93
nb.built = true
94
if nb.repo == nil {
68
- nb.repo = defaultRepo()
95
+ r, err := defaultRepo()
96
+ if err != nil {
97
+ return nil, err
98
+ }
99
+ nb.repo = r
100
}
101
conf := standardWithRouting(nb.repo, nb.online, nb.routing, nb.peerhost)
102
return NewIPFSNode(ctx, conf)