htlcswitch: add hop iterator
Short: such abstraction give as ability to test the channel link in the future. Long: hop iterator represents the entity which is be able to give payment route hop by hop. This interface will be used to have an abstraction over the algorithm which we use to determine the next hope in htlc route and also helps the unit test to create mock representation of such algorithm which uses simple array of hops.
This commit is contained in:
parent
db30571efe
commit
de01721aed
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user