Skip to content

Commit

Permalink
fix: CIDv1 error with go-libp2p 0.19 (ipfs#32)
Browse files Browse the repository at this point in the history
The error message changed in libp2p and we no longer get this nice error
message. String matching is a bad practice so just removing it, as we
validate CID and codec already.

This commit was moved from ipfs/go-namesys@605965e
  • Loading branch information
lidel authored Apr 27, 2022
1 parent 948dcb3 commit 043eed1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.

// CIDs in IPNS are expected to have libp2p-key multicodec
// We ease the transition by returning a more meaningful error with a valid CID
if err != nil && err.Error() == "can't convert CID of type protobuf to a peer ID" {
if err != nil {
ipnsCid, cidErr := cid.Decode(key)
if cidErr == nil && ipnsCid.Version() == 1 && ipnsCid.Type() != cid.Libp2pKey {
fixedCid := cid.NewCidV1(cid.Libp2pKey, ipnsCid.Hash()).String()
codecErr := fmt.Errorf("peer ID represented as CIDv1 require libp2p-key multicodec: retry with /ipns/%s", fixedCid)
log.Debugf("RoutingResolver: could not convert public key hash %s to peer ID: %s\n", key, codecErr)
log.Debugf("RoutingResolver: could not convert public key hash %q to peer ID: %s\n", key, codecErr)
out <- onceResult{err: codecErr}
close(out)
return out
Expand Down

0 comments on commit 043eed1

Please sign in to comment.