Disconnect misbehaving peers who send unsolicited blocks.

This commit is contained in:
Owain G. Ainsworth 2013-10-01 21:32:50 +01:00
parent 030c610211
commit 7eb1a5ce4e

View file

@ -213,6 +213,14 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
// Keep track of which peer the block was sent from so the notification // Keep track of which peer the block was sent from so the notification
// handler can request the parent blocks from the appropriate peer. // handler can request the parent blocks from the appropriate peer.
blockSha, _ := bmsg.block.Sha() blockSha, _ := bmsg.block.Sha()
// If we didnt' ask for this block then the peer is misbehaving.
if _, ok := bmsg.peer.requestedBlocks[*blockSha]; !ok {
log.Warnf("[BMGR] Got unreqeusted block from %s, disconnecting",
bmsg.peer.addr)
bmsg.peer.Disconnect()
return
}
b.blockPeerMutex.Lock() b.blockPeerMutex.Lock()
b.blockPeer[*blockSha] = bmsg.peer b.blockPeer[*blockSha] = bmsg.peer
b.blockPeerMutex.Unlock() b.blockPeerMutex.Unlock()