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.
This commit is contained in:
parent
23d10336c2
commit
ca358e9673
8
lnpeer/errors.go
Normal file
8
lnpeer/errors.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package lnpeer
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrPeerExiting signals that the peer received a disconnect request.
|
||||||
|
ErrPeerExiting = fmt.Errorf("peer exiting")
|
||||||
|
)
|
15
peer.go
15
peer.go
@ -32,9 +32,6 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
numNodes int32
|
numNodes int32
|
||||||
|
|
||||||
// ErrPeerExiting signals that the peer received a disconnect request.
|
|
||||||
ErrPeerExiting = fmt.Errorf("peer exiting")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -1411,7 +1408,7 @@ func (p *peer) logWireMessage(msg lnwire.Message, read bool) {
|
|||||||
func (p *peer) writeMessage(msg lnwire.Message) error {
|
func (p *peer) writeMessage(msg lnwire.Message) error {
|
||||||
// Simply exit if we're shutting down.
|
// Simply exit if we're shutting down.
|
||||||
if atomic.LoadInt32(&p.disconnect) != 0 {
|
if atomic.LoadInt32(&p.disconnect) != 0 {
|
||||||
return ErrPeerExiting
|
return lnpeer.ErrPeerExiting
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only log the message on the first attempt.
|
// Only log the message on the first attempt.
|
||||||
@ -1559,7 +1556,7 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
exitErr = ErrPeerExiting
|
exitErr = lnpeer.ErrPeerExiting
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1691,7 +1688,7 @@ func (p *peer) queue(priority bool, msg lnwire.Message, errChan chan error) {
|
|||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
peerLog.Tracef("Peer shutting down, could not enqueue msg.")
|
peerLog.Tracef("Peer shutting down, could not enqueue msg.")
|
||||||
if errChan != nil {
|
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:
|
case err := <-errChan:
|
||||||
return err
|
return err
|
||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
return ErrPeerExiting
|
return lnpeer.ErrPeerExiting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2550,7 +2547,7 @@ func (p *peer) AddNewChannel(channel *channeldb.OpenChannel,
|
|||||||
case <-cancel:
|
case <-cancel:
|
||||||
return errors.New("canceled adding new channel")
|
return errors.New("canceled adding new channel")
|
||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
return ErrPeerExiting
|
return lnpeer.ErrPeerExiting
|
||||||
}
|
}
|
||||||
|
|
||||||
// We pause here to wait for the peer to recognize the new channel
|
// 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:
|
case err := <-errChan:
|
||||||
return err
|
return err
|
||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
return ErrPeerExiting
|
return lnpeer.ErrPeerExiting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user