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
6adb15f4
Commit
6adb15f4
authored
Aug 28, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
namesys: async: go vet fixes
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
7ff9f09b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
16 deletions
+36
-16
core/corehttp/gateway_test.go
core/corehttp/gateway_test.go
+9
-1
namesys/base.go
namesys/base.go
+14
-10
namesys/dns.go
namesys/dns.go
+6
-2
namesys/interface.go
namesys/interface.go
+2
-2
namesys/namesys_test.go
namesys/namesys_test.go
+5
-1
No files found.
core/corehttp/gateway_test.go
View file @
6adb15f4
...
...
@@ -35,7 +35,7 @@ type mockNamesys map[string]path.Path
func
(
m
mockNamesys
)
Resolve
(
ctx
context
.
Context
,
name
string
,
opts
...
nsopts
.
ResolveOpt
)
(
value
path
.
Path
,
err
error
)
{
cfg
:=
nsopts
.
DefaultResolveOpts
()
for
_
,
o
:=
range
opts
{
o
(
cfg
)
o
(
&
cfg
)
}
depth
:=
cfg
.
Depth
if
depth
==
nsopts
.
UnlimitedDepth
{
...
...
@@ -57,6 +57,14 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re
return
value
,
nil
}
func
(
m
mockNamesys
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
opts
...
nsopts
.
ResolveOpt
)
<-
chan
namesys
.
Result
{
out
:=
make
(
chan
namesys
.
Result
,
1
)
v
,
err
:=
m
.
Resolve
(
ctx
,
name
,
opts
...
)
out
<-
namesys
.
Result
{
Path
:
v
,
Err
:
err
}
close
(
out
)
return
nil
}
func
(
m
mockNamesys
)
Publish
(
ctx
context
.
Context
,
name
ci
.
PrivKey
,
value
path
.
Path
)
error
{
return
errors
.
New
(
"not implemented for mockNamesys"
)
}
...
...
namesys/base.go
View file @
6adb15f4
...
...
@@ -68,23 +68,24 @@ func resolveAsyncDo(ctx context.Context, r resolver, name string, options opts.R
for
{
select
{
case
res
,
ok
:=
<-
resCh
:
if
res
.
err
!=
nil
{
outCh
<-
Result
{
err
:
res
.
err
}
return
}
if
!
ok
{
resCh
=
nil
continue
}
if
res
.
err
!=
nil
{
outCh
<-
Result
{
Err
:
res
.
err
}
return
}
log
.
Debugf
(
"resolved %s to %s"
,
name
,
res
.
value
.
String
())
if
strings
.
HasPrefix
(
res
.
value
.
String
(),
"/ipfs/"
)
{
outCh
<-
Result
{
e
rr
:
res
.
err
}
outCh
<-
Result
{
E
rr
:
res
.
err
}
continue
}
p
:=
strings
.
TrimPrefix
(
res
.
value
.
String
(),
prefix
)
if
depth
==
1
{
outCh
<-
Result
{
e
rr
:
ErrResolveRecursion
}
outCh
<-
Result
{
E
rr
:
ErrResolveRecursion
}
continue
}
...
...
@@ -99,17 +100,20 @@ func resolveAsyncDo(ctx context.Context, r resolver, name string, options opts.R
cancelSub
()
}
subCtx
,
cancelSub
=
context
.
WithCancel
(
ctx
)
defer
cancelSub
()
subCh
=
resolveAsyncDo
(
subCtx
,
r
,
p
,
subopts
,
prefix
)
case
res
,
ok
:=
<-
subCh
:
if
res
.
err
!=
nil
{
outCh
<-
Result
{
err
:
res
.
err
}
return
}
if
!
ok
{
subCh
=
nil
continue
}
if
res
.
Err
!=
nil
{
outCh
<-
Result
{
Err
:
res
.
Err
}
return
}
outCh
<-
res
case
<-
ctx
.
Done
()
:
}
...
...
namesys/dns.go
View file @
6adb15f4
...
...
@@ -31,6 +31,10 @@ func (r *DNSResolver) Resolve(ctx context.Context, name string, options ...opts.
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
),
"/ipns/"
)
}
func
(
r
*
DNSResolver
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
return
resolveAsync
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
),
"/ipns/"
)
}
type
lookupRes
struct
{
path
path
.
Path
error
error
...
...
@@ -112,8 +116,8 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
}
if
subRes
.
error
==
nil
{
select
{
case
out
<-
onceResult
{
value
:
subRes
.
path
}
:
case
<-
ctx
.
Done
()
:
case
out
<-
onceResult
{
value
:
subRes
.
path
}
:
case
<-
ctx
.
Done
()
:
}
return
}
...
...
namesys/interface.go
View file @
6adb15f4
...
...
@@ -65,8 +65,8 @@ type NameSystem interface {
// Result is the return type for Resolver.ResolveAsync.
type
Result
struct
{
p
ath
path
.
Path
e
rr
error
P
ath
path
.
Path
E
rr
error
}
// Resolver is an object capable of resolving names.
...
...
namesys/namesys_test.go
View file @
6adb15f4
...
...
@@ -38,11 +38,15 @@ func testResolution(t *testing.T, resolver Resolver, name string, depth uint, ex
}
}
func
(
r
*
mockResolver
)
resolveOnce
(
ctx
context
.
Context
,
name
string
,
opts
*
opts
.
ResolveOpts
)
(
path
.
Path
,
time
.
Duration
,
error
)
{
func
(
r
*
mockResolver
)
resolveOnce
(
ctx
context
.
Context
,
name
string
,
opts
opts
.
ResolveOpts
)
(
path
.
Path
,
time
.
Duration
,
error
)
{
p
,
err
:=
path
.
ParsePath
(
r
.
entries
[
name
])
return
p
,
0
,
err
}
func
(
r
*
mockResolver
)
resolveOnceAsync
(
ctx
context
.
Context
,
name
string
,
options
opts
.
ResolveOpts
)
<-
chan
onceResult
{
panic
(
"stub"
)
}
func
mockResolverOne
()
*
mockResolver
{
return
&
mockResolver
{
entries
:
map
[
string
]
string
{
...
...
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