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
9bd5c5d7
Commit
9bd5c5d7
authored
Nov 01, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix filtering bug in find closest peers
parent
d124b897
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
dht_test.go
dht_test.go
+33
-0
lookup.go
lookup.go
+1
-1
No files found.
dht_test.go
View file @
9bd5c5d7
...
...
@@ -824,3 +824,36 @@ func TestClientModeConnect(t *testing.T) {
t
.
Fatal
(
"expected it to be our test peer"
)
}
}
func
TestFindClosestPeers
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
nDHTs
:=
30
_
,
_
,
dhts
:=
setupDHTS
(
ctx
,
nDHTs
,
t
)
defer
func
()
{
for
i
:=
0
;
i
<
nDHTs
;
i
++
{
dhts
[
i
]
.
Close
()
defer
dhts
[
i
]
.
host
.
Close
()
}
}()
t
.
Logf
(
"connecting %d dhts in a ring"
,
nDHTs
)
for
i
:=
0
;
i
<
nDHTs
;
i
++
{
connect
(
t
,
ctx
,
dhts
[
i
],
dhts
[(
i
+
1
)
%
len
(
dhts
)])
}
peers
,
err
:=
dhts
[
1
]
.
GetClosestPeers
(
ctx
,
"foo"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
out
[]
peer
.
ID
for
p
:=
range
peers
{
out
=
append
(
out
,
p
)
}
if
len
(
out
)
!=
KValue
{
t
.
Fatalf
(
"got wrong number of peers (got %d, expected %d)"
,
len
(
out
),
KValue
)
}
}
lookup.go
View file @
9bd5c5d7
...
...
@@ -66,7 +66,7 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) (<-chan pee
var
filtered
[]
pstore
.
PeerInfo
for
_
,
clp
:=
range
closer
{
if
kb
.
Closer
(
clp
,
dht
.
self
,
key
)
&&
peerset
.
TryAdd
(
clp
)
{
if
peerset
.
TryAdd
(
clp
)
{
select
{
case
out
<-
clp
:
case
<-
ctx
.
Done
()
:
...
...
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