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

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