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
24c9ebcb
Unverified
Commit
24c9ebcb
authored
Jan 04, 2021
by
acud
Committed by
GitHub
Jan 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kademlia: limit bootnode connection attempts (#1068)
parent
c7f8c08e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
kademlia.go
pkg/kademlia/kademlia.go
+15
-6
handshake.go
pkg/p2p/libp2p/internal/handshake/handshake.go
+1
-1
No files found.
pkg/kademlia/kademlia.go
View file @
24c9ebcb
...
...
@@ -23,8 +23,9 @@ import (
)
const
(
nnLowWatermark
=
2
// the number of peers in consecutive deepest bins that constitute as nearest neighbours
maxConnAttempts
=
3
// when there is maxConnAttempts failed connect calls for a given peer it is considered non-connectable
nnLowWatermark
=
2
// the number of peers in consecutive deepest bins that constitute as nearest neighbours
maxConnAttempts
=
3
// when there is maxConnAttempts failed connect calls for a given peer it is considered non-connectable
maxBootnodeAttempts
=
3
// how many attempts to dial to bootnodes before giving up
)
var
(
...
...
@@ -218,6 +219,7 @@ func (k *Kad) manage() {
}
if
k
.
connectedPeers
.
Length
()
==
0
{
k
.
logger
.
Debug
(
"kademlia has no connected peers, trying bootnodes"
)
k
.
connectBootnodes
(
ctx
)
}
...
...
@@ -238,21 +240,28 @@ func (k *Kad) Start(ctx context.Context) error {
}
func
(
k
*
Kad
)
connectBootnodes
(
ctx
context
.
Context
)
{
var
count
int
var
attempts
,
connected
int
var
totalAttempts
=
maxBootnodeAttempts
*
len
(
k
.
bootnodes
)
for
_
,
addr
:=
range
k
.
bootnodes
{
if
count
>=
3
{
if
attempts
>=
totalAttempts
||
connected
>=
3
{
return
}
if
_
,
err
:=
p2p
.
Discover
(
ctx
,
addr
,
func
(
addr
ma
.
Multiaddr
)
(
stop
bool
,
err
error
)
{
k
.
logger
.
Tracef
(
"connecting to bootnode %s"
,
addr
)
if
attempts
>=
maxBootnodeAttempts
{
return
true
,
nil
}
bzzAddress
,
err
:=
k
.
p2p
.
Connect
(
ctx
,
addr
)
attempts
++
if
err
!=
nil
{
if
!
errors
.
Is
(
err
,
p2p
.
ErrAlreadyConnected
)
{
k
.
logger
.
Debugf
(
"connect fail %s: %v"
,
addr
,
err
)
k
.
logger
.
Warningf
(
"connect to bootnode %s"
,
addr
)
return
false
,
err
}
k
.
logger
.
Debugf
(
"connect to bootnode fail: %v"
,
err
)
return
false
,
nil
}
...
...
@@ -260,9 +269,9 @@ func (k *Kad) connectBootnodes(ctx context.Context) {
return
false
,
err
}
k
.
logger
.
Tracef
(
"connected to bootnode %s"
,
addr
)
co
unt
++
co
nnected
++
// connect to max 3 bootnodes
return
co
unt
>=
3
,
nil
return
co
nnected
>=
3
,
nil
});
err
!=
nil
{
k
.
logger
.
Debugf
(
"discover fail %s: %v"
,
addr
,
err
)
k
.
logger
.
Warningf
(
"discover to bootnode %s"
,
addr
)
...
...
pkg/p2p/libp2p/internal/handshake/handshake.go
View file @
24c9ebcb
...
...
@@ -50,7 +50,7 @@ var (
// ErrInvalidSyn is returned if observable address in ack is not a valid..
ErrInvalidSyn
=
errors
.
New
(
"invalid syn"
)
// ErrWelcomeMessageLength is return if the welcome message is longer than the maximum length
// ErrWelcomeMessageLength is return
ed
if the welcome message is longer than the maximum length
ErrWelcomeMessageLength
=
fmt
.
Errorf
(
"handshake welcome message longer than maximum of %d characters"
,
MaxWelcomeMessageLength
)
)
...
...
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