2020-04-29 23:51:55 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-05-22 14:51:18 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2020-04-29 23:51:55 +00:00
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2020-04-29 23:51:55 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
|
|
|
)
|
|
|
|
|
2020-05-26 12:50:35 +00:00
|
|
|
// 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.
|
2020-10-29 18:16:45 +00:00
|
|
|
func IpfsClientBlockstore(ipfsMaddr string, onlineMode bool) func(helpers.MetricsCtx, fx.Lifecycle, dtypes.ClientImportMgr) (dtypes.ClientBlockstore, error) {
|
2020-07-07 08:52:19 +00:00
|
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, localStore dtypes.ClientImportMgr) (dtypes.ClientBlockstore, error) {
|
2020-05-27 12:50:32 +00:00
|
|
|
var err error
|
2020-07-23 02:05:11 +00:00
|
|
|
var ipfsbs blockstore.Blockstore
|
2020-05-26 12:50:35 +00:00
|
|
|
if ipfsMaddr != "" {
|
2020-05-27 12:50:32 +00:00
|
|
|
var ma multiaddr.Multiaddr
|
|
|
|
ma, err = multiaddr.NewMultiaddr(ipfsMaddr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("parsing ipfs multiaddr: %w", err)
|
|
|
|
}
|
2021-01-29 20:01:00 +00:00
|
|
|
ipfsbs, err = blockstore.NewRemoteIpfsBstore(helpers.LifecycleCtx(mctx, lc), ma, onlineMode)
|
2020-05-26 12:50:35 +00:00
|
|
|
} else {
|
2021-01-29 20:01:00 +00:00
|
|
|
ipfsbs, err = blockstore.NewIpfsBstore(helpers.LifecycleCtx(mctx, lc), onlineMode)
|
2020-05-26 12:50:35 +00:00
|
|
|
}
|
2020-05-22 14:51:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err)
|
|
|
|
}
|
2020-07-31 20:24:50 +00:00
|
|
|
return blockstore.WrapIDStore(ipfsbs), nil
|
2020-05-22 14:51:18 +00:00
|
|
|
}
|
|
|
|
}
|