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
This commit is contained in:
parent
f88db561f1
commit
75bb52d715
1 changed files with 7 additions and 3 deletions
10
peer.go
10
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
|
// handleGetData is invoked when a peer receives a getdata bitcoin message and
|
||||||
// is used to deliver block and transaction information.
|
// is used to deliver block and transaction information.
|
||||||
func (p *peer) handleGetDataMsg(msg *btcwire.MsgGetData) {
|
func (p *peer) handleGetDataMsg(msg *btcwire.MsgGetData) {
|
||||||
|
numAdded := 0
|
||||||
notFound := btcwire.NewMsgNotFound()
|
notFound := btcwire.NewMsgNotFound()
|
||||||
|
|
||||||
// We wait on the this wait channel periodically to prevent queueing
|
// 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.
|
// provide a little pipelining.
|
||||||
var waitChan chan bool
|
var waitChan chan bool
|
||||||
doneChan := make(chan bool)
|
doneChan := make(chan bool)
|
||||||
out:
|
|
||||||
for i, iv := range msg.InvList {
|
for i, iv := range msg.InvList {
|
||||||
var c chan bool
|
var c chan bool
|
||||||
// If this will be the last message we send.
|
// If this will be the last message we send.
|
||||||
|
@ -651,11 +652,12 @@ out:
|
||||||
default:
|
default:
|
||||||
peerLog.Warnf("Unknown type in inventory request %d",
|
peerLog.Warnf("Unknown type in inventory request %d",
|
||||||
iv.Type)
|
iv.Type)
|
||||||
break out
|
continue
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notFound.AddInvVect(iv)
|
notFound.AddInvVect(iv)
|
||||||
}
|
}
|
||||||
|
numAdded++
|
||||||
waitChan = c
|
waitChan = c
|
||||||
}
|
}
|
||||||
if len(notFound.InvList) != 0 {
|
if len(notFound.InvList) != 0 {
|
||||||
|
@ -667,7 +669,9 @@ out:
|
||||||
// We don't process anything else by them in this time so that we
|
// 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
|
// 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.
|
// 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.
|
// handleGetBlocksMsg is invoked when a peer receives a getdata bitcoin message.
|
||||||
|
|
Loading…
Add table
Reference in a new issue