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
eafc461a
Commit
eafc461a
authored
Mar 03, 2017
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: add test to reproduce getclosestpeers bug
parent
fa1630a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
1 deletion
+76
-1
dht_test.go
dht_test.go
+75
-0
lookup.go
lookup.go
+1
-1
No files found.
dht_test.go
View file @
eafc461a
...
...
@@ -15,6 +15,7 @@ import (
ds
"github.com/ipfs/go-datastore"
dssync
"github.com/ipfs/go-datastore/sync"
u
"github.com/ipfs/go-ipfs-util"
kb
"github.com/libp2p/go-libp2p-kbucket"
netutil
"github.com/libp2p/go-libp2p-netutil"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
...
...
@@ -826,6 +827,80 @@ func TestClientModeConnect(t *testing.T) {
}
}
func
TestFindPeerQuery
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
nDHTs
:=
121
_
,
allpeers
,
dhts
:=
setupDHTS
(
ctx
,
nDHTs
,
t
)
defer
func
()
{
for
i
:=
0
;
i
<
nDHTs
;
i
++
{
dhts
[
i
]
.
Close
()
defer
dhts
[
i
]
.
host
.
Close
()
}
}()
guy
:=
dhts
[
0
]
others
:=
dhts
[
1
:
]
for
i
:=
0
;
i
<
20
;
i
++
{
for
j
:=
0
;
j
<
10
;
j
++
{
connect
(
t
,
ctx
,
others
[
i
],
others
[
20
+
(
i
*
4
)
+
j
])
}
}
for
i
:=
0
;
i
<
20
;
i
++
{
connect
(
t
,
ctx
,
guy
,
others
[
i
])
}
val
:=
"foobar"
rtval
:=
kb
.
ConvertKey
(
val
)
rtablePeers
:=
guy
.
routingTable
.
NearestPeers
(
rtval
,
KValue
)
if
len
(
rtablePeers
)
!=
20
{
t
.
Fatalf
(
"expected 20 peers back from routing table, got %d"
,
len
(
rtablePeers
))
}
netpeers
:=
guy
.
host
.
Network
()
.
Peers
()
if
len
(
netpeers
)
!=
20
{
t
.
Fatalf
(
"expected 20 peers to be connected, got %d"
,
len
(
netpeers
))
}
rtableset
:=
make
(
map
[
peer
.
ID
]
bool
)
for
_
,
p
:=
range
rtablePeers
{
rtableset
[
p
]
=
true
}
out
,
err
:=
guy
.
GetClosestPeers
(
ctx
,
val
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
notfromrtable
int
var
count
int
var
outpeers
[]
peer
.
ID
for
p
:=
range
out
{
count
++
if
!
rtableset
[
p
]
{
notfromrtable
++
}
outpeers
=
append
(
outpeers
,
p
)
}
if
notfromrtable
==
0
{
t
.
Fatal
(
"got entirely peers from our routing table"
)
}
fmt
.
Println
(
"counts: "
,
count
,
notfromrtable
)
actualclosest
:=
kb
.
SortClosestPeers
(
allpeers
[
1
:
],
rtval
)
exp
:=
actualclosest
[
:
20
]
got
:=
kb
.
SortClosestPeers
(
outpeers
,
rtval
)
for
i
,
v
:=
range
exp
{
if
v
!=
got
[
i
]
{
t
.
Fatal
(
"mismatch in expected closest peers:"
,
exp
,
got
)
}
}
}
func
TestFindClosestPeers
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
...
...
lookup.go
View file @
eafc461a
...
...
@@ -31,7 +31,7 @@ func loggableKey(k string) logging.LoggableMap {
// to the given key
func
(
dht
*
IpfsDHT
)
GetClosestPeers
(
ctx
context
.
Context
,
key
string
)
(
<-
chan
peer
.
ID
,
error
)
{
e
:=
log
.
EventBegin
(
ctx
,
"getClosestPeers"
,
loggableKey
(
key
))
tablepeers
:=
dht
.
routingTable
.
NearestPeers
(
kb
.
ConvertKey
(
key
),
K
Value
)
tablepeers
:=
dht
.
routingTable
.
NearestPeers
(
kb
.
ConvertKey
(
key
),
Alpha
Value
)
if
len
(
tablepeers
)
==
0
{
return
nil
,
kb
.
ErrLookupFailure
}
...
...
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