From ca358e9673b86ca04b53433e69d63305b0bb85d4 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 26 Apr 2019 17:31:27 -0700 Subject: [PATCH] lnpeer+peer: use importable lnpeer.ErrPeerExiting As a prepatory step to making gossip replies synchronous, we will move the ErrPeerExiting error into the lnpeer package so that it can be imported by the discovery package. With synchronous sends, this error can now be detected and handled by goroutines in the syncer, and cause them to exit instead of continue to sending backlogs. --- lnpeer/errors.go | 8 ++++++++ peer.go | 15 ++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 lnpeer/errors.go diff --git a/lnpeer/errors.go b/lnpeer/errors.go new file mode 100644 index 00000000..3787afe3 --- /dev/null +++ b/lnpeer/errors.go @@ -0,0 +1,8 @@ +package lnpeer + +import "fmt" + +var ( + // ErrPeerExiting signals that the peer received a disconnect request. + ErrPeerExiting = fmt.Errorf("peer exiting") +) diff --git a/peer.go b/peer.go index 0e79088f..71b06fc4 100644 --- a/peer.go +++ b/peer.go @@ -32,9 +32,6 @@ import ( var ( numNodes int32 - - // ErrPeerExiting signals that the peer received a disconnect request. - ErrPeerExiting = fmt.Errorf("peer exiting") ) const ( @@ -1411,7 +1408,7 @@ func (p *peer) logWireMessage(msg lnwire.Message, read bool) { func (p *peer) writeMessage(msg lnwire.Message) error { // Simply exit if we're shutting down. if atomic.LoadInt32(&p.disconnect) != 0 { - return ErrPeerExiting + return lnpeer.ErrPeerExiting } // Only log the message on the first attempt. @@ -1559,7 +1556,7 @@ out: } case <-p.quit: - exitErr = ErrPeerExiting + exitErr = lnpeer.ErrPeerExiting break out } } @@ -1691,7 +1688,7 @@ func (p *peer) queue(priority bool, msg lnwire.Message, errChan chan error) { case <-p.quit: peerLog.Tracef("Peer shutting down, could not enqueue msg.") if errChan != nil { - errChan <- ErrPeerExiting + errChan <- lnpeer.ErrPeerExiting } } } @@ -2504,7 +2501,7 @@ func (p *peer) sendMessage(sync, priority bool, msgs ...lnwire.Message) error { case err := <-errChan: return err case <-p.quit: - return ErrPeerExiting + return lnpeer.ErrPeerExiting } } @@ -2550,7 +2547,7 @@ func (p *peer) AddNewChannel(channel *channeldb.OpenChannel, case <-cancel: return errors.New("canceled adding new channel") case <-p.quit: - return ErrPeerExiting + return lnpeer.ErrPeerExiting } // We pause here to wait for the peer to recognize the new channel @@ -2559,7 +2556,7 @@ func (p *peer) AddNewChannel(channel *channeldb.OpenChannel, case err := <-errChan: return err case <-p.quit: - return ErrPeerExiting + return lnpeer.ErrPeerExiting } }