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
dms3
go-dms3-routing
Commits
4a051a54
Commit
4a051a54
authored
Dec 23, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dht/dht_test: bootstrap synchronously. fares better.
parent
8b4b0b84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
34 deletions
+37
-34
dht/dht.go
dht/dht.go
+13
-19
dht/dht_test.go
dht/dht_test.go
+24
-15
No files found.
dht/dht.go
View file @
4a051a54
...
...
@@ -365,26 +365,20 @@ func (dht *IpfsDHT) PingRoutine(t time.Duration) {
}
// Bootstrap builds up list of peers by requesting random peer IDs
func
(
dht
*
IpfsDHT
)
Bootstrap
(
ctx
context
.
Context
)
{
func
(
dht
*
IpfsDHT
)
Bootstrap
(
ctx
context
.
Context
,
queries
int
)
{
var
wg
sync
.
WaitGroup
// bootstrap sequentially, as results will compound
for
i
:=
0
;
i
<
NumBootstrapQueries
;
i
++
{
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
id
:=
make
([]
byte
,
16
)
rand
.
Read
(
id
)
pi
,
err
:=
dht
.
FindPeer
(
ctx
,
peer
.
ID
(
id
))
if
err
==
routing
.
ErrNotFound
{
// this isn't an error. this is precisely what we expect.
}
else
if
err
!=
nil
{
log
.
Errorf
(
"Bootstrap peer error: %s"
,
err
)
}
else
{
// woah, we got a peer under a random id? it _cannot_ be valid.
log
.
Errorf
(
"dht seemingly found a peer at a random bootstrap id (%s)..."
,
pi
)
}
}()
id
:=
make
([]
byte
,
16
)
rand
.
Read
(
id
)
pi
,
err
:=
dht
.
FindPeer
(
ctx
,
peer
.
ID
(
id
))
if
err
==
routing
.
ErrNotFound
{
// this isn't an error. this is precisely what we expect.
}
else
if
err
!=
nil
{
log
.
Errorf
(
"Bootstrap peer error: %s"
,
err
)
}
else
{
// woah, we got a peer under a random id? it _cannot_ be valid.
log
.
Errorf
(
"dht seemingly found a peer at a random bootstrap id (%s)..."
,
pi
)
}
}
wg
.
Wait
()
}
dht/dht_test.go
View file @
4a051a54
...
...
@@ -93,24 +93,23 @@ func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
func
bootstrap
(
t
*
testing
.
T
,
ctx
context
.
Context
,
dhts
[]
*
IpfsDHT
)
{
// try multiple rounds...
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
rounds
:=
1
for
i
:=
0
;
i
<
rounds
;
i
++
{
fmt
.
Printf
(
"bootstrapping round %d/%d
\n
"
,
i
,
rounds
)
var
wg
sync
.
WaitGroup
// tried async. sequential fares much better. compare:
// 100 async https://gist.github.com/jbenet/56d12f0578d5f34810b2
// 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd
// probably because results compound
for
_
,
dht
:=
range
dhts
{
wg
.
Add
(
1
)
go
func
(
i
int
)
{
defer
wg
.
Done
()
<-
time
.
After
(
time
.
Duration
(
i
)
*
time
.
Millisecond
)
// stagger them to avoid overwhelming
fmt
.
Printf
(
"bootstrapping round %d/%d -- %s
\n
"
,
i
,
rounds
,
dht
.
self
)
dht
.
Bootstrap
(
ctx
)
}(
i
)
fmt
.
Printf
(
"bootstrapping round %d/%d -- %s
\n
"
,
i
,
rounds
,
dht
.
self
)
dht
.
Bootstrap
(
ctx
,
3
)
}
wg
.
Wait
()
}
cancel
()
}
func
TestPing
(
t
*
testing
.
T
)
{
...
...
@@ -260,7 +259,7 @@ func TestProvides(t *testing.T) {
func
TestBootstrap
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
nDHTs
:=
4
0
nDHTs
:=
1
0
_
,
_
,
dhts
:=
setupDHTS
(
ctx
,
nDHTs
,
t
)
defer
func
()
{
for
i
:=
0
;
i
<
nDHTs
;
i
++
{
...
...
@@ -275,7 +274,6 @@ func TestBootstrap(t *testing.T) {
}
<-
time
.
After
(
100
*
time
.
Millisecond
)
t
.
Logf
(
"bootstrapping them so they find each other"
,
nDHTs
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
bootstrap
(
t
,
ctxT
,
dhts
)
...
...
@@ -308,8 +306,19 @@ func TestProvidesMany(t *testing.T) {
connect
(
t
,
ctx
,
dhts
[
i
],
dhts
[(
i
+
1
)
%
len
(
dhts
)])
}
<-
time
.
After
(
100
*
time
.
Millisecond
)
t
.
Logf
(
"bootstrapping them so they find each other"
,
nDHTs
)
bootstrap
(
t
,
ctx
,
dhts
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
bootstrap
(
t
,
ctxT
,
dhts
)
<-
time
.
After
(
5
*
time
.
Second
)
// the routing tables should be full now. let's inspect them.
t
.
Logf
(
"checking routing table of %d"
,
nDHTs
)
for
_
,
dht
:=
range
dhts
{
fmt
.
Printf
(
"checking routing table of %s
\n
"
,
dht
.
self
)
dht
.
routingTable
.
Print
()
fmt
.
Println
(
""
)
}
d
:=
0
for
k
,
v
:=
range
testCaseValues
{
...
...
@@ -341,7 +350,7 @@ func TestProvidesMany(t *testing.T) {
errchan
:=
make
(
chan
error
)
ctxT
,
_
:
=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
ctxT
,
_
=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
var
wg
sync
.
WaitGroup
getProvider
:=
func
(
dht
*
IpfsDHT
,
k
u
.
Key
)
{
...
...
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