htlcswitch: recreate hlcswitch from scratch

This commit gives the start for making the htlc manager and htlc switch
testable. The testability of htlc switch have been achieved by mocking
all external subsystems. The concrete list of updates:

1. create standalone package for htlc switch.
2. add "ChannelLink" interface, which represent the previous htlc link.
3. add "Peer" interface, which represent the remote node inside our
subsystem.
4. add htlc switch config to htlc switch susbystem, which stores the
handlers which are not elongs to any of the above interfaces.

With this commit we are able test htlc switch even without having
the concrete implementation of Peer, ChannelLink structures, they will
be added later.
This commit is contained in:
Andrey Samokhvalov
2017-05-01 19:58:08 +03:00
committed by Olaoluwa Osuntokun
parent 84f94bdf4f
commit b86409cdb3
9 changed files with 1814 additions and 9 deletions

View File

@@ -8,24 +8,24 @@ import (
"github.com/roasbeef/btcutil"
)
// hopID represents the id which is used by propagation subsystem in order to
// HopID represents the id which is used by propagation subsystem in order to
// identify lightning network node.
// TODO(andrew.shvv) remove after switching to the using channel id.
type hopID [ripemd160.Size]byte
type HopID [ripemd160.Size]byte
// 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
// 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
}
// String returns string representation of hop id.
func (h hopID) String() string {
func (h HopID) String() string {
return hex.EncodeToString(h[:])
}
// IsEqual checks does the two hop ids are equal.
func (h hopID) IsEqual(h2 hopID) bool {
func (h HopID) IsEqual(h2 HopID) bool {
return bytes.Equal(h[:], h2[:])
}