Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

api: do not try to resolve swarm hashes over ens #2081

Merged
merged 1 commit into from
Jan 28, 2020
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: 4 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func (a *API) Store(ctx context.Context, data io.Reader, size int64, toEncrypt b
// Resolve a name into a content-addressed hash
// where address could be an ENS/RNS name, or a content addressed hash
func (a *API) Resolve(ctx context.Context, address string) (storage.Address, error) {
// if the address is a hash, do not resolve
if hashMatcher.MatchString(address) {
return common.Hex2Bytes(address), nil
}
// if address is .rsk, resolve it with RNS resolver
if tld(address) == "rsk" {
// if RNS is not configured, return an error
Expand All @@ -249,18 +253,12 @@ func (a *API) Resolve(ctx context.Context, address string) (storage.Address, err
}
// if DNS is not configured, return an error
if a.dns == nil {
if hashMatcher.MatchString(address) {
return common.Hex2Bytes(address), nil
}
apiResolveFail.Inc(1)
return nil, fmt.Errorf("no DNS to resolve name: %q", address)
}
// try and resolve the address
resolved, err := a.dns.Resolve(address)
if err != nil {
if hashMatcher.MatchString(address) {
return common.Hex2Bytes(address), nil
}
return nil, err
}
return resolved[:], nil
Expand Down
4 changes: 2 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ func TestAPIResolve(t *testing.T) {
expectErr: errors.New(`no DNS to resolve name: "swarm.eth"`),
},
{
desc: "DNS configured, hash address, hash resolves, returns resolved address",
desc: "DNS not configured, hash address, hash resolves, returns hash",
dns: doesResolve,
addr: hashAddr,
result: resolvedAddr,
result: hashAddr,
},
{
desc: "DNS configured, immutable hash address, hash resolves, returns hash address",
Expand Down