| 806 | } |
| 807 | |
| 808 | static 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 |
nothing calls this directly
no test coverage detected