diff --git a/config_builder.go b/config_builder.go index 5679de10b..cbf12c3d6 100644 --- a/config_builder.go +++ b/config_builder.go @@ -44,6 +44,7 @@ import ( "github.com/lightningnetwork/lnd/lnwallet/btcwallet" "github.com/lightningnetwork/lnd/lnwallet/rpcwallet" "github.com/lightningnetwork/lnd/macaroons" + "github.com/lightningnetwork/lnd/protofsm" "github.com/lightningnetwork/lnd/routing" "github.com/lightningnetwork/lnd/rpcperms" "github.com/lightningnetwork/lnd/signal" @@ -162,6 +163,10 @@ type AuxComponents struct { // TrafficShaper is an optional traffic shaper that can be used to // control the outgoing channel of a payment. TrafficShaper fn.Option[routing.TlvTrafficShaper] + + // MsgRouter is an optional message router that if set will be used in + // place of a new blank default message router. + MsgRouter fn.Option[protofsm.MsgRouter] } // DefaultWalletImpl is the default implementation of our normal, btcwallet diff --git a/peer/brontide.go b/peer/brontide.go index 229013580..5e0264328 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -375,6 +375,11 @@ type Config struct { // invalid. DisallowRouteBlinding bool + // MsgRouter is an optional instance of the main message router that + // the peer will use. If None, then a new default version will be used + // in place. + MsgRouter fn.Option[protofsm.MsgRouter] + // Quit is the server's quit channel. If this is closed, we halt operation. Quit chan struct{} } @@ -513,6 +518,12 @@ var _ lnpeer.Peer = (*Brontide)(nil) func NewBrontide(cfg Config) *Brontide { logPrefix := fmt.Sprintf("Peer(%x):", cfg.PubKeyBytes) + // We'll either use the msg router instance passed in, or create a new + // blank instance. + msgRouter := cfg.MsgRouter.Alt(fn.Some[protofsm.MsgRouter]( + protofsm.NewMultiMsgRouter(), + )) + p := &Brontide{ cfg: cfg, activeSignal: make(chan struct{}), @@ -535,9 +546,7 @@ func NewBrontide(cfg Config) *Brontide { startReady: make(chan struct{}), quit: make(chan struct{}), log: build.NewPrefixLog(logPrefix, peerLog), - msgRouter: fn.Some[protofsm.MsgRouter]( - protofsm.NewMultiMsgRouter(), - ), + msgRouter: msgRouter, } var ( diff --git a/server.go b/server.go index 8f7ddce67..d484db2e9 100644 --- a/server.go +++ b/server.go @@ -3924,6 +3924,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, DisallowRouteBlinding: s.cfg.ProtocolOptions.NoRouteBlinding(), Quit: s.quit, AuxLeafStore: s.implCfg.AuxLeafStore, + MsgRouter: s.implCfg.MsgRouter, } copy(pCfg.PubKeyBytes[:], peerAddr.IdentityKey.SerializeCompressed())