Use repo libp2p identiny

This commit is contained in:
Łukasz Magiera 2019-07-10 19:36:17 +02:00
parent e639670195
commit 1f97ad2c2e
2 changed files with 16 additions and 1 deletions

View File

@ -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),
)
}

View File

@ -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 {