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

Function peer_connected

plugins/chanbackup.c:738–785  ·  view source on GitHub ↗

We use the hook here, since we want to send data to peer before any * reconnect messages (which might make it hang up!) */

Source from the content-addressed store, hash-verified

736/* We use the hook here, since we want to send data to peer before any
737 * reconnect messages (which might make it hang up!) */
738static struct command_result *peer_connected(struct command *cmd,
739 const char *buf,
740 const jsmntok_t *params)
741{
742 struct node_id *node_id;
743 struct out_req *req;
744 u8 *serialise_scb;
745 const char *err;
746 u8 *features;
747 struct chanbackup *cb = chanbackup(cmd->plugin);
748
749 serialise_scb = towire_peer_storage(cmd,
750 get_file_data(tmpctx, cmd->plugin));
751 node_id = tal(cmd, struct node_id);
752 err = json_scan(cmd, buf, params,
753 "{peer:{id:%,features:%}}",
754 JSON_SCAN(json_to_node_id, node_id),
755 JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &features));
756 if (err) {
757 plugin_err(cmd->plugin,
758 "peer_connected hook did not scan %s: %.*s",
759 err, json_tok_full_len(params),
760 json_tok_full(buf, params));
761 }
762
763 /* We shouldn't have to check, but LND hangs up? */
764 if (!feature_offered(features, OPT_PROVIDE_STORAGE)) {
765 return command_hook_success(cmd);
766 }
767
768 /* Remember this peer for future sends */
769 if (!peer_map_get(cb->peers, node_id))
770 peer_map_add(cb->peers, tal_dup(cb->peers, struct node_id, node_id));
771
772 if (!cb->send_our_peer_backup)
773 return send_peers_scb(cmd, node_id);
774
775 req = jsonrpc_request_start(cmd,
776 "sendcustommsg",
777 peer_after_send_scb,
778 peer_after_send_scb_failed,
779 node_id);
780
781 json_add_node_id(req->js, "node_id", node_id);
782 json_add_hex_talarr(req->js, "msg", serialise_scb);
783
784 return send_outreq(req);
785}
786
787static struct command_result *failed_peer_restore(struct command *cmd,
788 struct node_id *node_id,

Callers

nothing calls this directly

Calls 12

get_file_dataFunction · 0.85
feature_offeredFunction · 0.85
send_peers_scbFunction · 0.85
json_add_node_idFunction · 0.85
json_add_hex_talarrFunction · 0.85
chanbackupFunction · 0.70
plugin_errFunction · 0.70
command_hook_successFunction · 0.70
send_outreqFunction · 0.70
json_scanFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected