watchtower/multi: switch over to wtpolicy

migrate to using wtpolicy.Policy in wtwire messages and wtserver
This commit is contained in:
Conner Fromknecht
2019-01-10 15:35:11 -08:00
parent c315d74347
commit b746bf86c2
10 changed files with 113 additions and 92 deletions

View File

@@ -4,6 +4,7 @@ import (
"io"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/watchtower/blob"
)
// CreateSession is sent from a client to tower when to negotiate a session, which
@@ -11,9 +12,9 @@ import (
// An update is consumed by uploading an encrypted blob that contains
// information required to sweep a revoked commitment transaction.
type CreateSession struct {
// BlobVersion specifies the blob format that must be used by all
// updates sent under the session key used to negotiate this session.
BlobVersion uint16
// BlobType specifies the blob format that must be used by all updates sent
// under the session key used to negotiate this session.
BlobType blob.Type
// MaxUpdates is the maximum number of updates the watchtower will honor
// for this session.
@@ -41,7 +42,7 @@ var _ Message = (*CreateSession)(nil)
// This is part of the wtwire.Message interface.
func (m *CreateSession) Decode(r io.Reader, pver uint32) error {
return ReadElements(r,
&m.BlobVersion,
&m.BlobType,
&m.MaxUpdates,
&m.RewardRate,
&m.SweepFeeRate,
@@ -54,7 +55,7 @@ func (m *CreateSession) Decode(r io.Reader, pver uint32) error {
// This is part of the wtwire.Message interface.
func (m *CreateSession) Encode(w io.Writer, pver uint32) error {
return WriteElements(w,
m.BlobVersion,
m.BlobType,
m.MaxUpdates,
m.RewardRate,
m.SweepFeeRate,

View File

@@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/watchtower/blob"
)
// WriteElement is a one-stop shop to write the big endian representation of
@@ -30,6 +31,13 @@ func WriteElement(w io.Writer, element interface{}) error {
return err
}
case blob.Type:
var b [2]byte
binary.BigEndian.PutUint16(b[:], uint16(e))
if _, err := w.Write(b[:]); err != nil {
return err
}
case uint32:
var b [4]byte
binary.BigEndian.PutUint32(b[:], e)
@@ -127,6 +135,13 @@ func ReadElement(r io.Reader, element interface{}) error {
}
*e = binary.BigEndian.Uint16(b[:])
case *blob.Type:
var b [2]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
}
*e = blob.Type(binary.BigEndian.Uint16(b[:]))
case *uint32:
var b [4]byte
if _, err := io.ReadFull(r, b[:]); err != nil {