allow using ipfs for retrieval

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
Ignacio Hagopian 2020-05-26 09:50:35 -03:00 committed by Łukasz Magiera
parent de3edc2ec7
commit 0af7cd1448
3 changed files with 23 additions and 29 deletions

View File

@ -378,18 +378,13 @@ func ConfigFullNode(c interface{}) Option {
return Error(xerrors.Errorf("invalid config from repo, got: %T", c)) return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
} }
remoteIpfsMaddrNotEmpty := func(s *Settings) bool { ipfsMaddr := cfg.Client.IpfsMAddr
return len(cfg.Client.RemoteIpfsMAddr) > 0 useForRetrieval := cfg.Client.IpfsUseForRetrieval
}
return Options( return Options(
ConfigCommon(&cfg.Common), ConfigCommon(&cfg.Common),
If(cfg.Client.UseIpfs, If(cfg.Client.UseIpfs,
Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore), Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore(ipfsMaddr, useForRetrieval)),
), ),
ApplyIf(remoteIpfsMaddrNotEmpty,
Override(new(dtypes.ClientBlockstore), modules.IpfsRemoteClientBlockstore(cfg.Client.RemoteIpfsMAddr))),
If(cfg.Metrics.HeadNotifs, If(cfg.Metrics.HeadNotifs,
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)), Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
), ),

View File

@ -62,8 +62,9 @@ type Metrics struct {
} }
type Client struct { type Client struct {
UseIpfs bool UseIpfs bool
RemoteIpfsMAddr string IpfsMAddr string
IpfsUseForRetrieval bool
} }
func defCommon() Common { func defCommon() Common {

View File

@ -14,32 +14,30 @@ import (
"github.com/filecoin-project/lotus/node/modules/helpers" "github.com/filecoin-project/lotus/node/modules/helpers"
) )
func IpfsClientBlockstore(mctx helpers.MetricsCtx, lc fx.Lifecycle, fstore dtypes.ClientFilestore) (dtypes.ClientBlockstore, error) { // IpfsClientBlockstore returns a ClientBlockstore implementation backed by an IPFS node.
ipfsbs, err := ipfsbstore.NewIpfsBstore(helpers.LifecycleCtx(mctx, lc)) // If ipfsMaddr is empty, a local IPFS node is assumed considering IPFS_PATH configuration.
if err != nil { // If ipfsMaddr is not empty, it will connect to the remote IPFS node with the provided multiaddress.
return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err) // The flag useForRetrieval indicates if the IPFS node will also be used for storing retrieving deals.
} func IpfsClientBlockstore(ipfsMaddr string, useForRetrieval bool) func(helpers.MetricsCtx, fx.Lifecycle, dtypes.ClientFilestore) (dtypes.ClientBlockstore, error) {
return bufbstore.NewTieredBstore(
ipfsbs,
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) { return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fstore dtypes.ClientFilestore) (dtypes.ClientBlockstore, error) {
ma, err := multiaddr.NewMultiaddr(ipfsMaddr) ma, err := multiaddr.NewMultiaddr(ipfsMaddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("parsing ipfs multiaddr: %w", err) return nil, xerrors.Errorf("parsing ipfs multiaddr: %w", err)
} }
ipfsbs, err := ipfsbstore.NewRemoteIpfsBstore(helpers.LifecycleCtx(mctx, lc), ma) var ipfsbs *ipfsbstore.IpfsBstore
if ipfsMaddr != "" {
ipfsbs, err = ipfsbstore.NewRemoteIpfsBstore(helpers.LifecycleCtx(mctx, lc), ma)
} else {
ipfsbs, err = ipfsbstore.NewIpfsBstore(helpers.LifecycleCtx(mctx, lc))
}
if err != nil { if err != nil {
return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err) return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err)
} }
var ws blockstore.Blockstore
return bufbstore.NewTieredBstore( ws = ipfsbs
ipfsbs, if !useForRetrieval {
blockstore.NewIdStore((*filestore.Filestore)(fstore)), ws = blockstore.NewIdStore((*filestore.Filestore)(fstore))
), nil }
return bufbstore.NewTieredBstore(ipfsbs, ws), nil
} }
} }