From 1f97ad2c2edb7fa6262ef0c0647a45bdccf61972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 10 Jul 2019 19:36:17 +0200 Subject: [PATCH] Use repo libp2p identiny --- node/builder.go | 8 ++++++++ node/repo/fsrepo.go | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/node/builder.go b/node/builder.go index 4a81df2d8..0ba8e246c 100644 --- a/node/builder.go +++ b/node/builder.go @@ -205,6 +205,10 @@ func Repo(r repo.Repo) Option { if err != nil { return Error(err) } + pk, err := lr.Libp2pIdentity() + if err != nil { + return Error(err) + } return Options( Config(cfg), @@ -212,6 +216,10 @@ func Repo(r repo.Repo) Option { Override(new(datastore.Batching), modules.Datastore), Override(new(blockstore.Blockstore), modules.Blockstore), + + Override(new(ci.PrivKey), pk), + Override(new(ci.PubKey), ci.PrivKey.GetPublic), + Override(new(peer.ID), peer.IDFromPublicKey), ) } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index 0aa66fcbf..27d9d24a4 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -45,7 +45,7 @@ var _ Repo = &FsRepo{} func NewFS(path string) (*FsRepo, error) { path, err := homedir.Expand(path) if err != nil { - return &FsRepo{}, err + return nil, err } return &FsRepo{ @@ -175,6 +175,13 @@ func (fsr *fsLockedRepo) Libp2pIdentity() (crypto.PrivKey, error) { if err != nil { return nil, xerrors.Errorf("could not write private key: %w", err) } + } else if err != nil { + return nil, err + } + + stat, err = os.Stat(kpath) + if err != nil { + return nil, err } if stat.Mode()&0066 != 0 {