downloader: make sure that hashes are only accepted from the active peer

This commit is contained in:
obscuren
2015-04-18 17:35:03 +02:00
parent ff67fbf964
commit 60613b57d1
2 changed files with 54 additions and 20 deletions

View File

@@ -194,7 +194,10 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
if err := msgStream.Decode(&hashes); err != nil {
break
}
self.downloader.HashCh <- hashes
err := self.downloader.AddHashes(p.id, hashes)
if err != nil {
glog.V(logger.Debug).Infoln(err)
}
case GetBlocksMsg:
msgStream := rlp.NewStream(msg.Payload)
@@ -259,7 +262,11 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
// Make sure the block isn't already known. If this is the case simply drop
// the message and move on. If the TD is < currentTd; drop it as well. If this
// chain at some point becomes canonical, the downloader will fetch it.
if self.chainman.HasBlock(hash) && self.chainman.Td().Cmp(request.TD) > 0 {
if self.chainman.HasBlock(hash) {
break
}
if self.chainman.Td().Cmp(request.TD) > 0 {
glog.V(logger.Debug).Infoln("dropped block", request.Block.Number(), "due to low TD", request.TD)
break
}