diff --git a/htlcswitch/iterator.go b/htlcswitch/iterator.go index 833aaff63..9387df6f8 100644 --- a/htlcswitch/iterator.go +++ b/htlcswitch/iterator.go @@ -3,6 +3,7 @@ package htlcswitch import ( "bytes" "encoding/hex" + "io" "github.com/btcsuite/golangcrypto/ripemd160" "github.com/roasbeef/btcutil" @@ -29,3 +30,14 @@ func (h HopID) String() string { func (h HopID) IsEqual(h2 HopID) bool { return bytes.Equal(h[:], h2[:]) } + +// HopIterator interface represent the entity which is able to give route +// hops one by one. This interface is used to have an abstraction over the +// algorithm which we use to determine the next hope in htlc route. +type HopIterator interface { + // Next returns next hop if exist and nil if route is ended. + Next() *HopID + + // Encode encodes iterator and writes it to the writer. + Encode(w io.Writer) error +} diff --git a/htlcswitch/link.go b/htlcswitch/link.go index aee12639b..e37edc054 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -7,6 +7,8 @@ import ( "sync/atomic" "time" + "io" + "github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnwallet" @@ -26,6 +28,10 @@ type ChannelLinkConfig struct { // packets to other peer which should handle it. Switch *Switch + // DecodeOnion function responsible for decoding htlc Sphinx onion blob, + // and creating hop iterator which will give us next destination of htlc. + DecodeOnion func(r io.Reader, meta []byte) (HopIterator, error) + // Peer is a lightning network node with which we have the channel // link opened. Peer Peer