From fbbd8df487dcc3de762dd0ddf90efa096f16b11a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 30 Jan 2024 18:00:11 -0800 Subject: [PATCH] peer: update readHandler to dispatch to msgRouter if set Over time with this, we should be able to significantly reduce the size of the peer.Brontide struct as we only need all those deps as the peer needs to recognize and handle each incoming wire message itself. --- peer/brontide.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/peer/brontide.go b/peer/brontide.go index b9a9f68ca..d12c3ce38 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -493,6 +493,10 @@ type Brontide struct { // potentially holding lots of un-consumed events. channelEventClient *subscribe.Client + // msgRouter is an instance of the MsgRouter which is used to send off + // new wire messages for handing. + msgRouter fn.Option[MsgRouter] + startReady chan struct{} quit chan struct{} wg sync.WaitGroup @@ -530,6 +534,7 @@ func NewBrontide(cfg Config) *Brontide { startReady: make(chan struct{}), quit: make(chan struct{}), log: build.NewPrefixLog(logPrefix, peerLog), + msgRouter: fn.Some[MsgRouter](NewMultiMsgRouter()), } var ( @@ -1708,6 +1713,19 @@ out: } } + // If a message router is active, then we'll try to have it + // handle this message. If it can, then we're able to skip the + // rest of the message handling logic. + ok := fn.MapOptionZ(p.msgRouter, func(r MsgRouter) error { + return r.RouteMsg(nextMsg) + }) + + // No error occurred, and the message was handled by the + // router. + if ok == nil { + continue + } + var ( targetChan lnwire.ChannelID isLinkUpdate bool