Skip to content

Commit

Permalink
Add NewQueryV1, which has an optional PieceID param (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
ingar authored Jul 7, 2020
1 parent bc845dc commit 079c5cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions retrievalmarket/network/libp2p_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ func assertQueryReceived(inCtx context.Context, t *testing.T, fromNetwork networ
require.NoError(t, err)

// send query to host2
cid := shared_testutil.GenerateCids(1)[0]
q := retrievalmarket.NewQueryV0(cid)
cids := shared_testutil.GenerateCids(2)
q := retrievalmarket.NewQueryV1(cids[0], &cids[1])
require.NoError(t, qs1.WriteQuery(q))

var inq retrievalmarket.Query
Expand All @@ -393,6 +393,7 @@ func assertQueryReceived(inCtx context.Context, t *testing.T, fromNetwork networ
}
require.NotNil(t, inq)
assert.Equal(t, q.PayloadCID, inq.PayloadCID)
assert.Equal(t, q.PieceCID, inq.PieceCID)
}

// assertQueryResponseReceived performs the verification that a DealStatusResponse is received
Expand Down
12 changes: 11 additions & 1 deletion retrievalmarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,21 @@ type Query struct {
// QueryUndefined is a query with no values
var QueryUndefined = Query{}

// NewQueryV0 creates a V0 query (which only specifies a piece)
// NewQueryV0 creates a V0 query (which only specifies a payload)
func NewQueryV0(payloadCID cid.Cid) Query {
return Query{PayloadCID: payloadCID}
}

// NewQueryV1 creates a V1 query (which has an optional pieceCID)
func NewQueryV1(payloadCID cid.Cid, pieceCID *cid.Cid) Query {
return Query{
PayloadCID: payloadCID,
QueryParams: QueryParams{
PieceCID: pieceCID,
},
}
}

// QueryResponse is a miners response to a given retrieval query
type QueryResponse struct {
Status QueryResponseStatus
Expand Down

0 comments on commit 079c5cf

Please sign in to comment.