diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-13 18:46:29 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-13 18:46:29 +0800 |
commit | 7cb0e242450fd15c6ee8f5d70af41504a047e0aa (patch) | |
tree | 78a0226189f77ff05f73b773dbdcfd0a8e077d72 /eth/downloader/downloader.go | |
parent | 6dec90464dc2a263a5bcb72fdbff6c5439fb07dc (diff) | |
parent | d2d5dbc6fbdb613a0c5b1967ee82a74cd94739a3 (diff) | |
download | go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.tar go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.tar.gz go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.tar.bz2 go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.tar.lz go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.tar.xz go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.tar.zst go-tangerine-7cb0e242450fd15c6ee8f5d70af41504a047e0aa.zip |
Merge pull request #948 from karalabe/fix-downlaoder-activepeer-shadow
eth/downloader: fix active peer shadowing, polish func names
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r-- | eth/downloader/downloader.go | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 577152a21..c6eecfe2f 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -55,10 +55,9 @@ type hashPack struct { } type Downloader struct { - mu sync.RWMutex - queue *queue - peers *peerSet - activePeer string + mu sync.RWMutex + queue *queue + peers *peerSet // Callbacks hasBlock hashCheckFn @@ -162,7 +161,6 @@ func (d *Downloader) Has(hash common.Hash) bool { // syncWithPeer starts a block synchronization based on the hash chain from the // specified peer and head hash. func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) { - d.activePeer = p.id defer func() { // reset on error if err != nil { @@ -416,32 +414,26 @@ out: return nil } -// Deliver a chunk to the downloader. This is usually done through the BlocksMsg by -// the protocol handler. -func (d *Downloader) DeliverChunk(id string, blocks []*types.Block) error { +// DeliverBlocks injects a new batch of blocks received from a remote node. +// This is usually invoked through the BlocksMsg by the protocol handler. +func (d *Downloader) DeliverBlocks(id string, blocks []*types.Block) error { // Make sure the downloader is active if atomic.LoadInt32(&d.synchronising) == 0 { return errNoSyncActive } - d.blockCh <- blockPack{id, blocks} return nil } -func (d *Downloader) AddHashes(id string, hashes []common.Hash) error { +// DeliverHashes injects a new batch of hashes received from a remote node into +// the download schedule. This is usually invoked through the BlockHashesMsg by +// the protocol handler. +func (d *Downloader) DeliverHashes(id string, hashes []common.Hash) error { // Make sure the downloader is active if atomic.LoadInt32(&d.synchronising) == 0 { return errNoSyncActive } - - // make sure that the hashes that are being added are actually from the peer - // that's the current active peer. hashes that have been received from other - // peers are dropped and ignored. - if d.activePeer != id { - return fmt.Errorf("received hashes from %s while active peer is %s", id, d.activePeer) - } - if glog.V(logger.Debug) && len(hashes) != 0 { from, to := hashes[0], hashes[len(hashes)-1] glog.V(logger.Debug).Infof("adding %d (T=%d) hashes [ %x / %x ] from: %s\n", len(hashes), d.queue.Pending(), from[:4], to[:4], id) |