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

Function json_sendcustommsg

lightningd/connect_control.c:665–724  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663}
664
665static struct command_result *json_sendcustommsg(struct command *cmd,
666 const char *buffer,
667 const jsmntok_t *obj UNNEEDED,
668 const jsmntok_t *params)
669{
670 struct json_stream *response;
671 struct node_id *dest;
672 struct peer *peer;
673 u8 *msg;
674 int type;
675
676 if (!param(cmd, buffer, params,
677 p_req("node_id", param_node_id, &dest),
678 p_req("msg", param_bin_from_hex, &msg),
679 NULL))
680 return command_param_failed();
681
682 type = fromwire_peektype(msg);
683 if (peer_wire_is_defined(type)) {
684 return command_fail(
685 cmd, JSONRPC2_INVALID_REQUEST,
686 "Cannot send messages of type %d (%s). It is not possible "
687 "to send messages that have a type managed internally "
688 "since that might cause issues with the internal state "
689 "tracking.",
690 type, peer_wire_name(type));
691 }
692
693 if (type % 2 == 0) {
694 return command_fail(
695 cmd, JSONRPC2_INVALID_REQUEST,
696 "Cannot send even-typed %d custom message. Currently "
697 "custom messages are limited to odd-numbered message "
698 "types, as even-numbered types might result in "
699 "disconnections.",
700 type);
701 }
702
703 peer = peer_by_id(cmd->ld, dest);
704 if (!peer) {
705 return command_fail(cmd, JSONRPC2_INVALID_REQUEST,
706 "No such peer: %s",
707 type_to_string(cmd, struct node_id, dest));
708 }
709
710 if (peer->connected != PEER_CONNECTED)
711 return command_fail(cmd, JSONRPC2_INVALID_REQUEST,
712 "Peer is %s",
713 peer->connected == PEER_DISCONNECTED
714 ? "not connected" : "still connecting");
715
716 subd_send_msg(cmd->ld->connectd,
717 take(towire_connectd_custommsg_out(cmd, dest, msg)));
718
719 response = json_stream_success(cmd);
720 json_add_string(response, "status",
721 "Message sent to connectd for delivery");
722

Callers

nothing calls this directly

Calls 11

peer_by_idFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
subd_send_msgFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50
fromwire_peektypeFunction · 0.50
peer_wire_nameFunction · 0.50
type_to_stringClass · 0.50
json_add_stringFunction · 0.50

Tested by

no test coverage detected