Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
6c981a3a
Unverified
Commit
6c981a3a
authored
Aug 31, 2020
by
Petar Radovic
Committed by
GitHub
Aug 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
connect to max 3 bootnodes at startup (#636)
parent
531117ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
25 deletions
+24
-25
kademlia.go
pkg/kademlia/kademlia.go
+23
-24
kademlia_test.go
pkg/kademlia/kademlia_test.go
+1
-1
No files found.
pkg/kademlia/kademlia.go
View file @
6c981a3a
...
@@ -238,34 +238,33 @@ func (k *Kad) Start(ctx context.Context) error {
...
@@ -238,34 +238,33 @@ func (k *Kad) Start(ctx context.Context) error {
}
}
func
(
k
*
Kad
)
connectBootnodes
(
ctx
context
.
Context
)
{
func
(
k
*
Kad
)
connectBootnodes
(
ctx
context
.
Context
)
{
var
wg
sync
.
WaitGroup
var
count
int
for
_
,
addr
:=
range
k
.
bootnodes
{
for
_
,
addr
:=
range
k
.
bootnodes
{
wg
.
Add
(
1
)
if
count
==
3
{
go
func
(
a
ma
.
Multiaddr
)
{
return
defer
wg
.
Done
()
}
var
count
int
if
_
,
err
:=
p2p
.
Discover
(
ctx
,
a
,
func
(
addr
ma
.
Multiaddr
)
(
stop
bool
,
err
error
)
{
if
_
,
err
:=
p2p
.
Discover
(
ctx
,
addr
,
func
(
addr
ma
.
Multiaddr
)
(
stop
bool
,
err
error
)
{
k
.
logger
.
Tracef
(
"connecting to bootnode %s"
,
addr
)
k
.
logger
.
Tracef
(
"connecting to bootnode %s"
,
addr
)
_
,
err
=
k
.
p2p
.
ConnectNotify
(
ctx
,
addr
)
_
,
err
=
k
.
p2p
.
ConnectNotify
(
ctx
,
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
if
!
errors
.
Is
(
err
,
p2p
.
ErrAlreadyConnected
)
{
if
!
errors
.
Is
(
err
,
p2p
.
ErrAlreadyConnected
)
{
k
.
logger
.
Debugf
(
"connect fail %s: %v"
,
addr
,
err
)
k
.
logger
.
Debugf
(
"connect fail %s: %v"
,
addr
,
err
)
k
.
logger
.
Warningf
(
"connect to bootnode %s"
,
addr
)
k
.
logger
.
Warningf
(
"connect to bootnode %s"
,
addr
)
}
return
false
,
nil
}
}
k
.
logger
.
Tracef
(
"connected to bootnode %s"
,
addr
)
return
false
,
nil
count
++
// connect to max 3 bootnodes
return
count
>
3
,
nil
});
err
!=
nil
{
k
.
logger
.
Debugf
(
"discover fail %s: %v"
,
a
,
err
)
k
.
logger
.
Warningf
(
"discover to bootnode %s"
,
a
)
return
}
}
}(
addr
)
k
.
logger
.
Tracef
(
"connected to bootnode %s"
,
addr
)
count
++
// connect to max 3 bootnodes
return
count
==
3
,
nil
});
err
!=
nil
{
k
.
logger
.
Debugf
(
"discover fail %s: %v"
,
addr
,
err
)
k
.
logger
.
Warningf
(
"discover to bootnode %s"
,
addr
)
return
}
}
}
wg
.
Wait
()
}
}
// binSaturated indicates whether a certain bin is saturated or not.
// binSaturated indicates whether a certain bin is saturated or not.
...
...
pkg/kademlia/kademlia_test.go
View file @
6c981a3a
...
@@ -721,7 +721,7 @@ func TestStart(t *testing.T) {
...
@@ -721,7 +721,7 @@ func TestStart(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
waitCounter
(
t
,
&
conns
,
5
)
waitCounter
(
t
,
&
conns
,
3
)
waitCounter
(
t
,
&
failedConns
,
0
)
waitCounter
(
t
,
&
failedConns
,
0
)
})
})
}
}
...
...
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