diff --git a/server.go b/server.go index def6c6a7..fd13cb9e 100644 --- a/server.go +++ b/server.go @@ -1384,9 +1384,11 @@ func (s *server) peerTerminationWatcher(p *peer) { // available for use. s.fundingMgr.CancelPeerReservations(p.PubKey()) + pubKey := p.addr.IdentityKey + // We'll also inform the gossiper that this peer is no longer active, // so we don't need to maintain sync state for it any longer. - s.authGossiper.PruneSyncState(p.addr.IdentityKey) + s.authGossiper.PruneSyncState(pubKey) // Tell the switch to remove all links associated with this peer. // Passing nil as the target link indicates that all links associated @@ -1435,7 +1437,7 @@ func (s *server) peerTerminationWatcher(p *peer) { s.removePeer(p) // Next, check to see if this is a persistent peer or not. - pubStr := string(p.addr.IdentityKey.SerializeCompressed()) + pubStr := string(pubKey.SerializeCompressed()) _, ok := s.persistentPeers[pubStr] if ok { // We'll only need to re-launch a connection request if one @@ -1444,6 +1446,23 @@ func (s *server) peerTerminationWatcher(p *peer) { return } + // We'll ensure that we locate an advertised address to use + // within the peer's address for reconnection purposes. + // + // TODO(roasbeef): use them all? + if p.inbound { + advertisedAddr, err := s.fetchNodeAdvertisedAddr( + pubKey, + ) + if err != nil { + srvrLog.Errorf("Unable to retrieve advertised "+ + "address for node %x: %v", + pubKey.SerializeCompressed(), err) + } else { + p.addr.Address = advertisedAddr + } + } + // Otherwise, we'll launch a new connection request in order to // attempt to maintain a persistent connection with this peer. connReq := &connmgr.ConnReq{ @@ -1526,21 +1545,6 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, addr := conn.RemoteAddr() pubKey := brontideConn.RemotePub() - // We'll ensure that we locate an advertised address to use within the - // peer's address for reconnection purposes. - // - // TODO: leave the address field empty if there aren't any? - if inbound { - advertisedAddr, err := s.fetchNodeAdvertisedAddr(pubKey) - if err != nil { - srvrLog.Errorf("Unable to retrieve advertised address "+ - "for node %x: %v", pubKey.SerializeCompressed(), - err) - } else { - addr = advertisedAddr - } - } - peerAddr := &lnwire.NetAddress{ IdentityKey: pubKey, Address: addr,