Merge pull request #2500 from Roasbeef/mandatory-dlp

server: require the DLP bit for all incoming/outgoing connections
This commit is contained in:
Olaoluwa Osuntokun 2019-01-31 20:14:15 -08:00 committed by GitHub
commit 5167b02312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

26
peer.go

@ -958,9 +958,9 @@ func (p *peer) readHandler() {
p.Disconnect(err) p.Disconnect(err)
}) })
// Initialize our negotiated gossip sync method before reading // Initialize our negotiated gossip sync method before reading messages
// messages off the wire. When using gossip queries, this ensures // off the wire. When using gossip queries, this ensures a gossip
// a gossip syncer is active by the time query messages arrive. // syncer is active by the time query messages arrive.
// //
// TODO(conner): have peer store gossip syncer directly and bypass // TODO(conner): have peer store gossip syncer directly and bypass
// gossiper? // gossiper?
@ -2146,18 +2146,21 @@ func (p *peer) WipeChannel(chanPoint *wire.OutPoint) 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 {
p.remoteLocalFeatures = lnwire.NewFeatureVector(msg.LocalFeatures, p.remoteLocalFeatures = lnwire.NewFeatureVector(
lnwire.LocalFeatures) msg.LocalFeatures, lnwire.LocalFeatures,
p.remoteGlobalFeatures = lnwire.NewFeatureVector(msg.GlobalFeatures, )
lnwire.GlobalFeatures) p.remoteGlobalFeatures = lnwire.NewFeatureVector(
msg.GlobalFeatures, lnwire.GlobalFeatures,
)
// Now that we have their features loaded, we'll ensure that they
// didn't set any required bits that we don't know of.
unknownLocalFeatures := p.remoteLocalFeatures.UnknownRequiredFeatures() unknownLocalFeatures := p.remoteLocalFeatures.UnknownRequiredFeatures()
if len(unknownLocalFeatures) > 0 { if len(unknownLocalFeatures) > 0 {
err := fmt.Errorf("Peer set unknown local feature bits: %v", err := fmt.Errorf("Peer set unknown local feature bits: %v",
unknownLocalFeatures) unknownLocalFeatures)
return err return err
} }
unknownGlobalFeatures := p.remoteGlobalFeatures.UnknownRequiredFeatures() unknownGlobalFeatures := p.remoteGlobalFeatures.UnknownRequiredFeatures()
if len(unknownGlobalFeatures) > 0 { if len(unknownGlobalFeatures) > 0 {
err := fmt.Errorf("Peer set unknown global feature bits: %v", err := fmt.Errorf("Peer set unknown global feature bits: %v",
@ -2165,6 +2168,13 @@ func (p *peer) handleInitMsg(msg *lnwire.Init) error {
return err return err
} }
// Now that we know we understand their requirements, we'll check to
// see if they don't support anything that we deem to be mandatory.
switch {
case !p.remoteLocalFeatures.HasFeature(lnwire.DataLossProtectRequired):
return fmt.Errorf("data loss protection required")
}
return nil return nil
} }

@ -2370,7 +2370,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
// We'll signal that we understand the data loss protection feature, // We'll signal that we understand the data loss protection feature,
// and also that we support the new gossip query features. // and also that we support the new gossip query features.
localFeatures.Set(lnwire.DataLossProtectOptional) localFeatures.Set(lnwire.DataLossProtectRequired)
localFeatures.Set(lnwire.GossipQueriesOptional) localFeatures.Set(lnwire.GossipQueriesOptional)
// Now that we've established a connection, create a peer, and it to // Now that we've established a connection, create a peer, and it to