@cryptotaxi247 / kubo / commits / 1cdb9adf8

fix: interop with go-ipfs 0.13 (#160)

This ensures cid-codec introduced in https://github.com/ipfs/go-ipfs/pull/8568 gets correctly passed (+ we maintain backward-compatibility with CIDv0) This commit was moved from ipfs/go-ipfs-http-client@9c9f43fd9ca36c7ebdc664bb6936a6fe9881255b

Marcin Rataj committed Jun 23, 2022 at 22:39 UTC 1cdb9adf898a8a2b9d2cd0d3fe8ba6467a822166
1 file changed +12 -3
client/httpapi/dag.go
+12 -3
@@ -6,11 +6,12 @@ import (
6 "fmt"
7 "io/ioutil"
8
9 - "github.com/ipfs/go-block-format"
9 + blocks "github.com/ipfs/go-block-format"
10 "github.com/ipfs/go-cid"
11 - "github.com/ipfs/go-ipld-format"
11 + format "github.com/ipfs/go-ipld-format"
12 "github.com/ipfs/interface-go-ipfs-core/options"
13 "github.com/ipfs/interface-go-ipfs-core/path"
14 + multicodec "github.com/multiformats/go-multicodec"
15 )
16
17 type httpNodeAdder HttpApi
@@ -56,13 +57,21 @@ func (api *HttpDagServ) GetMany(ctx context.Context, cids []cid.Cid) <-chan *for
57 func (api *httpNodeAdder) add(ctx context.Context, nd format.Node, pin bool) error {
58 c := nd.Cid()
59 prefix := c.Prefix()
59 - format := cid.CodecToStr[prefix.Codec]
60 +
61 + // preserve 'cid-codec' when sent over HTTP
62 + cidCodec := multicodec.Code(prefix.Codec).String()
63 +
64 + // 'format' got replaced by 'cid-codec' in https://github.com/ipfs/interface-go-ipfs-core/pull/80
65 + // but we still support it here for backward-compatibility with use of CIDv0
66 + format := ""
67 if prefix.Version == 0 {
68 + cidCodec = ""
69 format = "v0"
70 }
71
72 stat, err := api.core().Block().Put(ctx, bytes.NewReader(nd.RawData()),
73 options.Block.Hash(prefix.MhType, prefix.MhLength),
74 + options.Block.CidCodec(cidCodec),
75 options.Block.Format(format),
76 options.Block.Pin(pin))
77 if err != nil {