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
p2p
go-p2p-kad-dht
Commits
eeb97674
Unverified
Commit
eeb97674
authored
Apr 22, 2020
by
Will Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
intercept failing query events when finding providers
parent
278c3ea7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
dual/dual.go
dual/dual.go
+12
-2
No files found.
dual/dual.go
View file @
eeb97674
...
...
@@ -97,8 +97,9 @@ func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error {
func
(
dht
*
DHT
)
FindProvidersAsync
(
ctx
context
.
Context
,
key
cid
.
Cid
,
count
int
)
<-
chan
peer
.
AddrInfo
{
reqCtx
,
cancel
:=
context
.
WithCancel
(
ctx
)
outCh
:=
make
(
chan
peer
.
AddrInfo
)
wanCh
:=
dht
.
WAN
.
FindProvidersAsync
(
reqCtx
,
key
,
count
)
lanCh
:=
dht
.
LAN
.
FindProvidersAsync
(
reqCtx
,
key
,
count
)
subCtx
,
errCh
:=
routing
.
RegisterForQueryEvents
(
reqCtx
)
wanCh
:=
dht
.
WAN
.
FindProvidersAsync
(
subCtx
,
key
,
count
)
lanCh
:=
dht
.
LAN
.
FindProvidersAsync
(
subCtx
,
key
,
count
)
zeroCount
:=
(
count
==
0
)
go
func
()
{
defer
cancel
()
...
...
@@ -106,9 +107,15 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int)
found
:=
make
(
map
[
peer
.
ID
]
struct
{},
count
)
var
pi
peer
.
AddrInfo
var
qEv
*
routing
.
QueryEvent
for
(
zeroCount
||
count
>
0
)
&&
(
wanCh
!=
nil
||
lanCh
!=
nil
)
{
var
ok
bool
select
{
case
qEv
,
ok
=
<-
errCh
:
if
ok
&&
qEv
!=
nil
&&
qEv
.
Type
!=
routing
.
QueryError
{
routing
.
PublishQueryEvent
(
reqCtx
,
qEv
)
}
continue
case
pi
,
ok
=
<-
wanCh
:
if
!
ok
{
wanCh
=
nil
...
...
@@ -133,6 +140,9 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int)
return
}
}
if
qEv
!=
nil
&&
qEv
.
Type
==
routing
.
QueryError
&&
len
(
found
)
==
0
{
routing
.
PublishQueryEvent
(
reqCtx
,
qEv
)
}
}()
return
outCh
}
...
...
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