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

Function send_to_peers

plugins/chanbackup.c:603–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

601}
602
603static struct command_result *send_to_peers(struct command *cmd)
604{
605 struct out_req *req;
606 size_t *idx = tal(cmd, size_t);
607 u8 *serialise_scb, *data;
608 const struct node_id *peers;
609 struct chanbackup *cb = chanbackup(cmd->plugin);
610
611 if (!cb->send_our_peer_backup)
612 return notification_or_hook_done(cmd);
613
614 /* BOLT #1:
615 * The sender of `peer_storage`:
616 * - MAY send `peer_storage` whenever necessary.
617 * - MUST limit its `blob` to 65531 bytes.
618 * - MUST encrypt the data in a manner that ensures its integrity
619 * upon receipt.
620 * - SHOULD pad the `blob` to ensure its length is always exactly 65531 bytes.
621 */
622 /* FIXME: We do not pad! But this is because LDK doesn't store > 1k anyway */
623 data = get_file_data(tmpctx, cmd->plugin);
624 if (tal_bytelen(data) > 65531) {
625 plugin_log(cmd->plugin, LOG_UNUSUAL,
626 "Peer backup would be %zu bytes. That is too large: disabling peer backups!",
627 tal_bytelen(data));
628 cb->send_our_peer_backup = false;
629 return notification_or_hook_done(cmd);
630 }
631 serialise_scb = towire_peer_storage(cmd, data);
632
633 peers = random_peers(tmpctx, cb);
634 *idx = tal_count(peers);
635 for (size_t i = 0; i < tal_count(peers); i++) {
636 struct info *info = tal(cmd, struct info);
637
638 info->idx = idx;
639 info->node_id = peers[i];
640
641 req = jsonrpc_request_start(cmd,
642 "sendcustommsg",
643 after_send_scb_single,
644 after_send_scb_single_fail,
645 info);
646
647 json_add_node_id(req->js, "node_id", &info->node_id);
648 json_add_hex_talarr(req->js, "msg", serialise_scb);
649 send_outreq(req);
650 }
651
652 if (*idx == 0)
653 return notification_or_hook_done(cmd);
654 return command_still_pending(cmd);
655}
656
657static struct command_result *after_staticbackup(struct command *cmd,
658 const char *method,

Callers 1

after_staticbackupFunction · 0.85

Calls 10

get_file_dataFunction · 0.85
tal_bytelenFunction · 0.85
random_peersFunction · 0.85
json_add_node_idFunction · 0.85
json_add_hex_talarrFunction · 0.85
chanbackupFunction · 0.70
plugin_logFunction · 0.70
send_outreqFunction · 0.70
command_still_pendingFunction · 0.70

Tested by

no test coverage detected