eth/downloader: use isMaster function

This commit is contained in:
rjl493456442 2019-09-25 18:54:22 +08:00
parent bdc80c155b
commit 8f3c160a80

View file

@ -314,12 +314,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
} }
d.queue.Revoke(id) d.queue.Revoke(id)
// If this peer was the master peer, abort sync immediately if d.isMaster(id) {
d.cancelLock.RLock()
master := id == d.cancelPeer
d.cancelLock.RUnlock()
if master {
d.cancel() d.cancel()
} }
return nil return nil
@ -562,8 +557,8 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
// isMaster returns an indicator whether the given peer id is master peer // isMaster returns an indicator whether the given peer id is master peer
// used for syncing. // used for syncing.
func (d *Downloader) isMaster(id string) bool { func (d *Downloader) isMaster(id string) bool {
d.cancelLock.Lock() d.cancelLock.RLock()
defer d.cancelLock.Unlock() defer d.cancelLock.RUnlock()
return d.cancelPeer == id return d.cancelPeer == id
} }