connmgr: for nodes with multiple addresses, attempt to connect to each
address.
This commit is contained in:
parent
654c5ea61a
commit
3087bec4db
51
server.go
51
server.go
|
@ -67,7 +67,7 @@ type server struct {
|
||||||
connMgr *connmgr.ConnManager
|
connMgr *connmgr.ConnManager
|
||||||
|
|
||||||
pendingConnMtx sync.RWMutex
|
pendingConnMtx sync.RWMutex
|
||||||
persistentConnReqs map[string]*connmgr.ConnReq
|
persistentConnReqs map[string][]*connmgr.ConnReq
|
||||||
|
|
||||||
broadcastRequests chan *broadcastReq
|
broadcastRequests chan *broadcastReq
|
||||||
sendRequests chan *sendReq
|
sendRequests chan *sendReq
|
||||||
|
@ -126,7 +126,7 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||||
sphinx: sphinx.NewRouter(privKey, activeNetParams.Params),
|
sphinx: sphinx.NewRouter(privKey, activeNetParams.Params),
|
||||||
lightningID: sha256.Sum256(serializedPubKey),
|
lightningID: sha256.Sum256(serializedPubKey),
|
||||||
|
|
||||||
persistentConnReqs: make(map[string]*connmgr.ConnReq),
|
persistentConnReqs: make(map[string][]*connmgr.ConnReq),
|
||||||
|
|
||||||
peersByID: make(map[int32]*peer),
|
peersByID: make(map[int32]*peer),
|
||||||
peersByPub: make(map[string]*peer),
|
peersByPub: make(map[string]*peer),
|
||||||
|
@ -247,26 +247,32 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, node := range linkNodes {
|
for _, node := range linkNodes {
|
||||||
// Create a wrapper address which couples the IP and the pubkey
|
|
||||||
// so the brontide authenticated connection can be established.
|
|
||||||
lnAddr := &lnwire.NetAddress{
|
|
||||||
IdentityKey: node.IdentityPub,
|
|
||||||
Address: node.Addresses[0],
|
|
||||||
}
|
|
||||||
pubStr := string(node.IdentityPub.SerializeCompressed())
|
pubStr := string(node.IdentityPub.SerializeCompressed())
|
||||||
srvrLog.Debugf("Attempting persistent connection to channel "+
|
|
||||||
"peer %v", lnAddr)
|
|
||||||
|
|
||||||
// Send the persistent connection request to the connection
|
// In case a node has multiple addresses, attempt to connect to
|
||||||
// manager, saving the request itself so we can cancel/restart
|
// each of them.
|
||||||
// the process as needed.
|
for _, address := range node.Addresses {
|
||||||
// TODO(roasbeef): use default addr
|
// Create a wrapper address which couples the IP and the pubkey
|
||||||
connReq := &connmgr.ConnReq{
|
// so the brontide authenticated connection can be established.
|
||||||
Addr: lnAddr,
|
lnAddr := &lnwire.NetAddress{
|
||||||
Permanent: true,
|
IdentityKey: node.IdentityPub,
|
||||||
|
Address: address,
|
||||||
|
}
|
||||||
|
srvrLog.Debugf("Attempting persistent connection to channel "+
|
||||||
|
"peer %v", lnAddr)
|
||||||
|
|
||||||
|
// Send the persistent connection request to the connection
|
||||||
|
// manager, saving the request itself so we can cancel/restart
|
||||||
|
// the process as needed.
|
||||||
|
// TODO(roasbeef): use default addr
|
||||||
|
connReq := &connmgr.ConnReq{
|
||||||
|
Addr: lnAddr,
|
||||||
|
Permanent: true,
|
||||||
|
}
|
||||||
|
s.persistentConnReqs[pubStr] =
|
||||||
|
append(s.persistentConnReqs[pubStr], connReq)
|
||||||
|
go s.connMgr.Connect(connReq)
|
||||||
}
|
}
|
||||||
s.persistentConnReqs[pubStr] = connReq
|
|
||||||
go s.connMgr.Connect(connReq)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
@ -500,8 +506,11 @@ func (s *server) inboundPeerConnected(conn net.Conn) {
|
||||||
// cancel the ongoing connection attempts to ensure that we don't end
|
// cancel the ongoing connection attempts to ensure that we don't end
|
||||||
// up with a duplicate connecting to the same peer.
|
// up with a duplicate connecting to the same peer.
|
||||||
s.pendingConnMtx.RLock()
|
s.pendingConnMtx.RLock()
|
||||||
if connReq, ok := s.persistentConnReqs[pubStr]; ok {
|
if connReqs, ok := s.persistentConnReqs[pubStr]; ok {
|
||||||
s.connMgr.Remove(connReq.ID())
|
for _, connReq := range connReqs {
|
||||||
|
s.connMgr.Remove(connReq.ID())
|
||||||
|
}
|
||||||
|
delete(s.persistentConnReqs, pubStr)
|
||||||
}
|
}
|
||||||
s.pendingConnMtx.RUnlock()
|
s.pendingConnMtx.RUnlock()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user