node.go 736 B

1234567891011121314151617181920212223242526272829
  1. package embeddedShell
  2. import (
  3. "github.com/ipfs/go-ipfs/core"
  4. "github.com/ipfs/go-ipfs/repo/fsrepo"
  5. "golang.org/x/net/context"
  6. "gopkg.in/errgo.v1"
  7. )
  8. func NewDefaultNodeWithFSRepo(ctx context.Context, repoPath string) (*core.IpfsNode, error) {
  9. r, err := fsrepo.Open(repoPath)
  10. if err != nil {
  11. return nil, errgo.Notef(err, "opening fsrepo failed")
  12. }
  13. node, err := core.NewNode(ctx, &core.BuildCfg{
  14. Online: true,
  15. Repo: r,
  16. })
  17. if err != nil {
  18. return nil, errgo.Notef(err, "ipfs NewNode() failed.")
  19. }
  20. // TODO: can we bootsrap localy/mdns first and fall back to default?
  21. err = node.Bootstrap(core.DefaultBootstrapConfig)
  22. if err != nil {
  23. return nil, errgo.Notef(err, "ipfs Bootstrap() failed.")
  24. }
  25. return node, nil
  26. }