multi: endpoints for onion messages

This commit creates the necessary endpoints for onion messages.
Specifically, it adds the following:

- `SendOnionMessage` endpoint to send onion messages.
- `SubscribeOnionMessages` endpoint to subscribe to incoming onion
  messages.

It uses the `msgmux` package to handle the onion messages.
This commit is contained in:
Gijs van Dam authored and yyforyongyu committed 2025-11-12 22:54:04 +08:00
1 parent 2ee0702942
commit 07dc74e198
9 files changed
+398

No files matched your search

+20
View File
@@ -47,6 +47,7 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/msgmux"
"github.com/lightningnetwork/lnd/netann"
"github.com/lightningnetwork/lnd/onionmessage"
"github.com/lightningnetwork/lnd/pool"
"github.com/lightningnetwork/lnd/protofsm"
"github.com/lightningnetwork/lnd/queue"
@@ -463,6 +464,10 @@ type Config struct {
// related wire messages.
AuxChannelNegotiator fn.Option[lnwallet.AuxChannelNegotiator]
// OnionMessageServer is an instance of a message server that dispatches
// onion messages to subscribers.
OnionMessageServer *subscribe.Server
// ShouldFwdExpEndorsement is a closure that indicates whether
// experimental endorsement signals should be set.
ShouldFwdExpEndorsement func() bool
@@ -898,6 +903,21 @@ func (p *Brontide) Start() error {
return fmt.Errorf("unable to load channels: %w", err)
}
onionMessageEndpoint := onionmessage.NewOnionEndpoint(
p.cfg.OnionMessageServer,
)
// We register the onion message endpoint with the message router.
err = fn.MapOptionZ(p.msgRouter, func(r msgmux.Router) error {
_ = r.UnregisterEndpoint(onionMessageEndpoint.Name())
return r.RegisterEndpoint(onionMessageEndpoint)
})
if err != nil {
return fmt.Errorf("unable to register endpoint for onion "+
"messaging: %w", err)
}
p.startTime = time.Now()
// Before launching the writeHandler goroutine, we send any channel