From 15da55effb1c85a9f3e03b1b2a238c7054e22f6e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 8 Jun 2018 20:34:31 -0700 Subject: [PATCH] server: finish correction of inbound/outbound within the server In this commit, we finish the fix for the inbound/outbound peer bool in the server. The prior commit forgot to also flip the inbound/output maps in Inbound/Outbound peer connected. As a result, the checks were incorrect and could cause lnd to refuse to accept any more inbound connections in the case of a concurrent connection attempt. --- server.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 803572290..5f0becd3f 100644 --- a/server.go +++ b/server.go @@ -1625,10 +1625,12 @@ func (s *server) InboundPeerConnected(conn net.Conn) { s.mu.Lock() defer s.mu.Unlock() - // If we already have an inbound connection to this peer, then ignore + // If we already have an outbound connection to this peer, then ignore // this new connection. - if _, ok := s.inboundPeers[pubStr]; ok { - srvrLog.Debugf("Ignoring duplicate inbound connection") + if _, ok := s.outboundPeers[pubStr]; ok { + srvrLog.Debugf("Already have outbound connection for %v, "+ + "ignoring inbound connection", nodePub.SerializeCompressed()) + conn.Close() return } @@ -1705,10 +1707,13 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) s.mu.Lock() defer s.mu.Unlock() - // If we already have an outbound connection to this peer, then ignore + // If we already have an inbound connection to this peer, then ignore // this new connection. - if _, ok := s.outboundPeers[pubStr]; ok { - srvrLog.Debugf("Ignoring duplicate outbound connection") + if _, ok := s.inboundPeers[pubStr]; ok { + srvrLog.Debugf("Already have inbound connection for %v, "+ + "ignoring outbound connection", + nodePub.SerializeCompressed()) + if connReq != nil { s.connMgr.Remove(connReq.ID()) }