remote ipfs support & automatic env

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
Ignacio Hagopian
2020-05-26 14:52:51 -03:00
parent 9089aadbbf
commit d5346f8326
8 changed files with 53 additions and 3 deletions
+6
View File
@@ -378,11 +378,17 @@ func ConfigFullNode(c interface{}) Option {
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
}
remoteIpfsMaddrNotEmpty := func(s *Settings) bool {
return len(cfg.Client.RemoteIpfsMAddr) > 0
}
return Options(
ConfigCommon(&cfg.Common),
If(cfg.Client.UseIpfs,
Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore),
),
ApplyIf(remoteIpfsMaddrNotEmpty,
Override(new(dtypes.ClientBlockstore), modules.IpfsRemoteClientBlockstore(cfg.Client.RemoteIpfsMAddr))),
If(cfg.Metrics.HeadNotifs,
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
+2 -1
View File
@@ -62,7 +62,8 @@ type Metrics struct {
}
type Client struct {
UseIpfs bool
UseIpfs bool
RemoteIpfsMAddr string
}
func defCommon() Common {
+7
View File
@@ -2,10 +2,12 @@ package config
import (
"bytes"
"fmt"
"io"
"os"
"github.com/BurntSushi/toml"
"github.com/kelseyhightower/envconfig"
"golang.org/x/xerrors"
)
@@ -32,6 +34,11 @@ func FromReader(reader io.Reader, def interface{}) (interface{}, error) {
return nil, err
}
err = envconfig.Process("LOTUS", cfg)
if err != nil {
return nil, fmt.Errorf("processing env vars overrides: %s", err)
}
return cfg, nil
}
+19
View File
@@ -6,6 +6,7 @@ import (
"github.com/ipfs/go-filestore"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"github.com/multiformats/go-multiaddr"
"github.com/filecoin-project/lotus/lib/bufbstore"
"github.com/filecoin-project/lotus/lib/ipfsbstore"
@@ -24,3 +25,21 @@ func IpfsClientBlockstore(mctx helpers.MetricsCtx, lc fx.Lifecycle, fstore dtype
blockstore.NewIdStore((*filestore.Filestore)(fstore)),
), nil
}
func IpfsRemoteClientBlockstore(ipfsMaddr string) func(helpers.MetricsCtx, fx.Lifecycle, dtypes.ClientFilestore) (dtypes.ClientBlockstore, error) {
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fstore dtypes.ClientFilestore) (dtypes.ClientBlockstore, error) {
ma, err := multiaddr.NewMultiaddr(ipfsMaddr)
if err != nil {
return nil, xerrors.Errorf("parsing ipfs multiaddr: %w", err)
}
ipfsbs, err := ipfsbstore.NewRemoteIpfsBstore(helpers.LifecycleCtx(mctx, lc), ma)
if err != nil {
return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err)
}
return bufbstore.NewTieredBstore(
ipfsbs,
blockstore.NewIdStore((*filestore.Filestore)(fstore)),
), nil
}
}
+3 -2
View File
@@ -3,7 +3,6 @@ package repo
import (
"encoding/json"
"fmt"
"github.com/filecoin-project/sector-storage/stores"
"io"
"io/ioutil"
"os"
@@ -11,6 +10,8 @@ import (
"strings"
"sync"
"github.com/filecoin-project/sector-storage/stores"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
badger "github.com/ipfs/go-ds-badger2"
@@ -276,7 +277,7 @@ func (fsr *fsLockedRepo) Datastore(ns string) (datastore.Batching, error) {
return namespace.Wrap(fsr.ds, datastore.NewKey(ns)), nil
}
func (fsr *fsLockedRepo) Config() (interface{}, error) {
func (fsr *fsLockedRepo) Config() (df interface{}, err error) {
if err := fsr.stillValid(); err != nil {
return nil, err
}