Merge pull request #4650 from jsign/jsign/offlinemode

make IPFS online mode configurable
This commit is contained in:
Łukasz Magiera 2020-10-29 22:24:58 +01:00 committed by GitHub
commit c3d00b0ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View File

@ -25,12 +25,12 @@ type IpfsBstore struct {
api iface.CoreAPI api iface.CoreAPI
} }
func NewIpfsBstore(ctx context.Context) (*IpfsBstore, error) { func NewIpfsBstore(ctx context.Context, onlineMode bool) (*IpfsBstore, error) {
localApi, err := httpapi.NewLocalApi() localApi, err := httpapi.NewLocalApi()
if err != nil { if err != nil {
return nil, xerrors.Errorf("getting local ipfs api: %w", err) return nil, xerrors.Errorf("getting local ipfs api: %w", err)
} }
api, err := localApi.WithOptions(options.Api.Offline(true)) api, err := localApi.WithOptions(options.Api.Offline(!onlineMode))
if err != nil { if err != nil {
return nil, xerrors.Errorf("setting offline mode: %s", err) return nil, xerrors.Errorf("setting offline mode: %s", err)
} }
@ -41,12 +41,12 @@ func NewIpfsBstore(ctx context.Context) (*IpfsBstore, error) {
}, nil }, nil
} }
func NewRemoteIpfsBstore(ctx context.Context, maddr multiaddr.Multiaddr) (*IpfsBstore, error) { func NewRemoteIpfsBstore(ctx context.Context, maddr multiaddr.Multiaddr, onlineMode bool) (*IpfsBstore, error) {
httpApi, err := httpapi.NewApi(maddr) httpApi, err := httpapi.NewApi(maddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("setting remote ipfs api: %w", err) return nil, xerrors.Errorf("setting remote ipfs api: %w", err)
} }
api, err := httpApi.WithOptions(options.Api.Offline(true)) api, err := httpApi.WithOptions(options.Api.Offline(!onlineMode))
if err != nil { if err != nil {
return nil, xerrors.Errorf("applying offline mode: %s", err) return nil, xerrors.Errorf("applying offline mode: %s", err)
} }

View File

@ -454,7 +454,7 @@ func ConfigFullNode(c interface{}) Option {
return Options( return Options(
ConfigCommon(&cfg.Common), ConfigCommon(&cfg.Common),
If(cfg.Client.UseIpfs, If(cfg.Client.UseIpfs,
Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore(ipfsMaddr)), Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore(ipfsMaddr, cfg.Client.IpfsOnlineMode)),
If(cfg.Client.IpfsUseForRetrieval, If(cfg.Client.IpfsUseForRetrieval,
Override(new(dtypes.ClientRetrievalStoreManager), modules.ClientBlockstoreRetrievalStoreManager), Override(new(dtypes.ClientRetrievalStoreManager), modules.ClientBlockstoreRetrievalStoreManager),
), ),

View File

@ -105,6 +105,7 @@ type Metrics struct {
type Client struct { type Client struct {
UseIpfs bool UseIpfs bool
IpfsOnlineMode bool
IpfsMAddr string IpfsMAddr string
IpfsUseForRetrieval bool IpfsUseForRetrieval bool
} }

View File

@ -16,7 +16,7 @@ import (
// If ipfsMaddr is empty, a local IPFS node is assumed considering IPFS_PATH configuration. // 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. // 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. // The flag useForRetrieval indicates if the IPFS node will also be used for storing retrieving deals.
func IpfsClientBlockstore(ipfsMaddr string) func(helpers.MetricsCtx, fx.Lifecycle, dtypes.ClientImportMgr) (dtypes.ClientBlockstore, error) { func IpfsClientBlockstore(ipfsMaddr string, onlineMode bool) func(helpers.MetricsCtx, fx.Lifecycle, dtypes.ClientImportMgr) (dtypes.ClientBlockstore, error) {
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, localStore dtypes.ClientImportMgr) (dtypes.ClientBlockstore, error) { return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, localStore dtypes.ClientImportMgr) (dtypes.ClientBlockstore, error) {
var err error var err error
var ipfsbs blockstore.Blockstore var ipfsbs blockstore.Blockstore
@ -26,9 +26,9 @@ func IpfsClientBlockstore(ipfsMaddr string) func(helpers.MetricsCtx, fx.Lifecycl
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) ipfsbs, err = ipfsbstore.NewRemoteIpfsBstore(helpers.LifecycleCtx(mctx, lc), ma, onlineMode)
} else { } else {
ipfsbs, err = ipfsbstore.NewIpfsBstore(helpers.LifecycleCtx(mctx, lc)) ipfsbs, err = ipfsbstore.NewIpfsBstore(helpers.LifecycleCtx(mctx, lc), onlineMode)
} }
if err != nil { if err != nil {
return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err) return nil, xerrors.Errorf("constructing ipfs blockstore: %w", err)