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
139439dc
Commit
139439dc
authored
Jun 23, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1309 from fjl/p2p-fix-lookup-spin
p2p: throttle all discovery lookups
parents
9cf7913c
6fb810ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
dial.go
p2p/dial.go
+15
-15
server.go
p2p/server.go
+1
-0
No files found.
p2p/dial.go
View file @
139439dc
...
...
@@ -17,10 +17,9 @@ const (
// redialing a certain node.
dialHistoryExpiration
=
30
*
time
.
Second
// Discovery lookup tasks will wait for this long when
// no results are returned. This can happen if the table
// becomes empty (i.e. not often).
emptyLookupDelay
=
10
*
time
.
Second
// Discovery lookups are throttled and can only run
// once every few seconds.
lookupInterval
=
4
*
time
.
Second
)
// dialstate schedules dials and discovery lookups.
...
...
@@ -206,18 +205,19 @@ func (t *dialTask) String() string {
func
(
t
*
discoverTask
)
Do
(
srv
*
Server
)
{
if
t
.
bootstrap
{
srv
.
ntab
.
Bootstrap
(
srv
.
BootstrapNodes
)
}
else
{
var
target
discover
.
NodeID
rand
.
Read
(
target
[
:
])
t
.
results
=
srv
.
ntab
.
Lookup
(
target
)
// newTasks generates a lookup task whenever dynamic dials are
// necessary. Lookups need to take some time, otherwise the
// event loop spins too fast. An empty result can only be
// returned if the table is empty.
if
len
(
t
.
results
)
==
0
{
time
.
Sleep
(
emptyLookupDelay
)
}
return
}
// newTasks generates a lookup task whenever dynamic dials are
// necessary. Lookups need to take some time, otherwise the
// event loop spins too fast.
next
:=
srv
.
lastLookup
.
Add
(
lookupInterval
)
if
now
:=
time
.
Now
();
now
.
Before
(
next
)
{
time
.
Sleep
(
next
.
Sub
(
now
))
}
srv
.
lastLookup
=
time
.
Now
()
var
target
discover
.
NodeID
rand
.
Read
(
target
[
:
])
t
.
results
=
srv
.
ntab
.
Lookup
(
target
)
}
func
(
t
*
discoverTask
)
String
()
(
s
string
)
{
...
...
p2p/server.go
View file @
139439dc
...
...
@@ -115,6 +115,7 @@ type Server struct {
ntab
discoverTable
listener
net
.
Listener
ourHandshake
*
protoHandshake
lastLookup
time
.
Time
// These are for Peers, PeerCount (and nothing else).
peerOp
chan
peerOpFunc
...
...
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