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
1fc99d5e
Unverified
Commit
1fc99d5e
authored
May 19, 2020
by
Adin Schmahmann
Committed by
GitHub
May 19, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #648 from libp2p/feat/put-back-test
Put back TestSelfWalkOnAddressChange
parents
2851c88a
ef3c037f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
dht_bootstrap_test.go
dht_bootstrap_test.go
+48
-0
No files found.
dht_bootstrap_test.go
0 → 100644
View file @
1fc99d5e
package
dht
import
(
"context"
"testing"
"time"
"github.com/libp2p/go-libp2p-core/event"
kb
"github.com/libp2p/go-libp2p-kbucket"
"github.com/stretchr/testify/require"
)
func
TestSelfWalkOnAddressChange
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
// create three DHT instances with auto refresh disabled
d1
:=
setupDHT
(
ctx
,
t
,
false
,
DisableAutoRefresh
())
d2
:=
setupDHT
(
ctx
,
t
,
false
,
DisableAutoRefresh
())
d3
:=
setupDHT
(
ctx
,
t
,
false
,
DisableAutoRefresh
())
var
connectedTo
*
IpfsDHT
// connect d1 to whoever is "further"
if
kb
.
CommonPrefixLen
(
kb
.
ConvertPeerID
(
d1
.
self
),
kb
.
ConvertPeerID
(
d2
.
self
))
<=
kb
.
CommonPrefixLen
(
kb
.
ConvertPeerID
(
d1
.
self
),
kb
.
ConvertPeerID
(
d3
.
self
))
{
connect
(
t
,
ctx
,
d1
,
d3
)
connectedTo
=
d3
}
else
{
connect
(
t
,
ctx
,
d1
,
d2
)
connectedTo
=
d2
}
// then connect d2 AND d3
connect
(
t
,
ctx
,
d2
,
d3
)
// d1 should have ONLY 1 peer in it's RT
waitForWellFormedTables
(
t
,
[]
*
IpfsDHT
{
d1
},
1
,
1
,
2
*
time
.
Second
)
require
.
Equal
(
t
,
connectedTo
.
self
,
d1
.
routingTable
.
ListPeers
()[
0
])
// now emit the address change event
em
,
err
:=
d1
.
host
.
EventBus
()
.
Emitter
(
&
event
.
EvtLocalAddressesUpdated
{})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
em
.
Emit
(
event
.
EvtLocalAddressesUpdated
{}))
waitForWellFormedTables
(
t
,
[]
*
IpfsDHT
{
d1
},
2
,
2
,
2
*
time
.
Second
)
// it should now have both peers in the RT
ps
:=
d1
.
routingTable
.
ListPeers
()
require
.
Contains
(
t
,
ps
,
d2
.
self
)
require
.
Contains
(
t
,
ps
,
d3
.
self
)
}
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