From 3f8526a0cacdfb9229c4f1f17ec9289d9289c9a7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 11 Sep 2019 05:41:08 -0700 Subject: [PATCH] peer+lnpeer: add new methods to expose local+global features for lnpeer interface --- discovery/mock_test.go | 6 ++++++ fundingmanager_test.go | 8 ++++++++ htlcswitch/decayedlog_test.go | 2 +- htlcswitch/link_test.go | 6 ++++++ htlcswitch/mock.go | 8 ++++++++ lnpeer/peer.go | 12 ++++++++++++ peer.go | 18 ++++++++++++++++++ 7 files changed, 59 insertions(+), 1 deletion(-) diff --git a/discovery/mock_test.go b/discovery/mock_test.go index 84ba8636..57fc319a 100644 --- a/discovery/mock_test.go +++ b/discovery/mock_test.go @@ -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. diff --git a/fundingmanager_test.go b/fundingmanager_test.go index 05c0f41c..759f783b 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -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 { diff --git a/htlcswitch/decayedlog_test.go b/htlcswitch/decayedlog_test.go index 2afcdda4..6cf97c50 100644 --- a/htlcswitch/decayedlog_test.go +++ b/htlcswitch/decayedlog_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/lightningnetwork/lightning-onion" + sphinx "github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lnd/chainntnfs" ) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index b7cf3ed1..b21ad5c2 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -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, diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index a3174b8f..626ebe82 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -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 diff --git a/lnpeer/peer.go b/lnpeer/peer.go index 16cbff63..e21e2796 100644 --- a/lnpeer/peer.go +++ b/lnpeer/peer.go @@ -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 } diff --git a/peer.go b/peer.go index 7f2d9155..c8f8ef27 100644 --- a/peer.go +++ b/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 {