discovery: implement ChannelAnnouncement banning

This commit hooks up the banman to the gossiper:
- peers that are banned and don't have a channel with us will get
  disconnected until they are unbanned.
- peers that are banned and have a channel with us won't get
  disconnected, but we will ignore their channel announcements until
  they are no longer banned. Note that this only disables gossip of
  announcements to us and still allows us to open channels to them.
This commit is contained in:
Eugene Siegel committed 2024-08-27 14:11:06 -04:00
1 parent 9380292a5a
commit 013452cff0
7 files changed
+480 -60

No files matched your search

+55 -2
View File
@@ -1026,6 +1026,8 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
return nil, err
}
scidCloserMan := discovery.NewScidCloserMan(s.graphDB, s.chanStateDB)
s.authGossiper = discovery.New(discovery.Config{
Graph: s.graphBuilder,
Notifier: s.cc.ChainNotifier,
@@ -1063,6 +1065,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
GetAlias: s.aliasMgr.GetPeerAlias,
FindChannel: s.findChannel,
IsStillZombieChannel: s.graphBuilder.IsZombieChannel,
ScidCloser: scidCloserMan,
}, nodeKeyDesc)
//nolint:lll
@@ -3639,11 +3642,34 @@ func (s *server) InboundPeerConnected(conn net.Conn) {
}
nodePub := conn.(*brontide.Conn).RemotePub()
pubStr := string(nodePub.SerializeCompressed())
pubSer := nodePub.SerializeCompressed()
pubStr := string(pubSer)
var pubBytes [33]byte
copy(pubBytes[:], pubSer)
s.mu.Lock()
defer s.mu.Unlock()
// If the remote node's public key is banned, drop the connection.
shouldDc, dcErr := s.authGossiper.ShouldDisconnect(nodePub)
if dcErr != nil {
srvrLog.Errorf("Unable to check if we should disconnect "+
"peer: %v", dcErr)
conn.Close()
return
}
if shouldDc {
srvrLog.Debugf("Dropping connection for %v since they are "+
"banned.", pubSer)
conn.Close()
return
}
// If we already have an outbound connection to this peer, then ignore
// this new connection.
if p, ok := s.outboundPeers[pubStr]; ok {
@@ -3726,11 +3752,38 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn)
}
nodePub := conn.(*brontide.Conn).RemotePub()
pubStr := string(nodePub.SerializeCompressed())
pubSer := nodePub.SerializeCompressed()
pubStr := string(pubSer)
var pubBytes [33]byte
copy(pubBytes[:], pubSer)
s.mu.Lock()
defer s.mu.Unlock()
// If the remote node's public key is banned, drop the connection.
shouldDc, dcErr := s.authGossiper.ShouldDisconnect(nodePub)
if dcErr != nil {
srvrLog.Errorf("Unable to check if we should disconnect "+
"peer: %v", dcErr)
conn.Close()
return
}
if shouldDc {
srvrLog.Debugf("Dropping connection for %v since they are "+
"banned.", pubSer)
if connReq != nil {
s.connMgr.Remove(connReq.ID())
}
conn.Close()
return
}
// If we already have an inbound connection to this peer, then ignore
// this new connection.
if p, ok := s.inboundPeers[pubStr]; ok {