MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_onion_message

Function handle_onion_message

connectd/onion_message.c:39–186  ·  view source on GitHub ↗

Peer sends an onion msg. */

Source from the content-addressed store, hash-verified

37
38/* Peer sends an onion msg. */
39void handle_onion_message(struct daemon *daemon,
40 struct peer *peer, const u8 *msg)
41{
42 enum onion_wire badreason;
43 struct onionpacket *op;
44 struct pubkey blinding, ephemeral;
45 struct route_step *rs;
46 u8 *onion;
47 struct tlv_onionmsg_payload *om;
48 struct secret ss, onion_ss;
49 const u8 *cursor;
50 size_t max, maxlen;
51
52 /* Ignore unless explicitly turned on. */
53 if (!feature_offered(daemon->our_features->bits[NODE_ANNOUNCE_FEATURE],
54 OPT_ONION_MESSAGES))
55 return;
56
57 /* FIXME: ratelimit! */
58 if (!fromwire_onion_message(msg, msg, &blinding, &onion)) {
59 inject_peer_msg(peer,
60 towire_warningfmt(NULL, NULL,
61 "Bad onion_message"));
62 return;
63 }
64
65 /* We unwrap the onion now. */
66 op = parse_onionpacket(tmpctx, onion, tal_bytelen(onion), &badreason);
67 if (!op) {
68 status_peer_debug(&peer->id, "onion msg: can't parse onionpacket: %s",
69 onion_wire_name(badreason));
70 return;
71 }
72
73 ephemeral = op->ephemeralkey;
74 if (!unblind_onion(&blinding, ecdh, &ephemeral, &ss)) {
75 status_peer_debug(&peer->id, "onion msg: can't unblind onionpacket");
76 return;
77 }
78
79 /* Now get onion shared secret and parse it. */
80 ecdh(&ephemeral, &onion_ss);
81 rs = process_onionpacket(tmpctx, op, &onion_ss, NULL, 0, false);
82 if (!rs) {
83 status_peer_debug(&peer->id,
84 "onion msg: can't process onionpacket ss=%s",
85 type_to_string(tmpctx, struct secret, &onion_ss));
86 return;
87 }
88
89 /* The raw payload is prepended with length in the modern onion. */
90 cursor = rs->raw_payload;
91 max = tal_bytelen(rs->raw_payload);
92 maxlen = fromwire_bigsize(&cursor, &max);
93 if (!cursor) {
94 status_peer_debug(&peer->id, "onion msg: Invalid hop payload %s",
95 tal_hex(tmpctx, rs->raw_payload));
96 return;

Callers 1

handle_message_locallyFunction · 0.85

Calls 15

inject_peer_msgFunction · 0.85
tal_bytelenFunction · 0.85
onion_wire_nameFunction · 0.85
unblind_onionFunction · 0.85
tal_hexFunction · 0.85
decrypt_final_enctlvFunction · 0.85
towire_tlvstream_rawFunction · 0.85
decrypt_enctlvFunction · 0.85
node_id_from_pubkeyFunction · 0.85
feature_offeredFunction · 0.50
towire_warningfmtFunction · 0.50
parse_onionpacketFunction · 0.50

Tested by

no test coverage detected