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

Function outgoing_onion_message

common/onion_message.c:164–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164struct onion_message *outgoing_onion_message(const tal_t *ctx,
165 const struct pubkey *ids,
166 const struct short_channel_id **scids,
167 const struct blinded_path *their_path,
168 struct tlv_onionmsg_tlv *final_tlv STEALS)
169{
170 struct onion_message *omsg;
171 struct blinded_path *our_path;
172 const struct blinded_path *combined_path;
173 struct tlv_encrypted_data_tlv **etlvs = new_encdata_tlvs(tmpctx, ids, scids);
174 struct tlv_onionmsg_tlv **otlvs;
175
176 assert(tal_count(ids) > 0);
177
178 if (their_path) {
179 struct tlv_encrypted_data_tlv *pre_final;
180
181 /* Path must lead to blinded path! */
182 if (their_path->first_node_id.is_pubkey)
183 assert(pubkey_eq(&ids[tal_count(ids)-1], &their_path->first_node_id.pubkey));
184
185 /* If we don't actually have any path, it's all them. */
186 if (tal_count(ids) == 1) {
187 combined_path = their_path;
188 goto wrap;
189 }
190
191 /* We need to tell last hop to hand blinded_path blinding for next hop */
192 pre_final = etlvs[tal_count(ids)-2];
193 pre_final->next_path_key_override = tal_dup(pre_final,
194 struct pubkey,
195 &their_path->first_path_key);
196 }
197
198 our_path = blinded_path_from_encdata_tlvs(tmpctx,
199 cast_const2(const struct tlv_encrypted_data_tlv **, etlvs),
200 ids);
201
202 /* Extend with their blinded path if there is one */
203 if (their_path) {
204 /* Remove final one, since it's actually the first one in blinded path. */
205 tal_resize(&our_path->path, tal_count(our_path->path)-1);
206 for (size_t i = 0; i < tal_count(their_path->path); i++)
207 extend_blinded_path(our_path, their_path->path[i]);
208 }
209
210 combined_path = our_path;
211
212wrap:
213 /* Now wrap in onionmsg_tlvs */
214 otlvs = onionmsg_tlvs_from_blinded_path(tmpctx, combined_path);
215
216 /* Transfer encrypted blob into final tlv, and use it to replace last tlv */
217 final_tlv->encrypted_recipient_data = tal_steal(final_tlv, otlvs[tal_count(otlvs)-1]->encrypted_recipient_data);
218 tal_free(otlvs[tal_count(otlvs)-1]);
219 otlvs[tal_count(otlvs)-1] = tal_steal(otlvs, final_tlv);
220
221 /* Now populate the onion message to return */

Callers 2

establish_path_doneFunction · 0.85

Calls 6

new_encdata_tlvsFunction · 0.85
extend_blinded_pathFunction · 0.85
tal_freeFunction · 0.85
onionmsg_tlvs_to_hopsFunction · 0.85

Tested by

no test coverage detected