peer: add error chan to queueMsg

This commit is contained in:
Johan T. Halseth 2017-11-15 18:23:46 -08:00 committed by Olaoluwa Osuntokun
parent c36b1c3992
commit 25b77a0aee

21
peer.go

@ -48,8 +48,8 @@ const (
// a buffered channel which will be sent upon once the write is complete. This // a buffered channel which will be sent upon once the write is complete. This
// buffered channel acts as a semaphore to be used for synchronization purposes. // buffered channel acts as a semaphore to be used for synchronization purposes.
type outgoinMsg struct { type outgoinMsg struct {
msg lnwire.Message msg lnwire.Message
sentChan chan struct{} // MUST be buffered. errChan chan error // MUST be buffered.
} }
// newChannelMsg packages a lnwallet.LightningChannel with a channel that // newChannelMsg packages a lnwallet.LightningChannel with a channel that
@ -1027,8 +1027,8 @@ out:
// callers to optionally synchronize sends with the // callers to optionally synchronize sends with the
// writeHandler. // writeHandler.
err := p.writeMessage(outMsg.msg) err := p.writeMessage(outMsg.msg)
if outMsg.sentChan != nil { if outMsg.errChan != nil {
close(outMsg.sentChan) outMsg.errChan <- err
} }
if err != nil { if err != nil {
@ -1122,12 +1122,17 @@ func (p *peer) PingTime() int64 {
} }
// queueMsg queues a new lnwire.Message to be eventually sent out on the // queueMsg queues a new lnwire.Message to be eventually sent out on the
// wire. // wire. It returns an error if we failed to queue the message. An error
func (p *peer) queueMsg(msg lnwire.Message, doneChan chan struct{}) { // is sent on errChan if the message fails being sent to the peer, or
// nil otherwise.
func (p *peer) queueMsg(msg lnwire.Message, errChan chan error) {
select { select {
case p.outgoingQueue <- outgoinMsg{msg, doneChan}: case p.outgoingQueue <- outgoinMsg{msg, errChan}:
case <-p.quit: case <-p.quit:
return peerLog.Debugf("Peer shutting down, could not enqueue msg.")
if errChan != nil {
errChan <- fmt.Errorf("peer shutting down")
}
} }
} }