Basic ClientListImports
This commit is contained in:
parent
cec4918cd9
commit
1f6629e978
10
api/api.go
10
api/api.go
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/ipfs/go-ipfs/filestore"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain"
|
"github.com/filecoin-project/go-lotus/chain"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
@ -17,6 +18,13 @@ type Version struct {
|
|||||||
// TODO: git commit / os / genesis cid?
|
// TODO: git commit / os / genesis cid?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Import struct {
|
||||||
|
Status filestore.Status
|
||||||
|
Key cid.Cid
|
||||||
|
FilePath string
|
||||||
|
Size uint64
|
||||||
|
}
|
||||||
|
|
||||||
// API is a low-level interface to the Filecoin network
|
// API is a low-level interface to the Filecoin network
|
||||||
type API interface {
|
type API interface {
|
||||||
// chain
|
// chain
|
||||||
@ -89,7 +97,7 @@ type API interface {
|
|||||||
//ClientUnimport(path string)
|
//ClientUnimport(path string)
|
||||||
|
|
||||||
// ClientListImports lists imported files and their root CIDs
|
// ClientListImports lists imported files and their root CIDs
|
||||||
//ClientListImports() []Import
|
ClientListImports(ctx context.Context) ([]Import, error)
|
||||||
|
|
||||||
//ClientListAsks() []Ask
|
//ClientListAsks() []Ask
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ type Struct struct {
|
|||||||
WalletNew func(context.Context, string) (address.Address, error)
|
WalletNew func(context.Context, string) (address.Address, error)
|
||||||
WalletList func(context.Context) ([]address.Address, error)
|
WalletList func(context.Context) ([]address.Address, error)
|
||||||
|
|
||||||
ClientImport func(ctx context.Context, path string) (cid.Cid, error)
|
ClientImport func(ctx context.Context, path string) (cid.Cid, error)
|
||||||
|
ClientListImports func(ctx context.Context) ([]Import, error)
|
||||||
|
|
||||||
NetPeers func(context.Context) ([]peer.AddrInfo, error)
|
NetPeers func(context.Context) ([]peer.AddrInfo, error)
|
||||||
NetConnect func(context.Context, peer.AddrInfo) error
|
NetConnect func(context.Context, peer.AddrInfo) error
|
||||||
@ -36,6 +37,10 @@ type Struct struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Struct) ClientListImports(ctx context.Context) ([]Import, error) {
|
||||||
|
return c.Internal.ClientListImports(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Struct) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
|
func (c *Struct) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
|
||||||
return c.Internal.ClientImport(ctx, path)
|
return c.Internal.ClientImport(ctx, path)
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,13 @@ var clientCmd = &cli.Command{
|
|||||||
Usage: "Make deals, store data, retrieve data",
|
Usage: "Make deals, store data, retrieve data",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
clientImportCmd,
|
clientImportCmd,
|
||||||
|
clientLocalCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientImportCmd = &cli.Command{
|
var clientImportCmd = &cli.Command{
|
||||||
Name: "import",
|
Name: "import",
|
||||||
Usage: "import data",
|
Usage: "Import data",
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, err := getAPI(cctx)
|
api, err := getAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -30,4 +31,25 @@ var clientImportCmd = &cli.Command{
|
|||||||
fmt.Println(c.String())
|
fmt.Println(c.String())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var clientLocalCmd = &cli.Command{
|
||||||
|
Name: "local",
|
||||||
|
Usage: "List locally imported data",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, err := getAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx := reqContext(cctx)
|
||||||
|
|
||||||
|
list, err := api.ClientListImports(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, v := range list {
|
||||||
|
fmt.Printf("%s %s %d %s\n", v.Key, v.FilePath, v.Size, v.Status)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package node
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/ipfs/go-ipfs/filestore"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"github.com/filecoin-project/go-lotus/build"
|
"github.com/filecoin-project/go-lotus/build"
|
||||||
@ -22,6 +23,7 @@ type API struct {
|
|||||||
Host host.Host
|
Host host.Host
|
||||||
Chain *chain.ChainStore
|
Chain *chain.ChainStore
|
||||||
PubSub *pubsub.PubSub
|
PubSub *pubsub.PubSub
|
||||||
|
Filestore *filestore.Filestore
|
||||||
Mpool *chain.MessagePool
|
Mpool *chain.MessagePool
|
||||||
Wallet *chain.Wallet
|
Wallet *chain.Wallet
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,14 @@ package node
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/ipfs/go-ipfs/filestore"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
exchange "github.com/ipfs/go-ipfs-exchange-interface"
|
exchange "github.com/ipfs/go-ipfs-exchange-interface"
|
||||||
|
ipld "github.com/ipfs/go-ipld-format"
|
||||||
ci "github.com/libp2p/go-libp2p-core/crypto"
|
ci "github.com/libp2p/go-libp2p-core/crypto"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
@ -18,7 +20,6 @@ import (
|
|||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
record "github.com/libp2p/go-libp2p-record"
|
record "github.com/libp2p/go-libp2p-record"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
ipld "github.com/ipfs/go-ipld-format"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"github.com/filecoin-project/go-lotus/chain"
|
"github.com/filecoin-project/go-lotus/chain"
|
||||||
@ -167,6 +168,7 @@ func Online() Option {
|
|||||||
Override(new(blockstore.GCLocker), blockstore.NewGCLocker),
|
Override(new(blockstore.GCLocker), blockstore.NewGCLocker),
|
||||||
Override(new(blockstore.GCBlockstore), blockstore.NewGCBlockstore),
|
Override(new(blockstore.GCBlockstore), blockstore.NewGCBlockstore),
|
||||||
Override(new(exchange.Interface), modules.Bitswap),
|
Override(new(exchange.Interface), modules.Bitswap),
|
||||||
|
Override(new(*filestore.Filestore), modules.ClientFstore),
|
||||||
Override(new(ipld.DAGService), modules.ClientDAG),
|
Override(new(ipld.DAGService), modules.ClientDAG),
|
||||||
|
|
||||||
// Filecoin services
|
// Filecoin services
|
||||||
|
@ -2,6 +2,8 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
|
"github.com/ipfs/go-ipfs/filestore"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -17,9 +19,10 @@ type LocalStorage struct {
|
|||||||
fx.In
|
fx.In
|
||||||
|
|
||||||
LocalDAG ipld.DAGService
|
LocalDAG ipld.DAGService
|
||||||
|
Filestore *filestore.Filestore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LocalStorage) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
|
func (s *LocalStorage) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
@ -55,3 +58,30 @@ func (s *LocalStorage) ClientImport(ctx context.Context, path string) (cid.Cid,
|
|||||||
|
|
||||||
return nd.Cid(), bufferedDS.Commit()
|
return nd.Cid(), bufferedDS.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (s *LocalStorage) ClientListImports(ctx context.Context) ([]api.Import, error) {
|
||||||
|
next, err := filestore.ListAll(s.Filestore, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: make this less very bad by tracking root cids instead of using ListAll
|
||||||
|
|
||||||
|
out := make([]api.Import, 0)
|
||||||
|
for {
|
||||||
|
r := next()
|
||||||
|
if r == nil {
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
if r.Offset != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out = append(out, api.Import{
|
||||||
|
Status: r.Status,
|
||||||
|
Key: r.Key,
|
||||||
|
FilePath: r.FilePath,
|
||||||
|
Size: r.Size,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -79,7 +79,7 @@ func Blockstore(r repo.LockedRepo) (blockstore.Blockstore, error) {
|
|||||||
return blockstore.NewIdStore(bs), nil
|
return blockstore.NewIdStore(bs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClientDAG(lc fx.Lifecycle, r repo.LockedRepo) (ipld.DAGService, error) {
|
func ClientFstore(r repo.LockedRepo) (*filestore.Filestore, error) {
|
||||||
clientds, err := r.Datastore("/client")
|
clientds, err := r.Datastore("/client")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -91,7 +91,10 @@ func ClientDAG(lc fx.Lifecycle, r repo.LockedRepo) (ipld.DAGService, error) {
|
|||||||
// TODO: fm.AllowUrls (needs more code in client import)
|
// TODO: fm.AllowUrls (needs more code in client import)
|
||||||
|
|
||||||
bs := blockstore.NewBlockstore(blocks)
|
bs := blockstore.NewBlockstore(blocks)
|
||||||
fstore := filestore.NewFilestore(bs, fm)
|
return filestore.NewFilestore(bs, fm), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClientDAG(lc fx.Lifecycle, fstore *filestore.Filestore) ipld.DAGService {
|
||||||
ibs := blockstore.NewIdStore(fstore)
|
ibs := blockstore.NewIdStore(fstore)
|
||||||
bsvc := blockservice.New(ibs, offline.Exchange(ibs))
|
bsvc := blockservice.New(ibs, offline.Exchange(ibs))
|
||||||
dag := merkledag.NewDAGService(bsvc)
|
dag := merkledag.NewDAGService(bsvc)
|
||||||
@ -102,5 +105,5 @@ func ClientDAG(lc fx.Lifecycle, r repo.LockedRepo) (ipld.DAGService, error) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return dag, nil
|
return dag
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user