htlcswitch/link: fail channel on lnwire.Error

This commit is contained in:
Johan T. Halseth 2018-03-01 00:39:26 +01:00
parent f1f1a38663
commit 33762e0f81
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -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
}