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
parent d5346f8326
commit 61daaa774b
No known key found for this signature in database
GPG Key ID: 4DC349E20B2AD1BE
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))
}
remoteIpfsMaddrNotEmpty := func(s *Settings) bool {
return len(cfg.Client.RemoteIpfsMAddr) > 0
}
ipfsMaddr := cfg.Client.IpfsMAddr
useForRetrieval := cfg.Client.IpfsUseForRetrieval
return Options(
ConfigCommon(&cfg.Common),
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,
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
),

View File

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

View File

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