Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
fix: switch to go-multicodec mappings (#240)
Browse files Browse the repository at this point in the history
The mappings in go-cid were maintained by hand and are invalid.
More details in ipfs/go-cid#137

This is switching to go-multicodec which has correct mappings
that are generated, not written by hand.

Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
lidel and mvdan authored Mar 31, 2022
1 parent 4a03a82 commit 2a28e1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/minio/sha256-simd v0.1.1
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.4.1
github.com/multiformats/go-multicodec v0.4.1
github.com/multiformats/go-multihash v0.0.14
github.com/multiformats/go-varint v0.0.6
github.com/stretchr/testify v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/multiformats/go-multiaddr v0.4.1 h1:Pq37uLx3hsyNlTDir7FZyU8+cFCTqd5y1
github.com/multiformats/go-multiaddr v0.4.1/go.mod h1:3afI9HfVW8csiF8UZqtpYRiDyew8pRX7qLIGHu9FLuM=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multicodec v0.4.1 h1:BSJbf+zpghcZMZrwTYBGwy0CPcVZGWiC72Cp8bBd4R4=
github.com/multiformats/go-multicodec v0.4.1/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
Expand Down
11 changes: 4 additions & 7 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ipfs/go-cid"
ic "github.com/libp2p/go-libp2p-core/crypto"
b58 "github.com/mr-tron/base58/base58"
mc "github.com/multiformats/go-multicodec"
mh "github.com/multiformats/go-multihash"
)

Expand Down Expand Up @@ -162,13 +163,9 @@ func Encode(id ID) string {

// FromCid converts a CID to a peer ID, if possible.
func FromCid(c cid.Cid) (ID, error) {
ty := c.Type()
if ty != cid.Libp2pKey {
s := cid.CodecToStr[ty]
if s == "" {
s = fmt.Sprintf("[unknown multicodec %d]", ty)
}
return "", fmt.Errorf("can't convert CID of type %s to a peer ID", s)
code := mc.Code(c.Type())
if code != mc.Libp2pKey {
return "", fmt.Errorf("can't convert CID of type %q to a peer ID", code)
}
return ID(c.Hash()), nil
}
Expand Down

0 comments on commit 2a28e1d

Please sign in to comment.