2017-05-01 16:46:53 +02:00
|
|
|
package htlcswitch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/hex"
|
2017-05-02 21:01:46 +02:00
|
|
|
"io"
|
2017-05-01 16:46:53 +02:00
|
|
|
|
|
|
|
"github.com/btcsuite/golangcrypto/ripemd160"
|
|
|
|
"github.com/roasbeef/btcutil"
|
|
|
|
)
|
|
|
|
|
2017-05-01 18:58:08 +02:00
|
|
|
// HopID represents the id which is used by propagation subsystem in order to
|
2017-05-01 16:46:53 +02:00
|
|
|
// identify lightning network node.
|
|
|
|
// TODO(andrew.shvv) remove after switching to the using channel id.
|
2017-05-01 18:58:08 +02:00
|
|
|
type HopID [ripemd160.Size]byte
|
2017-05-01 16:46:53 +02:00
|
|
|
|
2017-05-01 18:58:08 +02:00
|
|
|
// NewHopID creates new instance of hop form node public key.
|
|
|
|
func NewHopID(pubKey []byte) HopID {
|
|
|
|
var routeID HopID
|
|
|
|
copy(routeID[:], btcutil.Hash160(pubKey))
|
|
|
|
return routeID
|
2017-05-01 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// String returns string representation of hop id.
|
2017-05-01 18:58:08 +02:00
|
|
|
func (h HopID) String() string {
|
2017-05-01 16:46:53 +02:00
|
|
|
return hex.EncodeToString(h[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsEqual checks does the two hop ids are equal.
|
2017-05-01 18:58:08 +02:00
|
|
|
func (h HopID) IsEqual(h2 HopID) bool {
|
2017-05-01 16:46:53 +02:00
|
|
|
return bytes.Equal(h[:], h2[:])
|
|
|
|
}
|
2017-05-02 21:01:46 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|