Skip to content

Commit

Permalink
lnpeer+peer: use importable lnpeer.ErrPeerExiting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cfromknecht committed Apr 27, 2019
1 parent 23d1033 commit ca358e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 8 additions & 0 deletions lnpeer/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package lnpeer

import "fmt"

var (
// ErrPeerExiting signals that the peer received a disconnect request.
ErrPeerExiting = fmt.Errorf("peer exiting")
)
15 changes: 6 additions & 9 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ import (

var (
numNodes int32

// ErrPeerExiting signals that the peer received a disconnect request.
ErrPeerExiting = fmt.Errorf("peer exiting")
)

const (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1559,7 +1556,7 @@ out:
}

case <-p.quit:
exitErr = ErrPeerExiting
exitErr = lnpeer.ErrPeerExiting
break out
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand All @@ -2559,7 +2556,7 @@ func (p *peer) AddNewChannel(channel *channeldb.OpenChannel,
case err := <-errChan:
return err
case <-p.quit:
return ErrPeerExiting
return lnpeer.ErrPeerExiting
}
}

Expand Down

0 comments on commit ca358e9

Please sign in to comment.