Skip to content

Commit

Permalink
Merge pull request #1317 from ipfs/builder-default
Browse files Browse the repository at this point in the history
make the default repo for corebuilder work
  • Loading branch information
jbenet committed Jun 3, 2015
2 parents 6cff7e8 + 6b16981 commit 13cd226
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions core/builder.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package core

import (
"crypto/rand"
"encoding/base64"
"errors"

ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
dsync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
key "github.com/ipfs/go-ipfs/blocks/key"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
repo "github.com/ipfs/go-ipfs/repo"
cfg "github.com/ipfs/go-ipfs/repo/config"
)

var ErrAlreadyBuilt = errors.New("this builder has already been used")
Expand All @@ -28,10 +33,32 @@ func NewNodeBuilder() *NodeBuilder {
}
}

func defaultRepo() repo.Repo {
func defaultRepo() (repo.Repo, error) {
c := cfg.Config{}
priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, rand.Reader)
if err != nil {
return nil, err
}

data, err := pub.Hash()
if err != nil {
return nil, err
}

privkeyb, err := priv.Bytes()
if err != nil {
return nil, err
}

c.Bootstrap = cfg.DefaultBootstrapAddresses
c.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001"}
c.Identity.PeerID = key.Key(data).B58String()
c.Identity.PrivKey = base64.StdEncoding.EncodeToString(privkeyb)

return &repo.Mock{
D: dsync.MutexWrap(ds.NewMapDatastore()),
}
C: c,
}, nil
}

func (nb *NodeBuilder) Online() *NodeBuilder {
Expand Down Expand Up @@ -65,7 +92,11 @@ func (nb *NodeBuilder) Build(ctx context.Context) (*IpfsNode, error) {
}
nb.built = true
if nb.repo == nil {
nb.repo = defaultRepo()
r, err := defaultRepo()
if err != nil {
return nil, err
}
nb.repo = r
}
conf := standardWithRouting(nb.repo, nb.online, nb.routing, nb.peerhost)
return NewIPFSNode(ctx, conf)
Expand Down

0 comments on commit 13cd226

Please sign in to comment.