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

lightningnetwork / lnd / 15257840741

26 May 2025 03:48PM UTC coverage: 58.546% (+0.6%) from 57.977%
15257840741

Pull #9868

github

web-flow
Merge 988f39169 into 93a6ab875
Pull Request #9868: PoC Onion messaging using `msgmux`

138 of 189 new or added lines in 6 files covered. (73.02%)

84 existing lines in 11 files now uncovered.

97533 of 166592 relevant lines covered (58.55%)

1.82 hits per line

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

80.95
/msgmux/onion_endpoint.go
1
package msgmux
2

3
import (
4
        "context"
5

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

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

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

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

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

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

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

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

52
// SendMessage processes the incoming onion message.
53
// It returns true if the message was successfully processed.
54
func (o *OnionEndpoint) SendMessage(ctx context.Context, msg PeerMsg) bool {
3✔
55
        onionMsg, ok := msg.Message.(*lnwire.OnionMessage)
3✔
56
        if !ok {
3✔
NEW
57
                // This should ideally not happen if CanHandle is implemented
×
NEW
58
                // correctly. log.Warnf("OnionEndpoint received
×
NEW
59
                // non-OnionMessage: %T", msg.Message)
×
NEW
60
                return false
×
NEW
61
        }
×
62

63
        peer := msg.PeerPub.SerializeCompressed()
3✔
64
        // TODO: Implement actual onion message processing logic here. For
3✔
65
        // example, you might decrypt the onion packet, forward it, or handle
3✔
66
        // the payload.
3✔
67
        log.Debugf("OnionEndpoint received OnionMessage from peer %s: "+
3✔
68
                "BlindingPoint=%v, OnionPacket[:10]=%x...", peer,
3✔
69
                onionMsg.BlindingPoint, onionMsg.OnionBlob)
3✔
70

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

83
        // For now, we'll just acknowledge that we "handled" it.
84
        // Replace with actual processing success/failure.
85
        _ = onionMsg // Silencing unused variable for now
3✔
86

3✔
87
        return true
3✔
88
}
89

90
// A compile-time check to ensure OnionEndpoint implements the Endpoint
91
// interface.
92
var _ 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