From 84b2f982bb4bf382fda721882778e3e8f7e0117c Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Thu, 3 Mar 2022 10:40:46 +0000 Subject: [PATCH] Remove custom internal contextID codec in favour of multicodec 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. --- cardatatransfer/cardatatransfer.go | 9 ++------- cmd/provider/import.go | 3 ++- engine/engine.go | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cardatatransfer/cardatatransfer.go b/cardatatransfer/cardatatransfer.go index 667eff1b..9dd226e2 100644 --- a/cardatatransfer/cardatatransfer.go +++ b/cardatatransfer/cardatatransfer.go @@ -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, @@ -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) @@ -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 { diff --git a/cmd/provider/import.go b/cmd/provider/import.go index 528b54cf..11fa6989 100644 --- a/cmd/provider/import.go +++ b/cmd/provider/import.go @@ -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" ) @@ -32,7 +33,7 @@ var ( Action: doImportCar, } metadata = stiapi.Metadata{ - ProtocolID: cardatatransfer.ContextIDCodec, + ProtocolID: multicodec.TransportGraphsyncFilecoinv1, } ) diff --git a/engine/engine.go b/engine/engine.go index efcb7020..1e7bb1f6 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -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" @@ -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 ( @@ -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, } }