lnd: switch to using the connmgr for listening and persistent conns
This commit revamps the way in bound and outbound connections are handled within lnd. Instead of manually managing listening goroutines and also outbound connections, all the duty is now assigned to the connmgr, a new btcsuite package. The connmgr now handles accepting inbound (brontide) connections and communicates with the server to hand off new connections via a callback. Additionally, any outbound connection attempt is now made persistent by default, with the assumption that (for right now), connections are only to be made to peers we wish to make connections to. Finally, on start-up we now attempt to connection to all/any of our direct channel counter parties in order to promote the availability of our channels to the daemon itself and any RPC users.
This commit is contained in:
5 files changed
+279
-125
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/connmgr"
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lightning-onion"
|
||||
@@ -65,7 +66,8 @@ type peer struct {
|
||||
connected int32
|
||||
disconnect int32
|
||||
|
||||
conn net.Conn
|
||||
connReq *connmgr.ConnReq
|
||||
conn net.Conn
|
||||
|
||||
addr *lnwire.NetAddress
|
||||
lightningID wire.ShaHash
|
||||
@@ -318,6 +320,10 @@ func (p *peer) Disconnect() {
|
||||
|
||||
close(p.quit)
|
||||
|
||||
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
|
||||
@@ -762,6 +768,8 @@ func (p *peer) executeCooperativeClose(channel *lnwallet.LightningChannel) (*wir
|
||||
|
||||
// handleLocalClose kicks-off the workflow to execute a cooperative or forced
|
||||
// unilateral closure of the channel initiated by a local sub-system.
|
||||
// TODO(roasbeef): if no more active channels with peer call Remove on connMgr
|
||||
// with peerID
|
||||
func (p *peer) handleLocalClose(req *closeLinkReq) {
|
||||
var (
|
||||
err error
|
||||
|
||||
Reference in new issue
Block a user