| 861 | } |
| 862 | |
| 863 | static struct command_result *json_sendcustommsg(struct command *cmd, |
| 864 | const char *buffer, |
| 865 | const jsmntok_t *obj UNNEEDED, |
| 866 | const jsmntok_t *params) |
| 867 | { |
| 868 | struct json_stream *response; |
| 869 | struct node_id *dest; |
| 870 | struct peer *peer; |
| 871 | u8 *msg; |
| 872 | int type; |
| 873 | |
| 874 | if (!param_check(cmd, buffer, params, |
| 875 | p_req("node_id", param_node_id, &dest), |
| 876 | p_req("msg", param_bin_from_hex, &msg), |
| 877 | NULL)) |
| 878 | return command_param_failed(); |
| 879 | |
| 880 | type = fromwire_peektype(msg); |
| 881 | |
| 882 | /* Allow peer_storage and your_peer_storage msgtypes */ |
| 883 | if (peer_wire_is_internal(type)) { |
| 884 | return command_fail( |
| 885 | cmd, JSONRPC2_INVALID_REQUEST, |
| 886 | "Cannot send messages of type %d (%s). It is not possible " |
| 887 | "to send messages that have a type managed internally " |
| 888 | "since that might cause issues with the internal state " |
| 889 | "tracking.", |
| 890 | type, peer_wire_name(type)); |
| 891 | } |
| 892 | |
| 893 | if (type % 2 == 0) { |
| 894 | /* INFO the first time, then DEBUG */ |
| 895 | static enum log_level level = LOG_INFORM; |
| 896 | log_(cmd->ld->log, level, dest, false, |
| 897 | "sendcustommsg id=%s sending a custom even message (%u)", |
| 898 | cmd->id, type); |
| 899 | level = LOG_DBG; |
| 900 | } |
| 901 | |
| 902 | peer = peer_by_id(cmd->ld, dest); |
| 903 | if (!peer) { |
| 904 | return command_fail(cmd, JSONRPC2_INVALID_REQUEST, |
| 905 | "No such peer: %s", |
| 906 | fmt_node_id(cmd, dest)); |
| 907 | } |
| 908 | |
| 909 | /* We allow messages from plugins responding to peer_connected hook, |
| 910 | * so can be PEER_CONNECTING. */ |
| 911 | if (peer->connected == PEER_DISCONNECTED) |
| 912 | return command_fail(cmd, JSONRPC2_INVALID_REQUEST, |
| 913 | "Peer is not connected"); |
| 914 | |
| 915 | if (command_check_only(cmd)) |
| 916 | return command_check_done(cmd); |
| 917 | |
| 918 | subd_send_msg(cmd->ld->connectd, |
| 919 | take(towire_connectd_custommsg_out(cmd, dest, msg))); |
| 920 |
nothing calls this directly
no test coverage detected