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

Function connect_direct

plugins/fetchinvoice.c:890–946  ·  view source on GitHub ↗

We can't find a route, so we're going to try to connect, then just blast it * to them. */

Source from the content-addressed store, hash-verified

888/* We can't find a route, so we're going to try to connect, then just blast it
889 * to them. */
890static struct command_result *
891connect_direct(struct command *cmd,
892 const struct point32 *dst,
893 enum nodeid_parity parity,
894 struct command_result *(*cb)(struct command *command,
895 const char *buf,
896 const jsmntok_t *result,
897 struct sent *sent),
898 struct sent *sent)
899{
900 struct out_req *req;
901 struct connect_attempt *ca = tal(cmd, struct connect_attempt);
902
903 ca->cb = cb;
904 ca->sent = sent;
905
906 if (parity == nodeid_parity_unknown) {
907 plugin_notify_message(cmd, LOG_INFORM,
908 "Cannot find route, trying connect to 02/03%s directly",
909 type_to_string(tmpctx, struct point32, dst));
910 /* Try even first. */
911 node_id_from_point32(&ca->node_id, dst, SECP256K1_TAG_PUBKEY_EVEN);
912 } else {
913 plugin_notify_message(cmd, LOG_INFORM,
914 "Cannot find route, trying connect to %02x%s directly",
915 parity,
916 type_to_string(tmpctx, struct point32, dst));
917 node_id_from_point32(&ca->node_id, dst, parity);
918 }
919
920 /* Make a direct path -> dst. */
921 sent->path = tal_arr(sent, struct pubkey, 2);
922 sent->path[0] = local_id;
923 if (!pubkey_from_node_id(&sent->path[1], &ca->node_id)) {
924 /* Should not happen! */
925 return command_done_err(cmd, LIGHTNINGD,
926 "Failed: could not convert to pubkey?",
927 NULL);
928 }
929
930 if (disable_connect) {
931 /* FIXME: This means we will fail if parity is wrong! */
932 plugin_notify_message(cmd, LOG_UNUSUAL,
933 "Cannot find route, but"
934 " fetchplugin-noconnect set:"
935 " trying direct anyway to %s",
936 type_to_string(tmpctx, struct point32,
937 dst));
938 return cb(cmd, NULL, NULL, sent);
939 }
940
941 req = jsonrpc_request_start(cmd->plugin, cmd, "connect", connected,
942 parity == nodeid_parity_unknown ?
943 try_other_parity : connect_failed, ca);
944 json_add_node_id(req->js, "id", &ca->node_id);
945 return send_outreq(cmd->plugin, req);
946}
947

Callers 4

invreq_doneFunction · 0.85
force_payer_secretFunction · 0.85
createinvoice_doneFunction · 0.85
json_rawrequestFunction · 0.85

Calls 7

plugin_notify_messageFunction · 0.85
node_id_from_point32Function · 0.85
command_done_errFunction · 0.85
send_outreqFunction · 0.70
type_to_stringClass · 0.50
pubkey_from_node_idFunction · 0.50
json_add_node_idFunction · 0.50

Tested by

no test coverage detected