From 1a9ff602464b04cef2a483672138786058d593a2 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Thu, 13 Jun 2019 15:08:36 +0100 Subject: [PATCH 1/2] Allow resolution of .eth names via .eth.link --- namesys/namesys.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/namesys/namesys.go b/namesys/namesys.go index 6d59c62e334..cf944001d97 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -80,6 +80,9 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R return resolveAsync(ctx, ns, name, opts.ProcessOpts(options)) } +const ethTLD = ".eth" +const linkTLD = ".link" + // resolveOnce implements resolver. func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.ResolveOpts) <-chan onceResult { out := make(chan onceResult, 1) @@ -87,6 +90,11 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. if !strings.HasPrefix(name, ipnsPrefix) { name = ipnsPrefix + name } + if strings.HasSuffix(name, ethTLD) { + // This is an ENS name. As we're resolving via an arbitrary DNS server + // that may not know about .eth we need to add our link domain suffix. + name = name + linkTLD + } segments := strings.SplitN(name, "/", 4) if len(segments) < 3 || segments[0] != "" { log.Debugf("invalid name syntax for %s", name) From a7f322f8747d78a4a29374f4bd8b60311c08e3bf Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Thu, 4 Jul 2019 18:44:17 +0100 Subject: [PATCH 2/2] Add test for resolution of .eth names --- namesys/namesys_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index 031ae833ac6..d1ecf49e858 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -51,6 +51,7 @@ func mockResolverOne() *mockResolver { "QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy": "/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj", "QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n": "/ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy", "QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD": "/ipns/ipfs.io", + "QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei": "/ipfs/QmP3ouCnU8NNLsW6261pAx2pNLV2E4dQoisB1sgda12Act", }, } } @@ -58,7 +59,8 @@ func mockResolverOne() *mockResolver { func mockResolverTwo() *mockResolver { return &mockResolver{ entries: map[string]string{ - "ipfs.io": "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", + "ipfs.io": "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", + "www.wealdtech.eth.link": "/ipns/QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei", }, } } @@ -80,6 +82,8 @@ func TestNamesysResolution(t *testing.T) { testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 1, "/ipns/ipfs.io", ErrResolveRecursion) testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 2, "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", ErrResolveRecursion) testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 3, "/ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy", ErrResolveRecursion) + testResolution(t, r, "/ipns/www.wealdtech.eth", 1, "/ipns/QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei", ErrResolveRecursion) + testResolution(t, r, "/ipns/www.wealdtech.eth", 2, "/ipfs/QmP3ouCnU8NNLsW6261pAx2pNLV2E4dQoisB1sgda12Act", nil) } func TestPublishWithCache0(t *testing.T) {