Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
3f7d11f5
Commit
3f7d11f5
authored
Jan 05, 2016
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2116 from Kubuxu/fix/#2059
namesys: Make paths with multiple segemnts work. Fixes #2059
parents
4ba3a754
bcfb3d72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
7 deletions
+36
-7
namesys/dns.go
namesys/dns.go
+8
-3
namesys/dns_test.go
namesys/dns_test.go
+20
-0
namesys/namesys.go
namesys/namesys.go
+7
-3
namesys/routing.go
namesys/routing.go
+1
-1
No files found.
namesys/dns.go
View file @
3f7d11f5
...
...
@@ -45,12 +45,14 @@ 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
}
...
...
@@ -58,6 +60,9 @@ func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path,
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
}
}
...
...
namesys/dns_test.go
View file @
3f7d11f5
...
...
@@ -18,6 +18,7 @@ func (m *mockDNS) lookupTXT(name string) (txt []string, err error) {
}
func
TestDnsEntryParsing
(
t
*
testing
.
T
)
{
goodEntries
:=
[]
string
{
"QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD"
,
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD"
,
...
...
@@ -25,6 +26,7 @@ func TestDnsEntryParsing(t *testing.T) {
"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
)
}
namesys/namesys.go
View file @
3f7d11f5
...
...
@@ -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
)
...
...
namesys/routing.go
View file @
3f7d11f5
...
...
@@ -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
.
Warning
f
(
"RoutingResolve: bad input hash: [%s]
\n
"
,
name
)
return
""
,
err
}
// name should be a multihash. if it isn't, error out here.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment