server: attempt reconnection to all known addresses
This commit is contained in:
1 file changed
+21
-39
@@ -1597,52 +1597,34 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
|
|
||||||
pubStr := string(policy.Node.PubKeyBytes[:])
|
pubStr := string(policy.Node.PubKeyBytes[:])
|
||||||
|
|
||||||
// Add addresses from channel graph/NodeAnnouncements to the
|
// Add all unique addresses from channel graph/NodeAnnouncements
|
||||||
// list of addresses we'll connect to. If there are duplicates
|
// to the list of addresses we'll connect to for this peer.
|
||||||
// that have different ports specified, the port from the
|
var addrSet = make(map[string]net.Addr)
|
||||||
// channel graph should supersede the port from the link node.
|
for _, addr := range policy.Node.Addresses {
|
||||||
var addrs []net.Addr
|
switch addr.(type) {
|
||||||
|
case *net.TCPAddr, *tor.OnionAddr:
|
||||||
|
addrSet[addr.String()] = addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this peer is also recorded as a link node, we'll add any
|
||||||
|
// additional addresses that have not already been selected.
|
||||||
linkNodeAddrs, ok := nodeAddrsMap[pubStr]
|
linkNodeAddrs, ok := nodeAddrsMap[pubStr]
|
||||||
if ok {
|
if ok {
|
||||||
for _, lnAddress := range linkNodeAddrs.addresses {
|
for _, lnAddress := range linkNodeAddrs.addresses {
|
||||||
var addrHost string
|
switch lnAddress.(type) {
|
||||||
switch addr := lnAddress.(type) {
|
|
||||||
case *net.TCPAddr:
|
|
||||||
addrHost = addr.IP.String()
|
|
||||||
case *tor.OnionAddr:
|
|
||||||
addrHost = addr.OnionService
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var addrMatched bool
|
|
||||||
for _, polAddress := range policy.Node.Addresses {
|
|
||||||
switch addr := polAddress.(type) {
|
|
||||||
case *net.TCPAddr:
|
|
||||||
if addr.IP.String() == addrHost {
|
|
||||||
addrMatched = true
|
|
||||||
addrs = append(addrs, addr)
|
|
||||||
}
|
|
||||||
case *tor.OnionAddr:
|
|
||||||
if addr.OnionService == addrHost {
|
|
||||||
addrMatched = true
|
|
||||||
addrs = append(addrs, addr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !addrMatched {
|
|
||||||
addrs = append(addrs, lnAddress)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, addr := range policy.Node.Addresses {
|
|
||||||
switch addr.(type) {
|
|
||||||
case *net.TCPAddr, *tor.OnionAddr:
|
case *net.TCPAddr, *tor.OnionAddr:
|
||||||
addrs = append(addrs, addr)
|
addrSet[lnAddress.String()] = lnAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Construct a slice of the deduped addresses.
|
||||||
|
var addrs []net.Addr
|
||||||
|
for _, addr := range addrSet {
|
||||||
|
addrs = append(addrs, addr)
|
||||||
|
}
|
||||||
|
|
||||||
n := &nodeAddresses{
|
n := &nodeAddresses{
|
||||||
addresses: addrs,
|
addresses: addrs,
|
||||||
}
|
}
|
||||||
@@ -2356,7 +2338,7 @@ func (s *server) peerInitializer(p *peer) {
|
|||||||
// Start teh peer! If an error occurs, we Disconnect the peer, which
|
// Start teh peer! If an error occurs, we Disconnect the peer, which
|
||||||
// will unblock the peerTerminationWatcher.
|
// will unblock the peerTerminationWatcher.
|
||||||
if err := p.Start(); err != nil {
|
if err := p.Start(); err != nil {
|
||||||
p.Disconnect(errors.New("unable to start peer: %v"))
|
p.Disconnect(fmt.Errorf("unable to start peer: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user