mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
Merge pull request #7842 from morehouse/refactor_handle_warning_error
peer: combine handleWarning and handleError
This commit is contained in:
commit
d46ee0bd74
1 changed files with 19 additions and 47 deletions
|
@ -1564,11 +1564,11 @@ out:
|
|||
|
||||
case *lnwire.Warning:
|
||||
targetChan = msg.ChanID
|
||||
isLinkUpdate = p.handleWarning(msg)
|
||||
isLinkUpdate = p.handleWarningOrError(targetChan, msg)
|
||||
|
||||
case *lnwire.Error:
|
||||
targetChan = msg.ChanID
|
||||
isLinkUpdate = p.handleError(msg)
|
||||
isLinkUpdate = p.handleWarningOrError(targetChan, msg)
|
||||
|
||||
case *lnwire.ChannelReestablish:
|
||||
targetChan = msg.ChanID
|
||||
|
@ -1741,65 +1741,37 @@ func (p *Brontide) storeError(err error) {
|
|||
)
|
||||
}
|
||||
|
||||
// handleWarning processes a warning message read from the remote peer. The
|
||||
// boolean return indicates whether the message should be delivered to a
|
||||
// targeted peer or not. The message gets stored in memory as an error if we
|
||||
// have open channels with the peer we received it from.
|
||||
// handleWarningOrError processes a warning or error msg and returns true if
|
||||
// msg should be forwarded to the associated channel link. False is returned if
|
||||
// any necessary forwarding of msg was already handled by this method. If msg is
|
||||
// an error from a peer with an active channel, we'll store it in memory.
|
||||
//
|
||||
// NOTE: This method should only be called from within the readHandler.
|
||||
func (p *Brontide) handleWarning(msg *lnwire.Warning) bool {
|
||||
switch {
|
||||
// Connection wide messages should be forward the warning to all the
|
||||
// channels with this peer.
|
||||
case msg.ChanID == lnwire.ConnectionWideID:
|
||||
for _, chanStream := range p.activeMsgStreams {
|
||||
chanStream.AddMsg(msg)
|
||||
}
|
||||
func (p *Brontide) handleWarningOrError(chanID lnwire.ChannelID,
|
||||
msg lnwire.Message) bool {
|
||||
|
||||
return false
|
||||
|
||||
// If the channel ID for the warning message corresponds to a pending
|
||||
// channel, then the funding manager will handle the warning.
|
||||
case p.cfg.FundingManager.IsPendingChannel(msg.ChanID, p):
|
||||
p.cfg.FundingManager.ProcessFundingMsg(msg, p)
|
||||
return false
|
||||
|
||||
// If not we hand the warning to the channel link for this channel.
|
||||
case p.isActiveChannel(msg.ChanID):
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
if errMsg, ok := msg.(*lnwire.Error); ok {
|
||||
p.storeError(errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
// handleError processes an error message read from the remote peer. The boolean
|
||||
// returns indicates whether the message should be delivered to a targeted peer.
|
||||
// It stores the error we received from the peer in memory if we have a channel
|
||||
// open with the peer.
|
||||
//
|
||||
// NOTE: This method should only be called from within the readHandler.
|
||||
func (p *Brontide) handleError(msg *lnwire.Error) bool {
|
||||
// Store the error we have received.
|
||||
p.storeError(msg)
|
||||
|
||||
switch {
|
||||
// In the case of an all-zero channel ID we want to forward the error to
|
||||
// all channels with this peer.
|
||||
case msg.ChanID == lnwire.ConnectionWideID:
|
||||
// Connection wide messages should be forwarded to all channel links
|
||||
// with this peer.
|
||||
case chanID == lnwire.ConnectionWideID:
|
||||
for _, chanStream := range p.activeMsgStreams {
|
||||
chanStream.AddMsg(msg)
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
// If the channel ID for the error message corresponds to a pending
|
||||
// channel, then the funding manager will handle the error.
|
||||
case p.cfg.FundingManager.IsPendingChannel(msg.ChanID, p):
|
||||
// If the channel ID for the message corresponds to a pending channel,
|
||||
// then the funding manager will handle it.
|
||||
case p.cfg.FundingManager.IsPendingChannel(chanID, p):
|
||||
p.cfg.FundingManager.ProcessFundingMsg(msg, p)
|
||||
return false
|
||||
|
||||
// If not we hand the error to the channel link for this channel.
|
||||
case p.isActiveChannel(msg.ChanID):
|
||||
// If not we hand the message to the channel link for this channel.
|
||||
case p.isActiveChannel(chanID):
|
||||
return true
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Reference in a new issue