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

Function send_modern_message

plugins/fetchinvoice.c:653–722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

651};
652
653static struct command_result *
654send_modern_message(struct command *cmd,
655 struct tlv_onionmsg_payload_reply_path *reply_path,
656 struct sending *sending)
657{
658 struct sent *sent = sending->sent;
659 struct privkey blinding_iter;
660 struct pubkey fwd_blinding, *node_alias;
661 size_t nhops = tal_count(sent->path);
662 struct tlv_onionmsg_payload **payloads;
663 struct out_req *req;
664
665 /* Now create enctlvs for *forward* path. */
666 randombytes_buf(&blinding_iter, sizeof(blinding_iter));
667 if (!pubkey_from_privkey(&blinding_iter, &fwd_blinding))
668 return command_fail(cmd, LIGHTNINGD,
669 "Could not convert blinding %s to pubkey!",
670 type_to_string(tmpctx, struct privkey,
671 &blinding_iter));
672
673 /* We overallocate: this node (0) doesn't have payload or alias */
674 payloads = tal_arr(cmd, struct tlv_onionmsg_payload *, nhops);
675 node_alias = tal_arr(cmd, struct pubkey, nhops);
676
677 for (size_t i = 1; i < nhops - 1; i++) {
678 payloads[i] = tlv_onionmsg_payload_new(payloads);
679 payloads[i]->encrypted_data_tlv = create_enctlv(payloads[i],
680 &blinding_iter,
681 &sent->path[i],
682 &sent->path[i+1],
683 /* FIXME: Pad? */
684 0,
685 NULL,
686 &blinding_iter,
687 &node_alias[i]);
688 }
689 /* Final payload contains the actual data. */
690 payloads[nhops-1] = sending->payload;
691
692 /* We don't include enctlv in final, but it gives us final alias */
693 if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1],
694 /* FIXME: Pad? */ 0,
695 NULL,
696 &node_alias[nhops-1])) {
697 /* Should not happen! */
698 return command_fail(cmd, LIGHTNINGD,
699 "Could create final enctlv");
700 }
701
702 payloads[nhops-1]->reply_path = reply_path;
703
704 req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage",
705 sending->done,
706 forward_error,
707 sending->sent);
708 json_add_pubkey(req->js, "first_id", &sent->path[1]);
709 json_add_pubkey(req->js, "blinding", &fwd_blinding);
710 json_array_start(req->js, "hops");

Callers 1

use_reply_pathFunction · 0.85

Calls 12

pubkey_from_privkeyFunction · 0.85
create_enctlvFunction · 0.85
create_final_enctlvFunction · 0.85
json_add_pubkeyFunction · 0.85
command_failFunction · 0.70
send_outreqFunction · 0.70
type_to_stringClass · 0.50
json_array_startFunction · 0.50
json_object_startFunction · 0.50
json_add_hex_talarrFunction · 0.50
json_object_endFunction · 0.50
json_array_endFunction · 0.50

Tested by

no test coverage detected