Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/4] - peer: add new abstract message router #8520

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
Expand All @@ -42,6 +43,7 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
"github.com/lightningnetwork/lnd/lnwallet/rpcwallet"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/msgmux"
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sqldb"
Expand Down Expand Up @@ -118,6 +120,14 @@ type ChainControlBuilder interface {
*btcwallet.Config) (*chainreg.ChainControl, func(), error)
}

// AuxComponents is a set of auxiliary components that can be used by lnd for
// certain custom channel types.
type AuxComponents struct {
// MsgRouter is an optional message router that if set will be used in
// place of a new blank default message router.
MsgRouter fn.Option[msgmux.Router]
}

// ImplementationCfg is a struct that holds all configuration items for
// components that can be implemented outside lnd itself.
type ImplementationCfg struct {
Expand All @@ -144,6 +154,10 @@ type ImplementationCfg struct {
// ChainControlBuilder is a type that can provide a custom wallet
// implementation.
ChainControlBuilder

// AuxComponents is a set of auxiliary components that can be used by
// lnd for certain custom channel types.
AuxComponents
}

// DefaultWalletImpl is the default implementation of our normal, btcwallet
Expand Down
1 change: 1 addition & 0 deletions lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
cfg, cfg.Listeners, dbs, activeChainControl, &idKeyDesc,
activeChainControl.Cfg.WalletUnlockParams.ChansToRestore,
multiAcceptor, torController, tlsManager, leaderElector,
implCfg,
)
if err != nil {
return mkErr("unable to create server: %v", err)
Expand Down
15 changes: 12 additions & 3 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ type Config struct {
// This value will be passed to created links.
MaxFeeExposure lnwire.MilliSatoshi

// 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[msgmux.Router]

// Quit is the server's quit channel. If this is closed, we halt operation.
Quit chan struct{}
}
Expand Down Expand Up @@ -542,6 +547,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[msgmux.Router](
msgmux.NewMultiMsgRouter(),
))
Comment on lines +560 to +564
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😘👌🏼


p := &Brontide{
cfg: cfg,
activeSignal: make(chan struct{}),
Expand All @@ -564,9 +575,7 @@ func NewBrontide(cfg Config) *Brontide {
startReady: make(chan struct{}),
quit: make(chan struct{}),
log: build.NewPrefixLog(logPrefix, peerLog),
msgRouter: fn.Some[msgmux.Router](
msgmux.NewMultiMsgRouter(),
),
msgRouter: msgRouter,
}

if cfg.Conn != nil && cfg.Conn.RemoteAddr() != nil {
Expand Down
7 changes: 6 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ type server struct {

cfg *Config

implCfg *ImplementationCfg

// identityECDH is an ECDH capable wrapper for the private key used
// to authenticate any incoming connections.
identityECDH keychain.SingleKeyECDH
Expand Down Expand Up @@ -486,7 +488,8 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
chansToRestore walletunlocker.ChannelsToRecover,
chanPredicate chanacceptor.ChannelAcceptor,
torController *tor.Controller, tlsManager *TLSManager,
leaderElector cluster.LeaderElector) (*server, error) {
leaderElector cluster.LeaderElector,
implCfg *ImplementationCfg) (*server, error) {

var (
err error
Expand Down Expand Up @@ -571,6 +574,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,

s := &server{
cfg: cfg,
implCfg: implCfg,
graphDB: dbs.GraphDB.ChannelGraph(),
chanStateDB: dbs.ChanStateDB.ChannelStateDB(),
addrSource: dbs.ChanStateDB,
Expand Down Expand Up @@ -3986,6 +3990,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
DisallowRouteBlinding: s.cfg.ProtocolOptions.NoRouteBlinding(),
MaxFeeExposure: thresholdMSats,
Quit: s.quit,
MsgRouter: s.implCfg.MsgRouter,
}

copy(pCfg.PubKeyBytes[:], peerAddr.IdentityKey.SerializeCompressed())
Expand Down