Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4ba3a754ae99
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3f7d11f598a2
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 5, 2016

  1. namesys: Make paths with multiple segemnts work. Fixes #2059

     Also fixes non-recursive resolve erring instead showing one step.
    
     The patch of core/commands/resolve.go could be done better but I don't
     know how to get access to ErrResolveRecursion.
    
     It allows for dnslinks into sub-segments. So for example hosting
     multiple blogs
     on just domains from one pubkey.
    
     Fixes #2059
    
     Add tests and fix case when dnslinks references dnslink
    
    License: MIT
    Signed-off-by: Jakub (Kubuxu) Sztandera <kubuxu@gmail.com>
    Kubuxu committed Jan 5, 2016

    Verified

    This commit was signed with the committer’s verified signature.
    KinectTheUnknown David-Joseph Xayavong
    Copy the full SHA
    85774b8 View commit details
  2. Included more namesys tests.

    Fixed some issues with trailing slashes.
    
    License: MIT
    Signed-off-by: Jakub (Kubuxu) Sztandera <kubuxu@gmail.com>
    Kubuxu committed Jan 5, 2016

    Verified

    This commit was signed with the committer’s verified signature.
    KinectTheUnknown David-Joseph Xayavong
    Copy the full SHA
    bcfb3d7 View commit details
  3. Merge pull request #2116 from Kubuxu/fix/#2059

    namesys: Make paths with multiple segemnts work. Fixes #2059
    whyrusleeping committed Jan 5, 2016

    Verified

    This commit was signed with the committer’s verified signature.
    KinectTheUnknown David-Joseph Xayavong
    Copy the full SHA
    3f7d11f View commit details
Showing with 36 additions and 7 deletions.
  1. +8 −3 namesys/dns.go
  2. +20 −0 namesys/dns_test.go
  3. +7 −3 namesys/namesys.go
  4. +1 −1 namesys/routing.go
11 changes: 8 additions & 3 deletions namesys/dns.go
Original file line number Diff line number Diff line change
@@ -45,19 +45,24 @@ func (r *DNSResolver) ResolveN(ctx context.Context, name string, depth int) (pat
// TXT records for a given domain name should contain a b58
// encoded multihash.
func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
if !isd.IsDomain(name) {
segments := strings.SplitN(name, "/", 2)

if !isd.IsDomain(segments[0]) {
return "", errors.New("not a valid domain name")
}

log.Infof("DNSResolver resolving %s", name)
txt, err := r.lookupTXT(name)
log.Infof("DNSResolver resolving %s", segments[0])
txt, err := r.lookupTXT(segments[0])
if err != nil {
return "", err
}

for _, t := range txt {
p, err := parseEntry(t)
if err == nil {
if len(segments) > 1 {
return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[1])
}
return p, nil
}
}
20 changes: 20 additions & 0 deletions namesys/dns_test.go
Original file line number Diff line number Diff line change
@@ -18,13 +18,15 @@ func (m *mockDNS) lookupTXT(name string) (txt []string, err error) {
}

func TestDnsEntryParsing(t *testing.T) {

goodEntries := []string{
"QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
"dnslink=/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo",
"dnslink=/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/bar",
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo/bar/baz",
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo/bar/baz/",
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
}

@@ -86,6 +88,18 @@ func newMockDNS() *mockDNS {
"bad.example.com": []string{
"dnslink=",
},
"withsegment.example.com": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment",
},
"withrecsegment.example.com": []string{
"dnslink=/ipns/withsegment.example.com/subsub",
},
"withtrailing.example.com": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/",
},
"withtrailingrec.example.com": []string{
"dnslink=/ipns/withtrailing.example.com/segment/",
},
},
}
}
@@ -109,4 +123,10 @@ func TestDNSResolution(t *testing.T) {
testResolution(t, r, "loop1.example.com", 3, "/ipns/loop2.example.com", ErrResolveRecursion)
testResolution(t, r, "loop1.example.com", DefaultDepthLimit, "/ipns/loop1.example.com", ErrResolveRecursion)
testResolution(t, r, "bad.example.com", DefaultDepthLimit, "", ErrResolveFailed)
testResolution(t, r, "withsegment.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment", nil)
testResolution(t, r, "withrecsegment.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub", nil)
testResolution(t, r, "withsegment.example.com/test1", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/test1", nil)
testResolution(t, r, "withrecsegment.example.com/test2", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub/test2", nil)
testResolution(t, r, "withrecsegment.example.com/test3/", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub/test3/", nil)
testResolution(t, r, "withtrailingrec.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/", nil)
}
10 changes: 7 additions & 3 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
@@ -64,17 +64,21 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
if !strings.HasPrefix(name, "/ipns/") {
name = "/ipns/" + name
}
segments := strings.SplitN(name, "/", 3)
segments := strings.SplitN(name, "/", 4)
if len(segments) < 3 || segments[0] != "" {
log.Warningf("Invalid name syntax for %s", name)
return "", ErrResolveFailed
}

for protocol, resolver := range ns.resolvers {
log.Debugf("Attempting to resolve %s with %s", name, protocol)
log.Debugf("Attempting to resolve %s with %s", segments[2], protocol)
p, err := resolver.resolveOnce(ctx, segments[2])
if err == nil {
return p, err
if len(segments) > 3 {
return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
} else {
return p, err
}
}
}
log.Warningf("No resolver found for %s", name)
2 changes: 1 addition & 1 deletion namesys/routing.go
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa

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