Commit 6a81c72c authored by Steven Allen's avatar Steven Allen

correctly handle multi-hop dnslink resolution

Namesys returns `ErrResolveRecursion` when it stops recursing due to a depth
limit. It doesn't return success.

Alternative to #5199.

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent e7938a18
...@@ -40,7 +40,10 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re ...@@ -40,7 +40,10 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re
if depth == nsopts.UnlimitedDepth { if depth == nsopts.UnlimitedDepth {
depth = math.MaxUint64 depth = math.MaxUint64
} }
for depth > 0 && strings.HasPrefix(name, "/ipns/") { for strings.HasPrefix(name, "/ipns/") {
if depth <= 0 {
return value, namesys.ErrResolveRecursion
}
depth-- depth--
var ok bool var ok bool
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"strings" "strings"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
namesys "github.com/ipfs/go-ipfs/namesys"
nsopts "github.com/ipfs/go-ipfs/namesys/opts" nsopts "github.com/ipfs/go-ipfs/namesys/opts"
isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain" isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain"
...@@ -25,7 +26,8 @@ func IPNSHostnameOption() ServeOption { ...@@ -25,7 +26,8 @@ func IPNSHostnameOption() ServeOption {
host := strings.SplitN(r.Host, ":", 2)[0] host := strings.SplitN(r.Host, ":", 2)[0]
if len(host) > 0 && isd.IsDomain(host) { if len(host) > 0 && isd.IsDomain(host) {
name := "/ipns/" + host name := "/ipns/" + host
if _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)); err == nil { _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1))
if err == nil || err == namesys.ErrResolveRecursion {
r.Header.Set("X-Ipns-Original-Path", r.URL.Path) r.Header.Set("X-Ipns-Original-Path", r.URL.Path)
r.URL.Path = name + r.URL.Path r.URL.Path = name + r.URL.Path
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment