Skip to content

Commit

Permalink
Remove custom internal contextID codec in favour of multicodec
Browse files Browse the repository at this point in the history
Use the same multicodec that identifies transport over graphsync for
filecoinv1 internally to encode context ID as CID, used by the
standalone retrieval server implemented in cardatatransfer.

Because the transport they use is the same as what the multicodec
represents.
  • Loading branch information
masih committed Mar 3, 2022
1 parent b9f86d3 commit 84b2f98
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
9 changes: 2 additions & 7 deletions cardatatransfer/cardatatransfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ type carDataTransfer struct {
stores *stores.ReadOnlyBlockstores
}

// TBD: this is really for internal use only
// -- maybe we find something that doesn't overlap a protocol range?

const ContextIDCodec multicodec.Code = 0x300001

func StartCarDataTransfer(dt datatransfer.Manager, supplier BlockStoreSupplier) error {
cdt := &carDataTransfer{
dt: dt,
Expand All @@ -72,7 +67,7 @@ func StartCarDataTransfer(dt datatransfer.Manager, supplier BlockStoreSupplier)
func MetadataFromContextID(contextID []byte) (stiapi.Metadata, error) {
pieceCid, err := cid.Prefix{
Version: 1,
Codec: uint64(ContextIDCodec),
Codec: uint64(multicodec.TransportGraphsyncFilecoinv1),
MhType: multihash.IDENTITY,
MhLength: -1,
}.Sum(contextID)
Expand Down Expand Up @@ -148,7 +143,7 @@ func (cdt *carDataTransfer) attemptAcceptDeal(providerDealID ProviderDealID, pro

// get contextID
prefix := proposal.PieceCID.Prefix()
if prefix.Codec != uint64(ContextIDCodec) {
if prefix.Codec != uint64(multicodec.TransportGraphsyncFilecoinv1) {
return DealStatusErrored, errors.New("incorrect Piece CID codec")
}
if prefix.MhType != multihash.IDENTITY {
Expand Down
3 changes: 2 additions & 1 deletion cmd/provider/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/index-provider/cardatatransfer"
adminserver "github.com/filecoin-project/index-provider/server/admin/http"
stiapi "github.com/filecoin-project/storetheindex/api/v0"
"github.com/multiformats/go-multicodec"
"github.com/urfave/cli/v2"
)

Expand All @@ -32,7 +33,7 @@ var (
Action: doImportCar,
}
metadata = stiapi.Metadata{
ProtocolID: cardatatransfer.ContextIDCodec,
ProtocolID: multicodec.TransportGraphsyncFilecoinv1,
}
)

Expand Down
4 changes: 2 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/filecoin-project/go-legs/dtsync"
"github.com/filecoin-project/go-legs/httpsync"
provider "github.com/filecoin-project/index-provider"
"github.com/filecoin-project/index-provider/cardatatransfer"
"github.com/filecoin-project/index-provider/engine/chunker"
stiapi "github.com/filecoin-project/storetheindex/api/v0"
"github.com/filecoin-project/storetheindex/api/v0/ingest/schema"
Expand All @@ -21,6 +20,7 @@ import (
logging "github.com/ipfs/go-log/v2"
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/multiformats/go-multicodec"
)

const (
Expand Down Expand Up @@ -410,7 +410,7 @@ func (e *Engine) publishAdvForIndex(ctx context.Context, contextID []byte, metad
// The advertisement still requires a valid metadata even though
// metadata is not used for removal. Create a valid empty metadata.
metadata = stiapi.Metadata{
ProtocolID: cardatatransfer.ContextIDCodec,
ProtocolID: multicodec.TransportGraphsyncFilecoinv1,
}
}

Expand Down

0 comments on commit 84b2f98

Please sign in to comment.