From 169316eba211888a3027c0ae4c7e5859a5a7d24a Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 27 Sep 2021 16:34:17 +0200 Subject: [PATCH] server: fetch addr from db if outbound too This commit just ensures that we fetch the lastest advertised addresses for a peer from the db for both inbound and outbound peers. The reason for seperating this into its own commit is to make future commits in this PR easier to review. --- server.go | 66 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/server.go b/server.go index 2981f93e3..a205a8bd1 100644 --- a/server.go +++ b/server.go @@ -3531,39 +3531,43 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) { // within the peer's address for reconnection purposes. // // TODO(roasbeef): use them all? - if p.Inbound() { - advertisedAddr, err := s.fetchNodeAdvertisedAddr(pubKey) - switch { - // We found an advertised address, so use it. - case err == nil: - p.SetAddress(advertisedAddr) + advertisedAddr, err := s.fetchNodeAdvertisedAddr(pubKey) + switch { + // We found an advertised address, so use it. + case err == nil: + p.SetAddress(advertisedAddr) - // The peer doesn't have an advertised address. - case err == errNoAdvertisedAddr: - // Fall back to the existing peer address if - // we're not accepting connections over Tor. - if s.torController == nil { - break - } - - // If we are, the peer's address won't be known - // to us (we'll see a private address, which is - // the address used by our onion service to dial - // to lnd), so we don't have enough information - // to attempt a reconnect. - srvrLog.Debugf("Ignoring reconnection attempt "+ - "to inbound peer %v without "+ - "advertised address", p) - return - - // We came across an error retrieving an advertised - // address, log it, and fall back to the existing peer - // address. - default: - srvrLog.Errorf("Unable to retrieve advertised "+ - "address for node %x: %v", p.PubKey(), - err) + // The peer doesn't have an advertised address. + case err == errNoAdvertisedAddr: + // If it is an outbound peer then we fall back to the existing + // peer address. + if !p.Inbound() { + break } + + // Fall back to the existing peer address if + // we're not accepting connections over Tor. + if s.torController == nil { + break + } + + // If we are, the peer's address won't be known + // to us (we'll see a private address, which is + // the address used by our onion service to dial + // to lnd), so we don't have enough information + // to attempt a reconnect. + srvrLog.Debugf("Ignoring reconnection attempt "+ + "to inbound peer %v without "+ + "advertised address", p) + return + + // We came across an error retrieving an advertised + // address, log it, and fall back to the existing peer + // address. + default: + srvrLog.Errorf("Unable to retrieve advertised "+ + "address for node %x: %v", p.PubKey(), + err) } // Otherwise, we'll launch a new connection request in order to