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
8f0a4a25
Commit
8f0a4a25
authored
Jul 26, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: abort sync if master drops (timeout prev)
parent
a724952f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
2 deletions
+15
-2
downloader.go
eth/downloader/downloader.go
+15
-2
No files found.
eth/downloader/downloader.go
View file @
8f0a4a25
...
@@ -147,8 +147,10 @@ type Downloader struct {
...
@@ -147,8 +147,10 @@ type Downloader struct {
stateWakeCh
chan
bool
// [eth/63] Channel to signal the state fetcher of new tasks
stateWakeCh
chan
bool
// [eth/63] Channel to signal the state fetcher of new tasks
headerProcCh
chan
[]
*
types
.
Header
// [eth/62] Channel to feed the header processor new tasks
headerProcCh
chan
[]
*
types
.
Header
// [eth/62] Channel to feed the header processor new tasks
// Cancellation and termination
cancelPeer
string
// Identifier of the peer currently being used as the master (cancel on drop)
cancelCh
chan
struct
{}
// Channel to cancel mid-flight syncs
cancelCh
chan
struct
{}
// Channel to cancel mid-flight syncs
cancelLock
sync
.
RWMutex
// Lock to protect the cancel channel in delivers
cancelLock
sync
.
RWMutex
// Lock to protect the cancel channel
and peer
in delivers
quitCh
chan
struct
{}
// Quit channel to signal termination
quitCh
chan
struct
{}
// Quit channel to signal termination
quitLock
sync
.
RWMutex
// Lock to prevent double closes
quitLock
sync
.
RWMutex
// Lock to prevent double closes
...
@@ -254,12 +256,22 @@ func (d *Downloader) RegisterPeer(id string, version int, head common.Hash,
...
@@ -254,12 +256,22 @@ func (d *Downloader) RegisterPeer(id string, version int, head common.Hash,
// the specified peer. An effort is also made to return any pending fetches into
// the specified peer. An effort is also made to return any pending fetches into
// the queue.
// the queue.
func
(
d
*
Downloader
)
UnregisterPeer
(
id
string
)
error
{
func
(
d
*
Downloader
)
UnregisterPeer
(
id
string
)
error
{
// Unregister the peer from the active peer set and revoke any fetch tasks
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"Unregistering peer"
,
id
)
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"Unregistering peer"
,
id
)
if
err
:=
d
.
peers
.
Unregister
(
id
);
err
!=
nil
{
if
err
:=
d
.
peers
.
Unregister
(
id
);
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Unregister failed:"
,
err
)
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Unregister failed:"
,
err
)
return
err
return
err
}
}
d
.
queue
.
Revoke
(
id
)
d
.
queue
.
Revoke
(
id
)
// If this peer was the master peer, abort sync immediately
d
.
cancelLock
.
RLock
()
master
:=
id
==
d
.
cancelPeer
d
.
cancelLock
.
RUnlock
()
if
master
{
d
.
cancel
()
}
return
nil
return
nil
}
}
...
@@ -332,9 +344,10 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
...
@@ -332,9 +344,10 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
empty
=
true
empty
=
true
}
}
}
}
// Create cancel channel for aborting mid-flight
// Create cancel channel for aborting mid-flight
and mark the master peer
d
.
cancelLock
.
Lock
()
d
.
cancelLock
.
Lock
()
d
.
cancelCh
=
make
(
chan
struct
{})
d
.
cancelCh
=
make
(
chan
struct
{})
d
.
cancelPeer
=
id
d
.
cancelLock
.
Unlock
()
d
.
cancelLock
.
Unlock
()
defer
d
.
cancel
()
// No matter what, we can't leave the cancel channel open
defer
d
.
cancel
()
// No matter what, we can't leave the cancel channel open
...
...
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