Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
f539ed1e
Commit
f539ed1e
authored
May 25, 2015
by
Péter Szilágyi
Committed by
Felix Lange
May 26, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: force refresh if the table is empty
parent
5076170f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
13 deletions
+41
-13
table.go
p2p/discover/table.go
+41
-13
No files found.
p2p/discover/table.go
View file @
f539ed1e
...
...
@@ -191,6 +191,12 @@ func (tab *Table) Lookup(targetID NodeID) []*Node {
result
:=
tab
.
closest
(
target
,
bucketSize
)
tab
.
mutex
.
Unlock
()
// If the result set is empty, all nodes were dropped, refresh
if
len
(
result
.
entries
)
==
0
{
tab
.
refresh
()
return
nil
}
for
{
// ask the alpha closest nodes that we haven't asked yet
for
i
:=
0
;
i
<
len
(
result
.
entries
)
&&
pendingQueries
<
alpha
;
i
++
{
...
...
@@ -207,7 +213,7 @@ func (tab *Table) Lookup(targetID NodeID) []*Node {
tab
.
db
.
updateFindFails
(
n
.
ID
,
fails
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Bumping failures for %x: %d"
,
n
.
ID
[
:
8
],
fails
)
if
fails
>
maxFindnodeFailures
{
if
fails
>
=
maxFindnodeFailures
{
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Evacuating node %x: %d findnode failures"
,
n
.
ID
[
:
8
],
fails
)
tab
.
del
(
n
)
}
...
...
@@ -232,8 +238,23 @@ func (tab *Table) Lookup(targetID NodeID) []*Node {
return
result
.
entries
}
// refresh performs a lookup for a random target to keep buckets full.
// refresh performs a lookup for a random target to keep buckets full, or seeds
// the table if it is empty (initial bootstrap or discarded faulty peers).
func
(
tab
*
Table
)
refresh
()
{
seed
:=
true
// If the discovery table is empty, seed with previously known nodes
tab
.
mutex
.
Lock
()
for
_
,
bucket
:=
range
tab
.
buckets
{
if
len
(
bucket
.
entries
)
>
0
{
seed
=
false
break
}
}
tab
.
mutex
.
Unlock
()
// If the table is not empty, try to refresh using the live entries
if
!
seed
{
// The Kademlia paper specifies that the bucket refresh should
// perform a refresh in the least recently used bucket. We cannot
// adhere to this because the findnode target is a 512bit value
...
...
@@ -243,8 +264,15 @@ func (tab *Table) refresh() {
// We perform a lookup with a random target instead.
var
target
NodeID
rand
.
Read
(
target
[
:
])
result
:=
tab
.
Lookup
(
target
)
if
len
(
result
)
==
0
{
// Lookup failed, seed after all
seed
=
true
}
}
if
seed
{
// Pick a batch of previously know seeds to lookup with
seeds
:=
tab
.
db
.
querySeeds
(
10
)
for
_
,
seed
:=
range
seeds
{
...
...
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