peer+lnpeer: add new methods to expose local+global features for lnpeer interface

This commit is contained in:
Olaoluwa Osuntokun 2019-09-11 05:41:08 -07:00
parent a58cfa65ff
commit 3f8526a0ca
No known key found for this signature in database
GPG Key ID: BC13F65E2DC84465
7 changed files with 59 additions and 1 deletions

@ -56,6 +56,12 @@ func (p *mockPeer) Address() net.Addr { return nil }
func (p *mockPeer) QuitSignal() <-chan struct{} {
return p.quit
}
func (p *mockPeer) LocalGlobalFeatures() *lnwire.FeatureVector {
return nil
}
func (p *mockPeer) RemoteGlobalFeatures() *lnwire.FeatureVector {
return nil
}
// mockMessageStore is an in-memory implementation of the MessageStore interface
// used for the gossiper's unit tests.

@ -183,6 +183,14 @@ func (n *testNode) QuitSignal() <-chan struct{} {
return n.shutdownChannel
}
func (n *testNode) LocalGlobalFeatures() *lnwire.FeatureVector {
return lnwire.NewFeatureVector(nil, nil)
}
func (n *testNode) RemoteGlobalFeatures() *lnwire.FeatureVector {
return lnwire.NewFeatureVector(nil, nil)
}
func (n *testNode) AddNewChannel(channel *channeldb.OpenChannel,
quit <-chan struct{}) error {

@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/lightningnetwork/lightning-onion"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/chainntnfs"
)

@ -1651,6 +1651,12 @@ func (m *mockPeer) IdentityKey() *btcec.PublicKey {
func (m *mockPeer) Address() net.Addr {
return nil
}
func (m *mockPeer) LocalGlobalFeatures() *lnwire.FeatureVector {
return nil
}
func (m *mockPeer) RemoteGlobalFeatures() *lnwire.FeatureVector {
return nil
}
func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,

@ -597,6 +597,14 @@ func (s *mockServer) WipeChannel(*wire.OutPoint) error {
return nil
}
func (s *mockServer) LocalGlobalFeatures() *lnwire.FeatureVector {
return nil
}
func (s *mockServer) RemoteGlobalFeatures() *lnwire.FeatureVector {
return nil
}
func (s *mockServer) Stop() error {
if !atomic.CompareAndSwapInt32(&s.shutdown, 0, 1) {
return nil

@ -46,4 +46,16 @@ type Peer interface {
// using the interface to cancel any processing in the event the backing
// implementation exits.
QuitSignal() <-chan struct{}
// LocalGlobalFeatures returns the set of global features that has been
// advertised by the local peer. This allows sub-systems that use this
// interface to gate their behavior off the set of negotiated feature
// bits.
LocalGlobalFeatures() *lnwire.FeatureVector
// RemoteGlobalFeatures returns the set of global features that has
// been advertised by the remote peer. This allows sub-systems that use
// this interface to gate their behavior off the set of negotiated
// feature bits.
RemoteGlobalFeatures() *lnwire.FeatureVector
}

18
peer.go

@ -2410,6 +2410,24 @@ func (p *peer) handleInitMsg(msg *lnwire.Init) error {
return nil
}
// LocalGlobalFeatures returns the set of global features that has been
// advertised by the local node. This allows sub-systems that use this
// interface to gate their behavior off the set of negotiated feature bits.
//
// NOTE: Part of the lnpeer.Peer interface.
func (p *peer) LocalGlobalFeatures() *lnwire.FeatureVector {
return p.server.globalFeatures
}
// RemoteGlobalFeatures returns the set of global features that has been
// advertised by the remote node. This allows sub-systems that use this
// interface to gate their behavior off the set of negotiated feature bits.
//
// NOTE: Part of the lnpeer.Peer interface.
func (p *peer) RemoteGlobalFeatures() *lnwire.FeatureVector {
return p.remoteGlobalFeatures
}
// sendInitMsg sends init message to remote peer which contains our currently
// supported local and global features.
func (p *peer) sendInitMsg() error {