-
Notifications
You must be signed in to change notification settings - Fork 75
Retrieval query ask v2 #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5a6179c
94a937f
3945668
ccb317c
3311419
62e8a24
a3c0fe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/filecoin-project/boost/retrievalmarket/lp2pimpl" | ||
"github.com/filecoin-project/boost/retrievalmarket/types" | ||
"github.com/libp2p/go-libp2p" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"github.com/libp2p/go-libp2p-core/peerstore" | ||
"github.com/libp2p/go-libp2p-peerstore/pstoremem" | ||
) | ||
|
||
// RetrievalClient runs retrieval queries with Boost over libp2p | ||
type RetrievalClient struct { | ||
PeerStore peerstore.Peerstore | ||
queryClient *lp2pimpl.QueryClient | ||
} | ||
|
||
// NewRetrievalClient sets up a libp2p host to run retrieval query ask v2 queries | ||
func NewRetrievalClient() (*RetrievalClient, error) { | ||
pstore, err := pstoremem.NewPeerstore() | ||
if err != nil { | ||
return nil, fmt.Errorf("creating peer store: %w", err) | ||
} | ||
opts := []libp2p.Option{ | ||
libp2p.DefaultTransports, | ||
libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"), | ||
libp2p.Peerstore(pstore), | ||
libp2p.NoListenAddrs, | ||
} | ||
|
||
h, err := libp2p.New(opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
retryOpts := lp2pimpl.RetryParameters(time.Millisecond, time.Millisecond, 1, 1) | ||
return &RetrievalClient{ | ||
queryClient: lp2pimpl.NewQueryClient(h, retryOpts), | ||
PeerStore: pstore, | ||
}, nil | ||
} | ||
|
||
// Query sends a retrieval query v2 to another peer | ||
func (c *RetrievalClient) Query(ctx context.Context, providerID peer.ID, query types.Query) (*types.QueryResponse, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the RetrievalClient only has one method, I wonder if we can consolidate everything into the QueryClient? |
||
// Send the deal proposal to the provider | ||
return c.queryClient.SendQuery(ctx, providerID, query) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ func main() { | |
offlineDealCmd, | ||
providerCmd, | ||
walletCmd, | ||
retrievePieceCmd, | ||
}, | ||
} | ||
app.Setup() | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||||||||||
package main | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"fmt" | ||||||||||||||
|
||||||||||||||
bcli "github.com/filecoin-project/boost/cli" | ||||||||||||||
clinode "github.com/filecoin-project/boost/cli/node" | ||||||||||||||
"github.com/filecoin-project/boost/cmd" | ||||||||||||||
"github.com/filecoin-project/boost/retrievalmarket/lp2pimpl" | ||||||||||||||
"github.com/filecoin-project/boost/retrievalmarket/types" | ||||||||||||||
"github.com/filecoin-project/go-address" | ||||||||||||||
lcli "github.com/filecoin-project/lotus/cli" | ||||||||||||||
"github.com/ipfs/go-cid" | ||||||||||||||
"github.com/urfave/cli/v2" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
var retrievePieceCmd = &cli.Command{ | ||||||||||||||
Name: "retrieve-piece", | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest adding a I also don't think we really need to provide the piece cid. The path to get things can be "well-known", eg |
||||||||||||||
Usage: "", | ||||||||||||||
Flags: []cli.Flag{ | ||||||||||||||
&cli.StringFlag{ | ||||||||||||||
Name: "provider", | ||||||||||||||
Usage: "storage provider on-chain address", | ||||||||||||||
Required: true, | ||||||||||||||
}, | ||||||||||||||
&cli.StringFlag{ | ||||||||||||||
Name: "piece-cid", | ||||||||||||||
Usage: "", | ||||||||||||||
Required: true, | ||||||||||||||
}, | ||||||||||||||
}, | ||||||||||||||
Before: before, | ||||||||||||||
Action: func(cctx *cli.Context) error { | ||||||||||||||
ctx := bcli.ReqContext(cctx) | ||||||||||||||
|
||||||||||||||
pieceCID, err := cid.Parse(cctx.String("piece-cid")) | ||||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
n, err := clinode.Setup(cctx.String(cmd.FlagRepo.Name)) | ||||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
api, closer, err := lcli.GetGatewayAPI(cctx) | ||||||||||||||
if err != nil { | ||||||||||||||
return fmt.Errorf("cant setup gateway connection: %w", err) | ||||||||||||||
} | ||||||||||||||
defer closer() | ||||||||||||||
|
||||||||||||||
maddr, err := address.NewFromString(cctx.String("provider")) | ||||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
addrInfo, err := cmd.GetAddrInfo(ctx, api, maddr) | ||||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
log.Debugw("found storage provider", "id", addrInfo.ID, "multiaddrs", addrInfo.Addrs, "addr", maddr) | ||||||||||||||
|
||||||||||||||
if err := n.Host.Connect(ctx, *addrInfo); err != nil { | ||||||||||||||
return fmt.Errorf("failed to connect to peer %s: %w", addrInfo.ID, err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
dc := lp2pimpl.NewQueryClient(n.Host) | ||||||||||||||
resp, err := dc.SendQuery(ctx, addrInfo.ID, types.Query{ | ||||||||||||||
PieceCID: &pieceCID, | ||||||||||||||
}) | ||||||||||||||
if err != nil { | ||||||||||||||
return fmt.Errorf("send deal status request failed: %w", err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if resp.Error != "" { | ||||||||||||||
return fmt.Errorf("query response error: %s", resp.Error) | ||||||||||||||
} | ||||||||||||||
fmt.Println(resp.Protocols.HTTPFilecoinV1.URL) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest outputting all protocols and let the user parse for the one they want to use. |
||||||||||||||
return nil | ||||||||||||||
}, | ||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the
ListenAddrStrings
option if we're also supplyingNoListenAddr
?