peer: pendingMsgs is a FIFO
This commit is contained in:
parent
699c0ad23f
commit
213be705bc
27
peer/peer.go
27
peer/peer.go
@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2013-2016 The btcsuite developers
|
||||
// Copyright (c) 2016-2018 The Decred developers
|
||||
// Copyright (c) 2016-2019 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@ -7,7 +7,6 @@ package peer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -1471,7 +1470,7 @@ out:
|
||||
// handlers will not block on us sending a message. That data is then passed on
|
||||
// to outHandler to be actually written.
|
||||
func (p *Peer) queueHandler() {
|
||||
pendingMsgs := list.New()
|
||||
var pendingMsgs []outMsg
|
||||
var invSendQueue []*wire.InvVect
|
||||
trickleTicker := time.NewTicker(trickleTimeout)
|
||||
defer trickleTicker.Stop()
|
||||
@ -1486,11 +1485,11 @@ func (p *Peer) queueHandler() {
|
||||
waiting := false
|
||||
|
||||
// To avoid duplication below.
|
||||
queuePacket := func(msg outMsg, list *list.List, waiting bool) bool {
|
||||
queuePacket := func(msg outMsg, list *[]outMsg, waiting bool) bool {
|
||||
if !waiting {
|
||||
p.sendQueue <- msg
|
||||
} else {
|
||||
list.PushBack(msg)
|
||||
*list = append(*list, msg)
|
||||
}
|
||||
// we are always waiting now.
|
||||
return true
|
||||
@ -1499,23 +1498,23 @@ out:
|
||||
for {
|
||||
select {
|
||||
case msg := <-p.outputQueue:
|
||||
waiting = queuePacket(msg, pendingMsgs, waiting)
|
||||
waiting = queuePacket(msg, &pendingMsgs, waiting)
|
||||
|
||||
// This channel is notified when a message has been sent across
|
||||
// the network socket.
|
||||
case <-p.sendDoneQueue:
|
||||
// No longer waiting if there are no more messages
|
||||
// in the pending messages queue.
|
||||
next := pendingMsgs.Front()
|
||||
if next == nil {
|
||||
if len(pendingMsgs) == 0 {
|
||||
waiting = false
|
||||
continue
|
||||
}
|
||||
|
||||
// Notify the outHandler about the next item to
|
||||
// asynchronously send.
|
||||
val := pendingMsgs.Remove(next)
|
||||
p.sendQueue <- val.(outMsg)
|
||||
next := pendingMsgs[0]
|
||||
pendingMsgs = pendingMsgs[1:]
|
||||
p.sendQueue <- next
|
||||
|
||||
case iv := <-p.outputInvChan:
|
||||
// No handshake? They'll find out soon enough.
|
||||
@ -1547,7 +1546,7 @@ out:
|
||||
if len(invMsg.InvList) >= maxInvTrickleSize {
|
||||
waiting = queuePacket(
|
||||
outMsg{msg: invMsg},
|
||||
pendingMsgs, waiting)
|
||||
&pendingMsgs, waiting)
|
||||
invMsg = wire.NewMsgInvSizeHint(uint(len(invSendQueue)))
|
||||
}
|
||||
|
||||
@ -1557,7 +1556,7 @@ out:
|
||||
}
|
||||
if len(invMsg.InvList) > 0 {
|
||||
waiting = queuePacket(outMsg{msg: invMsg},
|
||||
pendingMsgs, waiting)
|
||||
&pendingMsgs, waiting)
|
||||
}
|
||||
invSendQueue = nil
|
||||
|
||||
@ -1568,9 +1567,7 @@ out:
|
||||
|
||||
// Drain any wait channels before we go away so we don't leave something
|
||||
// waiting for us.
|
||||
for e := pendingMsgs.Front(); e != nil; e = pendingMsgs.Front() {
|
||||
val := pendingMsgs.Remove(e)
|
||||
msg := val.(outMsg)
|
||||
for _, msg := range pendingMsgs {
|
||||
if msg.doneChan != nil {
|
||||
msg.doneChan <- struct{}{}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user