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.
This commit is contained in:
Elle Mouton committed 2021-10-04 14:57:49 +02:00
1 parent 004ce640d0
commit 169316eba2
1 file changed
+35 -31
+35 -31
View File
@@ -3531,39 +3531,43 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) {
// within the peer's address for reconnection purposes. // within the peer's address for reconnection purposes.
// //
// TODO(roasbeef): use them all? // TODO(roasbeef): use them all?
if p.Inbound() { advertisedAddr, err := s.fetchNodeAdvertisedAddr(pubKey)
advertisedAddr, err := s.fetchNodeAdvertisedAddr(pubKey) switch {
switch { // We found an advertised address, so use it.
// We found an advertised address, so use it. case err == nil:
case err == nil: p.SetAddress(advertisedAddr)
p.SetAddress(advertisedAddr)
// The peer doesn't have an advertised address. // The peer doesn't have an advertised address.
case err == errNoAdvertisedAddr: case err == errNoAdvertisedAddr:
// Fall back to the existing peer address if // If it is an outbound peer then we fall back to the existing
// we're not accepting connections over Tor. // peer address.
if s.torController == nil { if !p.Inbound() {
break 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)
} }
// 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 // Otherwise, we'll launch a new connection request in order to