Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

directly parse peer IDs as peer IDs #5409

Merged
merged 3 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
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
10 changes: 2 additions & 8 deletions namesys/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,10 @@ func (r *IpnsResolver) resolveOnce(ctx context.Context, name string, options *op
}

name = strings.TrimPrefix(name, "/ipns/")
hash, err := mh.FromB58String(name)
pid, err := peer.IDB58Decode(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I am missing something, this is not performing the same set of checks. In particular peer.IDB58Decode does not check it is a valid Multihash: https://github.com/libp2p/go-libp2p-peer/blob/master/peer.go#L121:L127

Copy link
Member Author

Choose a reason for hiding this comment

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

It calls mh.FromB58String internally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops sorry.

if err != nil {
// name should be a multihash. if it isn't, error out here.
log.Debugf("RoutingResolver: bad input hash: [%s]\n", name)
return "", 0, err
}

pid, err := peer.IDFromBytes(hash)
if err != nil {
log.Debugf("RoutingResolver: could not convert public key hash %s to peer ID: %s\n", name, err)
log.Debugf("RoutingResolver: IPNS address not a valid peer ID: [%s]\n", name)
return "", 0, err
}

Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0236-cli-api-dns-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_init_ipfs
test_expect_success "can make http request against dns resolved nc server" '
nc -ld 5005 > nc_out &
NCPID=$!
go-sleep 0.5s && kill "$NCPID" &
go-sleep 1s && kill "$NCPID" &
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 || true
'

Expand Down