allow using ipfs for retrieval
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
+17
-19
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user