Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit ecf364c

Browse files
authored
fix: interop with 'block put' from go-ipfs 0.13 (#158)
* chore: interop with go-ipfs 0.13 Applies necessary changes to ensure 'block/put' works and is backward-compatible. Context: ipfs/kubo#8568 * chore: 0.3.1 bumping as patch because we bumped to 0.3.0 recently, as part of other (unreleased) go-ipfs 0.13 work
1 parent fdbee7c commit ecf364c

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

block.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"io"
88

99
"github.com/ipfs/go-cid"
10-
"github.com/ipfs/interface-go-ipfs-core"
10+
iface "github.com/ipfs/interface-go-ipfs-core"
1111
caopts "github.com/ipfs/interface-go-ipfs-core/options"
1212
"github.com/ipfs/interface-go-ipfs-core/path"
13+
mc "github.com/multiformats/go-multicodec"
1314
mh "github.com/multiformats/go-multihash"
1415
)
1516

@@ -31,20 +32,33 @@ func (s *blockStat) Path() path.Resolved {
3132
}
3233

3334
func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error) {
34-
options, _, err := caopts.BlockPutOptions(opts...)
35+
options, err := caopts.BlockPutOptions(opts...)
36+
px := options.CidPrefix
3537
if err != nil {
3638
return nil, err
3739
}
3840

39-
mht, ok := mh.Codes[options.MhType]
41+
mht, ok := mh.Codes[px.MhType]
4042
if !ok {
41-
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
43+
return nil, fmt.Errorf("unknowm mhType %d", px.MhType)
44+
}
45+
46+
var cidOptKey, cidOptVal string
47+
switch {
48+
case px.Version == 0 && px.Codec == cid.DagProtobuf:
49+
// ensure legacy --format=v0 passes as BlockPutOption still works
50+
cidOptKey = "format"
51+
cidOptVal = "v0"
52+
default:
53+
// pass codec as string
54+
cidOptKey = "cid-codec"
55+
cidOptVal = mc.Code(px.Codec).String()
4256
}
4357

4458
req := api.core().Request("block/put").
4559
Option("mhtype", mht).
46-
Option("mhlen", options.MhLength).
47-
Option("format", options.Codec).
60+
Option("mhlen", px.MhLength).
61+
Option(cidOptKey, cidOptVal).
4862
Option("pin", options.Pin).
4963
FileBody(r)
5064

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ require (
99
github.com/ipfs/go-merkledag v0.6.0
1010
github.com/ipfs/go-path v0.1.1
1111
github.com/ipfs/go-unixfs v0.2.5
12-
github.com/ipfs/interface-go-ipfs-core v0.6.2
12+
github.com/ipfs/interface-go-ipfs-core v0.7.0
1313
github.com/ipfs/iptb v1.4.0
1414
github.com/ipfs/iptb-plugins v0.3.0
1515
github.com/libp2p/go-libp2p-core v0.8.6
1616
github.com/mitchellh/go-homedir v1.1.0
1717
github.com/multiformats/go-multiaddr v0.3.3
1818
github.com/multiformats/go-multibase v0.0.3
19+
github.com/multiformats/go-multicodec v0.4.1
1920
github.com/multiformats/go-multihash v0.0.15
2021
github.com/pkg/errors v0.9.1
2122
)

go.sum

+5-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ github.com/ipfs/go-unixfs v0.2.5/go.mod h1:SUdisfUjNoSDzzhGVxvCL9QO/nKdwXdr+gbMU
378378
github.com/ipfs/go-unixfsnode v1.1.2/go.mod h1:5dcE2x03pyjHk4JjamXmunTMzz+VUtqvPwZjIEkfV6s=
379379
github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2E=
380380
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
381-
github.com/ipfs/interface-go-ipfs-core v0.6.2 h1:nnkq9zhb5O8lPzkZeynEymc83RqkTRqfYH4x5JNUkT4=
382-
github.com/ipfs/interface-go-ipfs-core v0.6.2/go.mod h1:h3NuO3wzv2KuKazt0zDF2/i8AFRqiKHusyh5DUQQdPA=
381+
github.com/ipfs/interface-go-ipfs-core v0.7.0 h1:7tb+2upz8oCcjIyjo1atdMk+P+u7wPmI+GksBlLE8js=
382+
github.com/ipfs/interface-go-ipfs-core v0.7.0/go.mod h1:lF27E/nnSPbylPqKVXGZghal2hzifs3MmjyiEjnc9FY=
383383
github.com/ipfs/iptb v1.4.0 h1:YFYTrCkLMRwk/35IMyC6+yjoQSHTEcNcefBStLJzgvo=
384384
github.com/ipfs/iptb v1.4.0/go.mod h1:1rzHpCYtNp87/+hTxG5TfCVn/yMY3dKnLn8tBiMfdmg=
385385
github.com/ipfs/iptb-plugins v0.3.0 h1:C1rpq1o5lUZtaAOkLIox5akh6ba4uk/3RwWc6ttVxw0=
@@ -756,6 +756,9 @@ github.com/multiformats/go-multiaddr-net v0.2.0/go.mod h1:gGdH3UXny6U3cKKYCvpXI5
756756
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
757757
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
758758
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
759+
github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ=
760+
github.com/multiformats/go-multicodec v0.4.1 h1:BSJbf+zpghcZMZrwTYBGwy0CPcVZGWiC72Cp8bBd4R4=
761+
github.com/multiformats/go-multicodec v0.4.1/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
759762
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
760763
github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
761764
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=

version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "v0.3.0"
2+
"version": "v0.3.1"
33
}

0 commit comments

Comments
 (0)