• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 16170852573

09 Jul 2025 01:36PM UTC coverage: 68.199% (+10.6%) from 57.62%
16170852573

Pull #9868

github

web-flow
Merge e5726a7be into ea32aac77
Pull Request #9868: PoC Onion messaging using `msgmux`

169 of 228 new or added lines in 10 files covered. (74.12%)

17 existing lines in 3 files now uncovered.

137361 of 201411 relevant lines covered (68.2%)

21720.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/onion_message/onion_endpoint.go
1
package onion_message
2

3
import (
4
        "context"
5

6
        "github.com/lightningnetwork/lnd/lnwire"
7
        "github.com/lightningnetwork/lnd/msgmux"
8
        "github.com/lightningnetwork/lnd/subscribe"
9
)
10

11
// OnionEndpoint handles incoming onion messages.
12
type OnionEndpoint struct {
13
        // subscribe.Server is used for subscriptions to onion messages.
14
        onionMessageServer *subscribe.Server
15
}
16

17
// OnionMessageUpdate is onion message update dispatched to any potential
18
// subscriber.
19
type OnionMessageUpdate struct {
20
        // Peer is the peer pubkey
21
        Peer [33]byte
22

23
        // BlindingPoint is the route blinding ephemeral pubkey to be used for
24
        // the onion message.
25
        BlindingPoint []byte
26

27
        // OnionBlob is the raw serialized mix header used to relay messages in
28
        // a privacy-preserving manner. This blob should be handled in the same
29
        // manner as onions used to route HTLCs, with the exception that it uses
30
        // blinded routes by default.
31
        OnionBlob []byte
32
}
33

34
// NewOnionEndpoint creates a new OnionEndpoint.
35
func NewOnionEndpoint(messageServer *subscribe.Server) *OnionEndpoint {
6✔
36
        return &OnionEndpoint{
6✔
37
                onionMessageServer: messageServer,
6✔
38
        }
6✔
39
}
6✔
40

41
// Name returns the unique name of the endpoint.
42
func (o *OnionEndpoint) Name() string {
15✔
43
        return "OnionMessageHandler"
15✔
44
}
15✔
45

46
// CanHandle checks if the endpoint can handle the incoming message.
47
// It returns true if the message is an lnwire.OnionMessage.
48
func (o *OnionEndpoint) CanHandle(msg msgmux.PeerMsg) bool {
4✔
49
        _, ok := msg.Message.(*lnwire.OnionMessage)
4✔
50
        return ok
4✔
51
}
4✔
52

53
// SendMessage processes the incoming onion message.
54
// It returns true if the message was successfully processed.
55
func (o *OnionEndpoint) SendMessage(ctx context.Context,
56
        msg msgmux.PeerMsg) bool {
3✔
57

3✔
58
        onionMsg, ok := msg.Message.(*lnwire.OnionMessage)
3✔
59
        if !ok {
3✔
NEW
60
                return false
×
NEW
61
        }
×
62

63
        peer := msg.PeerPub.SerializeCompressed()
3✔
64
        log.Debugf("OnionEndpoint received OnionMessage from peer %s: "+
3✔
65
                "BlindingPoint=%v, OnionPacket[:10]=%x...", peer,
3✔
66
                onionMsg.BlindingPoint, onionMsg.OnionBlob)
3✔
67

3✔
68
        var peerArr [33]byte
3✔
69
        copy(peerArr[:], peer)
3✔
70
        err := o.onionMessageServer.SendUpdate(&OnionMessageUpdate{
3✔
71
                Peer:          peerArr,
3✔
72
                BlindingPoint: onionMsg.BlindingPoint.SerializeCompressed(),
3✔
73
                OnionBlob:     onionMsg.OnionBlob,
3✔
74
        })
3✔
75
        if err != nil {
3✔
NEW
76
                log.Errorf("Failed to send onion message update: %v", err)
×
NEW
77
                return false
×
NEW
78
        }
×
79

80
        return true
3✔
81
}
82

83
// A compile-time check to ensure OnionEndpoint implements the Endpoint
84
// interface.
85
var _ msgmux.Endpoint = (*OnionEndpoint)(nil)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc