server+peer: re-write persistent connection handling
The prior methods we employed to handle persistent connections could result in the following situation: both peers come up, and _concurrently_ establish connection to each other. With the prior logic, at this point, both connections would be terminated as each peer would go to kill the connection of the other peer. In order to resolve this issue in this commit, we’ve re-written the way we handle persistent connections. The eliminate the issue described above, in the case of concurrent peer connection, we now use a deterministic method to decide _which_ connection should be closed. The following rule governs which connection should be closed: the connection of the peer with the “smaller” public key should be closed. With this rule we now avoid the issue described above. Additionally, each peer now gains a peerTerminationWatcher which waits until a peer has been disconnected, and then cleans up all resources allocated to the peer, notifies relevant sub-systems of its demise, and finally handles re-connecting to the peer if it's persistent. This replaces the goroutine that was spawned in the old version of peer.Disconnect().
This commit is contained in:
2 files changed
+185
-50
No files matched your search
@@ -342,21 +342,6 @@ func (p *peer) Disconnect() {
|
||||
|
||||
close(p.quit)
|
||||
|
||||
// If this connection was established persistently, then notify the
|
||||
// connection manager that the peer has been disconnected.
|
||||
if p.connReq != nil {
|
||||
p.server.connMgr.Disconnect(p.connReq.ID())
|
||||
}
|
||||
|
||||
// Launch a goroutine to clean up the remaining resources.
|
||||
go func() {
|
||||
// Tell the switch to unregister all links associated with this
|
||||
// peer. Passing nil as the target link indicates that all
|
||||
// links associated with this interface should be closed.
|
||||
p.server.htlcSwitch.UnregisterLink(p.addr.IdentityKey, nil)
|
||||
|
||||
p.server.donePeers <- p
|
||||
}()
|
||||
}
|
||||
|
||||
// String returns the string representation of this peer.
|
||||
|
||||
Reference in new issue
Block a user