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

Function json_sendcustommsg

lightningd/connect_control.c:808–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

806}
807
808static struct command_result *json_sendcustommsg(struct command *cmd,
809 const char *buffer,
810 const jsmntok_t *obj UNNEEDED,
811 const jsmntok_t *params)
812{
813 struct json_stream *response;
814 struct node_id *dest;
815 struct peer *peer;
816 u8 *msg;
817 int type;
818
819 if (!param_check(cmd, buffer, params,
820 p_req("node_id", param_node_id, &dest),
821 p_req("msg", param_bin_from_hex, &msg),
822 NULL))
823 return command_param_failed();
824
825 type = fromwire_peektype(msg);
826
827 /* Allow peer_storage and your_peer_storage msgtypes */
828 if (peer_wire_is_internal(type)) {
829 return command_fail(
830 cmd, JSONRPC2_INVALID_REQUEST,
831 "Cannot send messages of type %d (%s). It is not possible "
832 "to send messages that have a type managed internally "
833 "since that might cause issues with the internal state "
834 "tracking.",
835 type, peer_wire_name(type));
836 }
837
838 if (type % 2 == 0) {
839 /* INFO the first time, then DEBUG */
840 static enum log_level level = LOG_INFORM;
841 log_(cmd->ld->log, level, dest, false,
842 "sendcustommsg id=%s sending a custom even message (%u)",
843 cmd->id, type);
844 level = LOG_DBG;
845 }
846
847 peer = peer_by_id(cmd->ld, dest);
848 if (!peer) {
849 return command_fail(cmd, JSONRPC2_INVALID_REQUEST,
850 "No such peer: %s",
851 fmt_node_id(cmd, dest));
852 }
853
854 /* We allow messages from plugins responding to peer_connected hook,
855 * so can be PEER_CONNECTING. */
856 if (peer->connected == PEER_DISCONNECTED)
857 return command_fail(cmd, JSONRPC2_INVALID_REQUEST,
858 "Peer is not connected");
859
860 if (command_check_only(cmd))
861 return command_check_done(cmd);
862
863 subd_send_msg(cmd->ld->connectd,
864 take(towire_connectd_custommsg_out(cmd, dest, msg)));
865

Callers

nothing calls this directly

Calls 14

param_checkFunction · 0.85
fromwire_peektypeFunction · 0.85
peer_wire_is_internalFunction · 0.85
peer_by_idFunction · 0.85
fmt_node_idFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
log_Function · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
subd_send_msgFunction · 0.70
json_stream_successFunction · 0.70

Tested by

no test coverage detected