lnwire: add cancellation reason to htlc cancel messages

This commit adds a new field to the CancelHTLC message which describes
the event that led to an HTLC being cancelled up stream.

A new enum has been added which describers the “why” concerning the
cancellation of the HTLC. Currently the encoding and back propagation
of the errors aren’t properly implemented as defined within the spec.
As a result the current error types provide to privacy as the error are
in plain-site rather doing being properly encrypted.
This commit is contained in:
Olaoluwa Osuntokun committed 2017-01-07 21:20:54 -08:00
1 parent fd0c0574e6
commit d079c88702
3 files changed
+82 -4

No files matched your search

+12
View File
@@ -88,6 +88,12 @@ func writeElement(w io.Writer, element interface{}) error {
if _, err := w.Write(b[:]); err != nil {
return err
}
case CancelReason:
var b [2]byte
binary.BigEndian.PutUint16(b[:], uint16(e))
if _, err := w.Write(b[:]); err != nil {
return err
}
case ErrorCode:
var b [2]byte
binary.BigEndian.PutUint16(b[:], uint16(e))
@@ -384,6 +390,12 @@ func readElement(r io.Reader, element interface{}) error {
return err
}
*e = b[0]
case *CancelReason:
var b [2]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
}
*e = CancelReason(binary.BigEndian.Uint16(b[:]))
case *uint16:
var b [2]byte
if _, err := io.ReadFull(r, b[:]); err != nil {