htlcswitch+routing: make error decryption mockable

This commit is contained in:
Joost Jager 2019-06-19 15:04:17 +02:00
parent 2b47632b26
commit 0cdae56d28
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

View File

@ -244,10 +244,21 @@ func (s *SphinxErrorEncrypter) Reextract(
// ErrorEncrypter interface.
var _ ErrorEncrypter = (*SphinxErrorEncrypter)(nil)
// OnionErrorDecrypter is the interface that provides onion level error
// decryption.
type OnionErrorDecrypter interface {
// DecryptError attempts to decrypt the passed encrypted error response.
// The onion failure is encrypted in backward manner, starting from the
// node where error have occurred. As a result, in order to decrypt the
// error we need get all shared secret and apply decryption in the
// reverse order.
DecryptError(encryptedData []byte) (*sphinx.DecryptedError, error)
}
// SphinxErrorDecrypter wraps the sphinx data SphinxErrorDecrypter and maps the
// returned errors to concrete lnwire.FailureMessage instances.
type SphinxErrorDecrypter struct {
*sphinx.OnionErrorDecrypter
OnionErrorDecrypter
}
// DecryptError peels off each layer of onion encryption from the first hop, to
@ -255,7 +266,8 @@ type SphinxErrorDecrypter struct {
// along with the source of the error.
//
// NOTE: Part of the ErrorDecrypter interface.
func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (*ForwardingError, error) {
func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (
*ForwardingError, error) {
failure, err := s.OnionErrorDecrypter.DecryptError(reason)
if err != nil {