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
9b5a0e67
Commit
9b5a0e67
authored
Mar 20, 2020
by
Adin Schmahmann
Committed by
Steven Allen
Apr 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: calling FindProvidersAsync with a count of zero now completes the query
parent
ac9f0335
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
+21
-6
routing.go
routing.go
+21
-6
No files found.
routing.go
View file @
9b5a0e67
...
...
@@ -539,14 +539,22 @@ func (dht *IpfsDHT) FindProviders(ctx context.Context, c cid.Cid) ([]peer.AddrIn
// FindProvidersAsync is the same thing as FindProviders, but returns a channel.
// Peers will be returned on the channel as soon as they are found, even before
// the search query completes.
// the search query completes. If count is zero then the query will run until it
// completes. Note: not reading from the returned channel may block the query
// from progressing.
func
(
dht
*
IpfsDHT
)
FindProvidersAsync
(
ctx
context
.
Context
,
key
cid
.
Cid
,
count
int
)
<-
chan
peer
.
AddrInfo
{
peerOut
:=
make
(
chan
peer
.
AddrInfo
,
count
)
if
!
dht
.
enableProviders
{
peerOut
:=
make
(
chan
peer
.
AddrInfo
)
close
(
peerOut
)
return
peerOut
}
chSize
:=
count
if
count
==
0
{
chSize
=
1
}
peerOut
:=
make
(
chan
peer
.
AddrInfo
,
chSize
)
keyMH
:=
key
.
Hash
()
logger
.
Event
(
ctx
,
"findProviders"
,
multihashLoggableKey
(
keyMH
))
...
...
@@ -558,7 +566,14 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
defer
logger
.
EventBegin
(
ctx
,
"findProvidersAsync"
,
multihashLoggableKey
(
key
))
.
Done
()
defer
close
(
peerOut
)
ps
:=
peer
.
NewLimitedSet
(
count
)
findAll
:=
count
==
0
var
ps
*
peer
.
Set
if
findAll
{
ps
=
peer
.
NewSet
()
}
else
{
ps
=
peer
.
NewLimitedSet
(
count
)
}
provs
:=
dht
.
ProviderManager
.
GetProviders
(
ctx
,
key
)
for
_
,
p
:=
range
provs
{
// NOTE: Assuming that this list of peers is unique
...
...
@@ -573,7 +588,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
// If we have enough peers locally, don't bother with remote RPC
// TODO: is this a DOS vector?
if
ps
.
Size
()
>=
count
{
if
!
findAll
&&
ps
.
Size
()
>=
count
{
return
}
}
...
...
@@ -610,7 +625,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
return
nil
,
ctx
.
Err
()
}
}
if
ps
.
Size
()
>=
count
{
if
!
findAll
&&
ps
.
Size
()
>=
count
{
logger
.
Debugf
(
"got enough providers (%d/%d)"
,
ps
.
Size
(),
count
)
return
nil
,
nil
}
...
...
@@ -630,7 +645,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
return
peers
,
nil
},
func
(
peerset
*
kpeerset
.
SortedPeerset
)
bool
{
return
ps
.
Size
()
>=
count
return
!
findAll
&&
ps
.
Size
()
>=
count
},
)
...
...
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