| 663 | } |
| 664 | |
| 665 | static 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 |
nothing calls this directly
no test coverage detected