htlcswitch: add ForwardingError constructor

Add a constructor for the creation of forwarding errors.
A special constructor is added for the case where we have
an unknown wire failure, and must set a nil failure message.
This commit is contained in:
carla committed 2020-01-14 15:07:29 +02:00
1 parent daa08be62a
commit 6f0a342f92
4 files changed
+89 -94

No files matched your search

+23 -7
View File
@@ -40,6 +40,27 @@ func (f *ForwardingError) Error() string {
)
}
// NewForwardingError creates a new payment error which wraps a wire error
// with additional metadata.
func NewForwardingError(failure lnwire.FailureMessage, index int,
extraMsg string) *ForwardingError {
return &ForwardingError{
FailureSourceIdx: index,
FailureMessage: failure,
ExtraMsg: extraMsg,
}
}
// NewUnknownForwardingError returns a forwarding error which has a nil failure
// message. This constructor should only be used in the case where we cannot
// decode the failure we have received from a peer.
func NewUnknownForwardingError(index int) *ForwardingError {
return &ForwardingError{
FailureSourceIdx: index,
}
}
// ErrorDecrypter is an interface that is used to decrypt the onion encrypted
// failure reason an extra out a well formed error.
type ErrorDecrypter interface {
@@ -94,15 +115,10 @@ func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (
r := bytes.NewReader(failure.Message)
failureMsg, err := lnwire.DecodeFailure(r, 0)
if err != nil {
return &ForwardingError{
FailureSourceIdx: failure.SenderIdx,
}, nil
return NewUnknownForwardingError(failure.SenderIdx), nil
}
return &ForwardingError{
FailureSourceIdx: failure.SenderIdx,
FailureMessage: failureMsg,
}, nil
return NewForwardingError(failureMsg, failure.SenderIdx, ""), nil
}
// A compile time check to ensure ErrorDecrypter implements the Deobfuscator