From 7eb1a5ce4eea7042766ff1c578394ba1d5f20599 Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Tue, 1 Oct 2013 21:32:50 +0100 Subject: [PATCH] Disconnect misbehaving peers who send unsolicited blocks. --- blockmanager.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/blockmanager.go b/blockmanager.go index cbc0cb38..548d9fa1 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -213,6 +213,14 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) { // Keep track of which peer the block was sent from so the notification // handler can request the parent blocks from the appropriate peer. 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.blockPeer[*blockSha] = bmsg.peer b.blockPeerMutex.Unlock()