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

fix: CIDv1 error with go-libp2p 0.19 #32

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right.

Just playing this out though, if there is a DNSLink name that is a CIDv1 with a codec other than libp2p-key it previously would've worked as long as the codec wasn't dag-pb but now always fails. To be fair, the realm of TLD DNSLinks (i.e. foo not foo.bar or foo.bar.baz) has a bunch of sketchy areas anyway and is uncommon so I'm not too concerned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in some sense we had a bug before and this fixed it. Now, we always prioritize CIDs over DNSLink names, so if someone tries to squat Handshake TLD that looks like a valid CID, it won't work.

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