multi: make MsgRouter available in the ImplementationCfg

With this commit, we allow the `MsgRouter` to be available in the `ImplementationCfg`. With this, programs outside of lnd itself are able to now hook into the message processing flow to direct handle custom messages, and even normal wire messages.
This commit is contained in:
Olaoluwa Osuntokun
2024-04-04 16:13:30 -07:00
committed by Oliver Gugger
parent 6eab09c2a0
commit b9786e1f20
3 changed files with 20 additions and 1 deletions

View File

@@ -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/peer"
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sqldb"
@@ -157,6 +158,10 @@ type AuxComponents struct {
// AuxLeafStore is an optional data source that can be used by custom
// channels to fetch+store various data.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
// MsgRouter is an optional message router that if set will be used in
// place of a new balnk default message router.
MsgRouter fn.Option[peer.MsgRouter]
}
// DefaultWalletImpl is the default implementation of our normal, btcwallet

View File

@@ -374,6 +374,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[MsgRouter]
// Quit is the server's quit channel. If this is closed, we halt operation.
Quit chan struct{}
}
@@ -512,6 +517,14 @@ 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.
//
// TODO(roasbeef): extend w/ source peer info?
msgRouter := cfg.MsgRouter.Alt(
fn.Some[MsgRouter](NewMultiMsgRouter()),
)
p := &Brontide{
cfg: cfg,
activeSignal: make(chan struct{}),
@@ -534,7 +547,7 @@ func NewBrontide(cfg Config) *Brontide {
startReady: make(chan struct{}),
quit: make(chan struct{}),
log: build.NewPrefixLog(logPrefix, peerLog),
msgRouter: fn.Some[MsgRouter](NewMultiMsgRouter()),
msgRouter: msgRouter,
}
var (

View File

@@ -3912,6 +3912,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())