Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
fix: CIDv1 error with go-libp2p 0.19 (#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.
  • Loading branch information
lidel authored Apr 27, 2022
1 parent bf4b3cf commit 605965e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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 605965e

Please sign in to comment.