mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-26 17:52:25 +01:00
htlcswitch/link: fail channel on lnwire.Error
This commit is contained in:
parent
f1f1a38663
commit
33762e0f81
@ -1319,7 +1319,21 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
l.fail("error receiving fee update: %v", err)
|
||||
return
|
||||
}
|
||||
case *lnwire.Error:
|
||||
// Error received from remote, MUST fail channel, but should
|
||||
// only print the contents of the error message if all
|
||||
// characters are printable ASCII.
|
||||
errMsg := "non-ascii data"
|
||||
if isASCII(msg.Data) {
|
||||
errMsg = string(msg.Data)
|
||||
}
|
||||
l.fail("ChannelPoint(%v): recieved error from peer: %v",
|
||||
l.channel.ChannelPoint(), errMsg)
|
||||
default:
|
||||
log.Warnf("ChannelPoint(%v): received unknown message of type %T",
|
||||
l.channel.ChannelPoint(), msg)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ackDownStreamPackets is responsible for removing htlcs from a link's
|
||||
@ -2407,3 +2421,16 @@ func (l *channelLink) tracef(format string, a ...interface{}) {
|
||||
msg := fmt.Sprintf(format, a...)
|
||||
log.Tracef("ChannelLink(%s) %s", l.ShortChanID(), msg)
|
||||
}
|
||||
|
||||
// isASCII is a helper method that checks whether all bytes in `data` would be
|
||||
// printable ASCII characters if interpreted as a string.
|
||||
func isASCII(data []byte) bool {
|
||||
isASCII := true
|
||||
for _, c := range data {
|
||||
if c < 32 || c > 126 {
|
||||
isASCII = false
|
||||
break
|
||||
}
|
||||
}
|
||||
return isASCII
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user