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
8dc3048f
Commit
8dc3048f
authored
Jun 09, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: fix hash fetch timeout handling
Fixes #1206
parent
3239aca6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
downloader.go
eth/downloader/downloader.go
+18
-12
No files found.
eth/downloader/downloader.go
View file @
8dc3048f
...
@@ -263,23 +263,29 @@ func (d *Downloader) Cancel() bool {
...
@@ -263,23 +263,29 @@ func (d *Downloader) Cancel() bool {
// XXX Make synchronous
// XXX Make synchronous
func
(
d
*
Downloader
)
fetchHashes
(
p
*
peer
,
h
common
.
Hash
)
error
{
func
(
d
*
Downloader
)
fetchHashes
(
p
*
peer
,
h
common
.
Hash
)
error
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Downloading hashes (%x) from %s"
,
h
[
:
4
],
p
.
id
)
start
:=
time
.
Now
()
// Add the hash to the queue first, and start hash retrieval
d
.
queue
.
Insert
([]
common
.
Hash
{
h
})
p
.
getHashes
(
h
)
var
(
var
(
start
=
time
.
Now
()
active
=
p
// active peer will help determine the current active peer
active
=
p
// active peer will help determine the current active peer
head
=
common
.
Hash
{}
// common and last hash
head
=
common
.
Hash
{}
// common and last hash
timeout
=
time
.
NewTimer
(
hashTTL
)
// timer to dump a non-responsive active peer
timeout
=
time
.
NewTimer
(
0
)
// timer to dump a non-responsive active peer
attempted
=
make
(
map
[
string
]
bool
)
// attempted peers will help with retries
attempted
=
make
(
map
[
string
]
bool
)
// attempted peers will help with retries
crossTicker
=
time
.
NewTicker
(
crossCheckCycle
)
// ticker to periodically check expired cross checks
crossTicker
=
time
.
NewTicker
(
crossCheckCycle
)
// ticker to periodically check expired cross checks
)
)
defer
crossTicker
.
Stop
()
defer
crossTicker
.
Stop
()
defer
timeout
.
Stop
()
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Downloading hashes (%x) from %s"
,
h
[
:
4
],
p
.
id
)
<-
timeout
.
C
// timeout channel should be initially empty.
getHashes
:=
func
(
from
common
.
Hash
)
{
active
.
getHashes
(
from
)
timeout
.
Reset
(
hashTTL
)
}
// Add the hash to the queue, and start hash retrieval.
d
.
queue
.
Insert
([]
common
.
Hash
{
h
})
getHashes
(
h
)
attempted
[
p
.
id
]
=
true
attempted
[
p
.
id
]
=
true
for
finished
:=
false
;
!
finished
;
{
for
finished
:=
false
;
!
finished
;
{
...
@@ -293,7 +299,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
...
@@ -293,7 +299,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Received hashes from incorrect peer(%s)"
,
hashPack
.
peerId
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Received hashes from incorrect peer(%s)"
,
hashPack
.
peerId
)
break
break
}
}
timeout
.
Reset
(
hashTTL
)
timeout
.
Stop
(
)
// Make sure the peer actually gave something valid
// Make sure the peer actually gave something valid
if
len
(
hashPack
.
hashes
)
==
0
{
if
len
(
hashPack
.
hashes
)
==
0
{
...
@@ -345,7 +351,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
...
@@ -345,7 +351,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
active
.
getBlocks
([]
common
.
Hash
{
origin
})
active
.
getBlocks
([]
common
.
Hash
{
origin
})
// Also fetch a fresh
// Also fetch a fresh
active
.
getHashes
(
head
)
getHashes
(
head
)
continue
continue
}
}
// We're done, prepare the download cache and proceed pulling the blocks
// We're done, prepare the download cache and proceed pulling the blocks
...
@@ -399,7 +405,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
...
@@ -399,7 +405,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
// set p to the active peer. this will invalidate any hashes that may be returned
// set p to the active peer. this will invalidate any hashes that may be returned
// by our previous (delayed) peer.
// by our previous (delayed) peer.
active
=
p
active
=
p
p
.
getHashes
(
head
)
getHashes
(
head
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Hash fetching switched to new peer(%s)"
,
p
.
id
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Hash fetching switched to new peer(%s)"
,
p
.
id
)
}
}
}
}
...
...
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