server: ensure persistent connections to tor addrs are made if active
In this commit, we restrict the persistent connection logic on startup to only attempt to establish connections to Tor addresses if Tor outbound support is enabled. Otherwise, we'll continually attempt to reach the address even though we never will.
This commit is contained in:
1 file changed
+23
-10
@@ -1555,14 +1555,13 @@ type nodeAddresses struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// establishPersistentConnections attempts to establish persistent connections
|
// establishPersistentConnections attempts to establish persistent connections
|
||||||
// to all our direct channel collaborators. In order to promote liveness of
|
// to all our direct channel collaborators. In order to promote liveness of our
|
||||||
// our active channels, we instruct the connection manager to attempt to
|
// active channels, we instruct the connection manager to attempt to establish
|
||||||
// establish and maintain persistent connections to all our direct channel
|
// and maintain persistent connections to all our direct channel counterparties.
|
||||||
// counterparties.
|
|
||||||
func (s *server) establishPersistentConnections() error {
|
func (s *server) establishPersistentConnections() error {
|
||||||
// nodeAddrsMap stores the combination of node public keys and
|
// nodeAddrsMap stores the combination of node public keys and addresses
|
||||||
// addresses that we'll attempt to reconnect to. PubKey strings are
|
// that we'll attempt to reconnect to. PubKey strings are used as keys
|
||||||
// used as keys since other PubKey forms can't be compared.
|
// since other PubKey forms can't be compared.
|
||||||
nodeAddrsMap := map[string]*nodeAddresses{}
|
nodeAddrsMap := map[string]*nodeAddresses{}
|
||||||
|
|
||||||
// Iterate through the list of LinkNodes to find addresses we should
|
// Iterate through the list of LinkNodes to find addresses we should
|
||||||
@@ -1600,11 +1599,18 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
|
|
||||||
// Add all unique addresses from channel graph/NodeAnnouncements
|
// Add all unique addresses from channel graph/NodeAnnouncements
|
||||||
// to the list of addresses we'll connect to for this peer.
|
// to the list of addresses we'll connect to for this peer.
|
||||||
var addrSet = make(map[string]net.Addr)
|
addrSet := make(map[string]net.Addr)
|
||||||
for _, addr := range policy.Node.Addresses {
|
for _, addr := range policy.Node.Addresses {
|
||||||
switch addr.(type) {
|
switch addr.(type) {
|
||||||
case *net.TCPAddr, *tor.OnionAddr:
|
case *net.TCPAddr:
|
||||||
addrSet[addr.String()] = addr
|
addrSet[addr.String()] = addr
|
||||||
|
|
||||||
|
// We'll only attempt to connect to Tor addresses if Tor
|
||||||
|
// outbound support is enabled.
|
||||||
|
case *tor.OnionAddr:
|
||||||
|
if cfg.Tor.Active {
|
||||||
|
addrSet[addr.String()] = addr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1614,8 +1620,15 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
if ok {
|
if ok {
|
||||||
for _, lnAddress := range linkNodeAddrs.addresses {
|
for _, lnAddress := range linkNodeAddrs.addresses {
|
||||||
switch lnAddress.(type) {
|
switch lnAddress.(type) {
|
||||||
case *net.TCPAddr, *tor.OnionAddr:
|
case *net.TCPAddr:
|
||||||
addrSet[lnAddress.String()] = lnAddress
|
addrSet[lnAddress.String()] = lnAddress
|
||||||
|
|
||||||
|
// We'll only attempt to connect to Tor
|
||||||
|
// addresses if Tor outbound support is enabled.
|
||||||
|
case *tor.OnionAddr:
|
||||||
|
if cfg.Tor.Active {
|
||||||
|
addrSet[lnAddress.String()] = lnAddress
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user