Skip to content

Commit

Permalink
fix: interop with go-ipfs 0.13 (#160)
Browse files Browse the repository at this point in the history
This ensures cid-codec introduced in #8568
gets correctly passed (+ we maintain backward-compatibility with CIDv0)

This commit was moved from ipfs/go-ipfs-http-client@9c9f43f
  • Loading branch information
lidel committed Jun 23, 2022
1 parent fd20901 commit 1cdb9ad
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client/httpapi/dag.go
Expand Up @@ -6,11 +6,12 @@ import (
"fmt"
"io/ioutil"

"github.com/ipfs/go-block-format"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipld-format"
format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
multicodec "github.com/multiformats/go-multicodec"
)

type httpNodeAdder HttpApi
Expand Down Expand Up @@ -56,13 +57,21 @@ func (api *HttpDagServ) GetMany(ctx context.Context, cids []cid.Cid) <-chan *for
func (api *httpNodeAdder) add(ctx context.Context, nd format.Node, pin bool) error {
c := nd.Cid()
prefix := c.Prefix()
format := cid.CodecToStr[prefix.Codec]

// preserve 'cid-codec' when sent over HTTP
cidCodec := multicodec.Code(prefix.Codec).String()

// 'format' got replaced by 'cid-codec' in https://github.com/ipfs/interface-go-ipfs-core/pull/80
// but we still support it here for backward-compatibility with use of CIDv0
format := ""
if prefix.Version == 0 {
cidCodec = ""
format = "v0"
}

stat, err := api.core().Block().Put(ctx, bytes.NewReader(nd.RawData()),
options.Block.Hash(prefix.MhType, prefix.MhLength),
options.Block.CidCodec(cidCodec),
options.Block.Format(format),
options.Block.Pin(pin))
if err != nil {
Expand Down

0 comments on commit 1cdb9ad

Please sign in to comment.