peer: Update peer handling of received feature vectors.

This updates peer to be compatible with the new feature vector API.
This commit is contained in:
Jim Posen 2017-10-11 11:36:23 -07:00 committed by Olaoluwa Osuntokun
parent 1633ab180f
commit af49752d4d
2 changed files with 24 additions and 29 deletions

50
peer.go

@ -147,15 +147,13 @@ type peer struct {
server *server server *server
// localSharedFeatures is a product of comparison of our and their // theirLocalFeatures is the local feature vector received from the peer
// local features vectors which consist of features which are present // during the connection handshake.
// on both sides. theirLocalFeatures *lnwire.FeatureVector
localSharedFeatures *lnwire.SharedFeatures
// globalSharedFeatures is a product of comparison of our and their // theirGlobalFeatures is the global feature vector received from the peer
// global features vectors which consist of features which are present // during the connection handshake.
// on both sides. theirGlobalFeatures *lnwire.FeatureVector
globalSharedFeatures *lnwire.SharedFeatures
queueQuit chan struct{} queueQuit chan struct{}
quit chan struct{} quit chan struct{}
@ -190,9 +188,6 @@ func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
shutdownChanReqs: make(chan *lnwire.Shutdown), shutdownChanReqs: make(chan *lnwire.Shutdown),
closingSignedChanReqs: make(chan *lnwire.ClosingSigned), closingSignedChanReqs: make(chan *lnwire.ClosingSigned),
localSharedFeatures: nil,
globalSharedFeatures: nil,
queueQuit: make(chan struct{}), queueQuit: make(chan struct{}),
quit: make(chan struct{}), quit: make(chan struct{}),
} }
@ -1942,23 +1937,26 @@ func (p *peer) WipeChannel(channel *lnwallet.LightningChannel) error {
// handleInitMsg handles the incoming init message which contains global and // handleInitMsg handles the incoming init message which contains global and
// local features vectors. If feature vectors are incompatible then disconnect. // local features vectors. If feature vectors are incompatible then disconnect.
func (p *peer) handleInitMsg(msg *lnwire.Init) error { func (p *peer) handleInitMsg(msg *lnwire.Init) error {
localSharedFeatures, err := p.server.localFeatures.Compare(msg.LocalFeatures) p.theirLocalFeatures = lnwire.NewFeatureVector(msg.LocalFeatures,
if err != nil { lnwire.LocalFeatures)
err := errors.Errorf("can't compare remote and local feature "+ p.theirGlobalFeatures = lnwire.NewFeatureVector(msg.GlobalFeatures,
"vectors: %v", err) lnwire.GlobalFeatures)
peerLog.Error(err)
return err
}
p.localSharedFeatures = localSharedFeatures
globalSharedFeatures, err := p.server.globalFeatures.Compare(msg.GlobalFeatures) unknownLocalFeatures := p.theirLocalFeatures.UnknownRequiredFeatures()
if err != nil { if len(unknownLocalFeatures) > 0 {
err := errors.Errorf("can't compare remote and global feature "+ err := errors.Errorf("Peer set unknown local feature bits: %v",
"vectors: %v", err) unknownLocalFeatures)
peerLog.Error(err)
return err
}
unknownGlobalFeatures := p.theirGlobalFeatures.UnknownRequiredFeatures()
if len(unknownGlobalFeatures) > 0 {
err := errors.Errorf("Peer set unknown global feature bits: %v",
unknownGlobalFeatures)
peerLog.Error(err) peerLog.Error(err)
return err return err
} }
p.globalSharedFeatures = globalSharedFeatures
return nil return nil
} }
@ -1967,8 +1965,8 @@ func (p *peer) handleInitMsg(msg *lnwire.Init) error {
// supported local and global features. // supported local and global features.
func (p *peer) sendInitMsg() error { func (p *peer) sendInitMsg() error {
msg := lnwire.NewInitMessage( msg := lnwire.NewInitMessage(
p.server.globalFeatures, p.server.globalFeatures.RawFeatureVector,
p.server.localFeatures, p.server.localFeatures.RawFeatureVector,
) )
return p.writeMessage(msg) return p.writeMessage(msg)

@ -252,9 +252,6 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
shutdownChanReqs: make(chan *lnwire.Shutdown), shutdownChanReqs: make(chan *lnwire.Shutdown),
closingSignedChanReqs: make(chan *lnwire.ClosingSigned), closingSignedChanReqs: make(chan *lnwire.ClosingSigned),
localSharedFeatures: nil,
globalSharedFeatures: nil,
queueQuit: make(chan struct{}), queueQuit: make(chan struct{}),
quit: make(chan struct{}), quit: make(chan struct{}),
} }