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.
This commit is contained in:
Olaoluwa Osuntokun 2024-01-30 18:00:11 -08:00 committed by Oliver Gugger
parent ba6f01d48b
commit fbbd8df487
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

@ -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