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