-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
825168f
commit 939ce0a
Showing
8 changed files
with
280 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package retrievalimpl_test | ||
|
||
import ( | ||
"context" | ||
retrievalimpl "github.com/filecoin-project/go-fil-components/retrievalmarket/impl" | ||
tut "github.com/filecoin-project/go-fil-components/retrievalmarket/network/testutil" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"testing" | ||
|
||
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestClient_Query(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
|
||
mnet := mocknet.New(ctx) | ||
h1, err := mnet.GenPeer() | ||
require.NoError(t, err) | ||
h2, err := mnet.GenPeer() | ||
require.NoError(t, err) | ||
|
||
bs := | ||
|
||
t.Run("it works", func(t *testing.T) { | ||
net := tut.NewTestRetrievalMarketNetwork(h1, []peer.ID{h2.ID()}) | ||
|
||
c := retrievalimpl.NewClient(h1, bs, n) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
package network | ||
|
||
import ( | ||
"context" | ||
"github.com/filecoin-project/go-fil-components/retrievalmarket" | ||
logging "github.com/ipfs/go-log" | ||
host "github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
) | ||
|
||
var log = logging.Logger("retrieval_network") | ||
|
||
func NewFromLibp2pHost(host.Host) RetrievalMarketNetwork { | ||
return nil | ||
func NewFromLibp2pHost(h host.Host) RetrievalMarketNetwork { | ||
return libp2pRetrievalMarketNetwork{host: h} | ||
} | ||
// libp2pDataTransferNetwork transforms the libp2p host interface, which sends and receives | ||
// libp2pRetrievalMarketNetwork transforms the libp2p host interface, which sends and receives | ||
// NetMessage objects, into the graphsync network interface. | ||
type libp2pDataTransferNetwork struct { | ||
type libp2pRetrievalMarketNetwork struct { | ||
host host.Host | ||
// inbound messages from the network are forwarded to the receiver | ||
receiver | ||
receiver RetrievalReceiver | ||
} | ||
|
||
func (impl libp2pRetrievalMarketNetwork) NewQueryStream(id peer.ID) (RetrievalQueryStream, error) { | ||
s, err := impl.host.NewStream(context.Background(), id, retrievalmarket.QueryProtocolID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return | ||
} | ||
|
||
func (impl libp2pRetrievalMarketNetwork) NewDealStream(id peer.ID) (RetrievalDealStream, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (impl libp2pRetrievalMarketNetwork) SetDelegate(r RetrievalReceiver) error { | ||
impl.receiver = r | ||
impl.host.SetStreamHandler(retrievalmarket.ProtocolID, impl.handleNewStream) | ||
} | ||
|
||
|
||
func debugLog(msg string) { | ||
log.Debugf("retrievalmarket net handleNewStream -- %s", ms) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package network | ||
|
||
import ( | ||
"github.com/filecoin-project/go-fil-components/retrievalmarket" | ||
retrievalimpl "github.com/filecoin-project/go-fil-components/retrievalmarket/impl" | ||
"github.com/filecoin-project/go-fil-components/shared/cborutil" | ||
"github.com/filecoin-project/go-fil-components/shared/tokenamount" | ||
"github.com/ipfs/go-cid" | ||
p2pnet "github.com/libp2p/go-libp2p-core/network" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
) | ||
|
||
type queryStream struct { | ||
p peer.ID | ||
s p2pnet.Stream | ||
} | ||
|
||
func (qs queryStream) ReadQuery() (retrievalmarket.Query, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (qs queryStream) WriteQuery(q retrievalmarket.Query) error { | ||
cid, err := cid.Cast(q.PieceCID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return cborutil.WriteCborRPC(qs.s, &retrievalimpl.OldQuery{Piece: cid}) | ||
} | ||
|
||
func (qs queryStream) ReadQueryResponse() (retrievalmarket.QueryResponse, error) { | ||
var oldResp retrievalimpl.OldQueryResponse | ||
if err := oldResp.UnmarshalCBOR(qs.s); err != nil { | ||
log.Warn(err) | ||
return retrievalmarket.QueryResponseUndefined, err | ||
} | ||
|
||
resp := retrievalmarket.QueryResponse{ | ||
Status: retrievalmarket.QueryResponseStatus(oldResp.Status), | ||
Size: oldResp.Size, | ||
MinPricePerByte: tokenamount.Div(oldResp.MinPrice, tokenamount.FromInt(oldResp.Size)), | ||
} | ||
return resp, nil | ||
} | ||
|
||
func (qs queryStream) WriteQueryResponse(retrievalmarket.QueryResponse) error { | ||
panic("implement me") | ||
} | ||
|
||
var _ RetrievalQueryStream = (*queryStream)(nil) | ||
|
||
func (qs queryStream) Close() error { | ||
return qs.s.Close() | ||
} |
Oops, something went wrong.