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

Function handle_onion

connectd/onion_message.c:35–133  ·  view source on GitHub ↗

Source is NULL if we're injecting, otherwise it's a forward */

Source from the content-addressed store, hash-verified

33
34/* Source is NULL if we're injecting, otherwise it's a forward */
35static const char *handle_onion(const tal_t *ctx,
36 struct daemon *daemon,
37 const struct node_id *source,
38 const struct pubkey *path_key,
39 const u8 *onion)
40{
41 u8 *next_onion_msg;
42 struct sciddir_or_pubkey next_node;
43 struct tlv_onionmsg_tlv *final_om;
44 struct pubkey final_alias;
45 struct secret *final_path_id;
46 const char *err;
47
48 err = onion_message_parse(tmpctx, onion, path_key,
49 &daemon->mykey,
50 &next_onion_msg, &next_node,
51 &final_om, &final_alias, &final_path_id);
52 if (err) {
53 if (source) {
54 daemon_conn_send(daemon->master,
55 take(towire_connectd_onionmsg_forward_fail(NULL,
56 source,
57 onion,
58 path_key,
59 NULL,
60 NULL)));
61 }
62 return tal_steal(ctx, err);
63 }
64
65 if (final_om) {
66 u8 *omsg;
67
68 /* We re-marshall here by policy, before handing to lightningd */
69 omsg = tal_arr(tmpctx, u8, 0);
70 towire_tlvstream_raw(&omsg, final_om->fields);
71 daemon_conn_send(daemon->master,
72 take(towire_connectd_got_onionmsg_to_us(NULL,
73 final_path_id,
74 final_om->reply_path,
75 omsg)));
76 } else {
77 struct node_id next_node_id;
78 struct peer *next_peer;
79
80 assert(next_onion_msg);
81
82 /* BOLT #4:
83 * - if it is not the final node according to the onion encryption:
84 *...
85 * - if `next_node_id` is present:
86 * - the *next peer* is the peer with that node id.
87 * - otherwise, if `short_channel_id` is present and corresponds to an announced short_channel_id or a local alias for a channel:
88 * - the *next peer* is the peer at the other end of that channel.
89 * - otherwise:
90 * - MUST ignore the message.
91 * - SHOULD forward the message using `onion_message` to the *next peer*.
92 */

Callers 2

handle_onion_messageFunction · 0.85
inject_onionmsg_reqFunction · 0.85

Calls 7

onion_message_parseFunction · 0.85
daemon_conn_sendFunction · 0.85
towire_tlvstream_rawFunction · 0.85
fmt_short_channel_idFunction · 0.85
node_id_from_pubkeyFunction · 0.85
fmt_sciddir_or_pubkeyFunction · 0.85
inject_peer_msgFunction · 0.70

Tested by

no test coverage detected