mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-09 13:55:17 +01:00
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:
committed by
Oliver Gugger
parent
6eab09c2a0
commit
b9786e1f20
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user