From 75bb52d7158b0ee697c34d2977a9b95f552c0a9f Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 21 Apr 2014 14:52:02 -0400 Subject: [PATCH] In handleGetDataMsg, fix two unknown inv type bugs. On unknown inventory types, handleGetDataMsg would loop forever. After fixing that, if a getdata request only had unknown inventory types, it would block forever. ok @davecgh --- peer.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/peer.go b/peer.go index 6d27cd5a..5a5e2e16 100644 --- a/peer.go +++ b/peer.go @@ -624,6 +624,7 @@ func (p *peer) handleHeadersMsg(msg *btcwire.MsgHeaders) { // handleGetData is invoked when a peer receives a getdata bitcoin message and // is used to deliver block and transaction information. func (p *peer) handleGetDataMsg(msg *btcwire.MsgGetData) { + numAdded := 0 notFound := btcwire.NewMsgNotFound() // We wait on the this wait channel periodically to prevent queueing @@ -632,7 +633,7 @@ func (p *peer) handleGetDataMsg(msg *btcwire.MsgGetData) { // provide a little pipelining. var waitChan chan bool doneChan := make(chan bool) -out: + for i, iv := range msg.InvList { var c chan bool // If this will be the last message we send. @@ -651,11 +652,12 @@ out: default: peerLog.Warnf("Unknown type in inventory request %d", iv.Type) - break out + continue } if err != nil { notFound.AddInvVect(iv) } + numAdded++ waitChan = c } if len(notFound.InvList) != 0 { @@ -667,7 +669,9 @@ out: // We don't process anything else by them in this time so that we // have an idea of when we should hear back from them - else the idle // timeout could fire when we were only half done sending the blocks. - <-doneChan + if numAdded > 0 { + <-doneChan + } } // handleGetBlocksMsg is invoked when a peer receives a getdata bitcoin message.