Merge remote-tracking branch 'origin/master' into next
This commit is contained in:
commit
02234d00b7
@ -118,6 +118,7 @@ type FullNode interface {
|
|||||||
ClientListDeals(ctx context.Context) ([]DealInfo, error)
|
ClientListDeals(ctx context.Context) ([]DealInfo, error)
|
||||||
ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error)
|
ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error)
|
||||||
ClientFindData(ctx context.Context, root cid.Cid) ([]QueryOffer, error)
|
ClientFindData(ctx context.Context, root cid.Cid) ([]QueryOffer, error)
|
||||||
|
ClientMinerQueryOffer(ctx context.Context, root cid.Cid, miner address.Address) (QueryOffer, error)
|
||||||
ClientRetrieve(ctx context.Context, order RetrievalOrder, ref *FileRef) error
|
ClientRetrieve(ctx context.Context, order RetrievalOrder, ref *FileRef) error
|
||||||
ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error)
|
ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error)
|
||||||
ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*CommPRet, error)
|
ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*CommPRet, error)
|
||||||
|
@ -109,17 +109,18 @@ type FullNodeStruct struct {
|
|||||||
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
||||||
WalletDelete func(context.Context, address.Address) error `perm:"write"`
|
WalletDelete func(context.Context, address.Address) error `perm:"write"`
|
||||||
|
|
||||||
ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"`
|
ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"`
|
||||||
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
||||||
ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"`
|
ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"`
|
||||||
ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"`
|
ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"`
|
||||||
ClientStartDeal func(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) `perm:"admin"`
|
ClientMinerQueryOffer func(ctx context.Context, root cid.Cid, miner address.Address) (api.QueryOffer, error) `perm:"read"`
|
||||||
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
|
ClientStartDeal func(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) `perm:"admin"`
|
||||||
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
|
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
|
||||||
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error `perm:"admin"`
|
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
|
||||||
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
|
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error `perm:"admin"`
|
||||||
ClientCalcCommP func(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) `perm:"read"`
|
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
|
||||||
ClientGenCar func(ctx context.Context, ref api.FileRef, outpath string) error `perm:"write"`
|
ClientCalcCommP func(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) `perm:"read"`
|
||||||
|
ClientGenCar func(ctx context.Context, ref api.FileRef, outpath string) error `perm:"write"`
|
||||||
|
|
||||||
StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"`
|
StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"`
|
||||||
StateMinerSectors func(context.Context, address.Address, *abi.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
|
StateMinerSectors func(context.Context, address.Address, *abi.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
|
||||||
@ -337,6 +338,10 @@ func (c *FullNodeStruct) ClientFindData(ctx context.Context, root cid.Cid) ([]ap
|
|||||||
return c.Internal.ClientFindData(ctx, root)
|
return c.Internal.ClientFindData(ctx, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) ClientMinerQueryOffer(ctx context.Context, root cid.Cid, miner address.Address) (api.QueryOffer, error) {
|
||||||
|
return c.Internal.ClientMinerQueryOffer(ctx, root, miner)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) {
|
func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) {
|
||||||
return c.Internal.ClientStartDeal(ctx, params)
|
return c.Internal.ClientStartDeal(ctx, params)
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
lapi "github.com/filecoin-project/lotus/api"
|
lapi "github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
@ -391,6 +392,10 @@ var clientRetrieveCmd = &cli.Command{
|
|||||||
Name: "car",
|
Name: "car",
|
||||||
Usage: "export to a car file instead of a regular file",
|
Usage: "export to a car file instead of a regular file",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "miner",
|
||||||
|
Usage: "miner address for retrieval, if not present it'll use local discovery",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
if cctx.NArg() != 2 {
|
if cctx.NArg() != 2 {
|
||||||
@ -398,7 +403,7 @@ var clientRetrieveCmd = &cli.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
fapi, closer, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -409,7 +414,7 @@ var clientRetrieveCmd = &cli.Command{
|
|||||||
if cctx.String("address") != "" {
|
if cctx.String("address") != "" {
|
||||||
payer, err = address.NewFromString(cctx.String("address"))
|
payer, err = address.NewFromString(cctx.String("address"))
|
||||||
} else {
|
} else {
|
||||||
payer, err = api.WalletDefaultAddress(ctx)
|
payer, err = fapi.WalletDefaultAddress(ctx)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -432,23 +437,39 @@ var clientRetrieveCmd = &cli.Command{
|
|||||||
return nil
|
return nil
|
||||||
}*/ // TODO: fix
|
}*/ // TODO: fix
|
||||||
|
|
||||||
offers, err := api.ClientFindData(ctx, file)
|
var offer api.QueryOffer
|
||||||
if err != nil {
|
minerStrAddr := cctx.String("miner")
|
||||||
return err
|
if minerStrAddr == "" { // Local discovery
|
||||||
|
offers, err := fapi.ClientFindData(ctx, file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: parse offer strings from `client find`, make this smarter
|
||||||
|
if len(offers) < 1 {
|
||||||
|
fmt.Println("Failed to find file")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
offer = offers[0]
|
||||||
|
} else { // Directed retrieval
|
||||||
|
minerAddr, err := address.NewFromString(minerStrAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
offer, err = fapi.ClientMinerQueryOffer(ctx, file, minerAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if offer.Err != "" {
|
||||||
// TODO: parse offer strings from `client find`, make this smarter
|
return fmt.Errorf("The received offer errored: %s", offer.Err)
|
||||||
|
|
||||||
if len(offers) < 1 {
|
|
||||||
fmt.Println("Failed to find file")
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ref := &lapi.FileRef{
|
ref := &lapi.FileRef{
|
||||||
Path: cctx.Args().Get(1),
|
Path: cctx.Args().Get(1),
|
||||||
IsCAR: cctx.Bool("car"),
|
IsCAR: cctx.Bool("car"),
|
||||||
}
|
}
|
||||||
if err := api.ClientRetrieve(ctx, offers[0].Order(payer), ref); err != nil {
|
if err := fapi.ClientRetrieve(ctx, offer.Order(payer), ref); err != nil {
|
||||||
return xerrors.Errorf("Retrieval Failed: %w", err)
|
return xerrors.Errorf("Retrieval Failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-fil-markets/pieceio"
|
"github.com/filecoin-project/go-fil-markets/pieceio"
|
||||||
basicnode "github.com/ipld/go-ipld-prime/node/basic"
|
basicnode "github.com/ipld/go-ipld-prime/node/basic"
|
||||||
@ -201,25 +202,51 @@ func (a *API) ClientFindData(ctx context.Context, root cid.Cid) ([]api.QueryOffe
|
|||||||
|
|
||||||
out := make([]api.QueryOffer, len(peers))
|
out := make([]api.QueryOffer, len(peers))
|
||||||
for k, p := range peers {
|
for k, p := range peers {
|
||||||
queryResponse, err := a.Retrieval.Query(ctx, p, root, retrievalmarket.QueryParams{})
|
out[k] = a.makeRetrievalQuery(ctx, p, root, retrievalmarket.QueryParams{})
|
||||||
if err != nil {
|
|
||||||
out[k] = api.QueryOffer{Err: err.Error(), Miner: p.Address, MinerPeerID: p.ID}
|
|
||||||
} else {
|
|
||||||
out[k] = api.QueryOffer{
|
|
||||||
Root: root,
|
|
||||||
Size: queryResponse.Size,
|
|
||||||
MinPrice: queryResponse.PieceRetrievalPrice(),
|
|
||||||
PaymentInterval: queryResponse.MaxPaymentInterval,
|
|
||||||
PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease,
|
|
||||||
Miner: queryResponse.PaymentAddress, // TODO: check
|
|
||||||
MinerPeerID: p.ID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) ClientMinerQueryOffer(ctx context.Context, payload cid.Cid, miner address.Address) (api.QueryOffer, error) {
|
||||||
|
mi, err := a.StateMinerInfo(ctx, miner, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return api.QueryOffer{}, err
|
||||||
|
}
|
||||||
|
rp := retrievalmarket.RetrievalPeer{
|
||||||
|
Address: miner,
|
||||||
|
ID: mi.PeerId,
|
||||||
|
}
|
||||||
|
return a.makeRetrievalQuery(ctx, rp, payload, retrievalmarket.QueryParams{}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) makeRetrievalQuery(ctx context.Context, rp retrievalmarket.RetrievalPeer, payload cid.Cid, qp retrievalmarket.QueryParams) api.QueryOffer {
|
||||||
|
queryResponse, err := a.Retrieval.Query(ctx, rp, payload, qp)
|
||||||
|
if err != nil {
|
||||||
|
return api.QueryOffer{Err: err.Error(), Miner: rp.Address, MinerPeerID: rp.ID}
|
||||||
|
}
|
||||||
|
var errStr string
|
||||||
|
switch queryResponse.Status {
|
||||||
|
case retrievalmarket.QueryResponseAvailable:
|
||||||
|
errStr = ""
|
||||||
|
case retrievalmarket.QueryResponseUnavailable:
|
||||||
|
errStr = fmt.Sprintf("retrieval query offer was unavailable: %s", queryResponse.Message)
|
||||||
|
case retrievalmarket.QueryResponseError:
|
||||||
|
errStr = fmt.Sprintf("retrieval query offer errored: %s", queryResponse.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.QueryOffer{
|
||||||
|
Root: payload,
|
||||||
|
Size: queryResponse.Size,
|
||||||
|
MinPrice: queryResponse.PieceRetrievalPrice(),
|
||||||
|
PaymentInterval: queryResponse.MaxPaymentInterval,
|
||||||
|
PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease,
|
||||||
|
Miner: queryResponse.PaymentAddress, // TODO: check
|
||||||
|
MinerPeerID: rp.ID,
|
||||||
|
Err: errStr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) ClientImport(ctx context.Context, ref api.FileRef) (cid.Cid, error) {
|
func (a *API) ClientImport(ctx context.Context, ref api.FileRef) (cid.Cid, error) {
|
||||||
|
|
||||||
bufferedDS := ipld.NewBufferedDAG(ctx, a.LocalDAG)
|
bufferedDS := ipld.NewBufferedDAG(ctx, a.LocalDAG)
|
||||||
|
Loading…
Reference in New Issue
Block a user