56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package modules
|
|
|
|
import (
|
|
"context"
|
|
"github.com/filecoin-project/go-lotus/node/modules/helpers"
|
|
"github.com/ipfs/go-bitswap"
|
|
"github.com/ipfs/go-bitswap/network"
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
"github.com/libp2p/go-libp2p-core/routing"
|
|
"path/filepath"
|
|
|
|
"github.com/ipfs/go-blockservice"
|
|
"github.com/ipfs/go-datastore"
|
|
"github.com/ipfs/go-datastore/namespace"
|
|
"github.com/ipfs/go-filestore"
|
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
|
"github.com/ipfs/go-merkledag"
|
|
"go.uber.org/fx"
|
|
|
|
"github.com/filecoin-project/go-lotus/node/modules/dtypes"
|
|
"github.com/filecoin-project/go-lotus/node/repo"
|
|
)
|
|
|
|
func ClientFstore(r repo.LockedRepo) (dtypes.ClientFilestore, error) {
|
|
clientds, err := r.Datastore("/client")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
blocks := namespace.Wrap(clientds, datastore.NewKey("blocks"))
|
|
|
|
fm := filestore.NewFileManager(clientds, filepath.Dir(r.Path()))
|
|
fm.AllowFiles = true
|
|
// TODO: fm.AllowUrls (needs more code in client import)
|
|
|
|
bs := blockstore.NewBlockstore(blocks)
|
|
return filestore.NewFilestore(bs, fm), nil
|
|
}
|
|
|
|
func ClientDAG(mctx helpers.MetricsCtx, lc fx.Lifecycle, fstore dtypes.ClientFilestore, rt routing.Routing, h host.Host) dtypes.ClientDAG {
|
|
ibs := blockstore.NewIdStore((*filestore.Filestore)(fstore))
|
|
|
|
bitswapNetwork := network.NewFromIpfsHost(h, rt)
|
|
exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, ibs)
|
|
|
|
bsvc := blockservice.New(ibs, exch)
|
|
dag := merkledag.NewDAGService(bsvc)
|
|
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(_ context.Context) error {
|
|
return bsvc.Close()
|
|
},
|
|
})
|
|
|
|
return dag
|
|
}
|