| 3507 | AUTODATA(json_command, &graceful_command); |
| 3508 | |
| 3509 | static struct command_result *json_disconnect(struct command *cmd, |
| 3510 | const char *buffer, |
| 3511 | const jsmntok_t *obj UNNEEDED, |
| 3512 | const jsmntok_t *params) |
| 3513 | { |
| 3514 | struct disconnect_command *dc; |
| 3515 | struct peer *peer; |
| 3516 | struct channel *channel; |
| 3517 | bool *force; |
| 3518 | |
| 3519 | if (!param_check(cmd, buffer, params, |
| 3520 | p_req("id", param_peer, &peer), |
| 3521 | p_opt_def("force", param_bool, &force, false), |
| 3522 | NULL)) |
| 3523 | return command_param_failed(); |
| 3524 | |
| 3525 | if (peer->connected == PEER_DISCONNECTED) { |
| 3526 | return command_fail(cmd, LIGHTNINGD, "Peer not connected"); |
| 3527 | } |
| 3528 | |
| 3529 | channel = peer_any_channel_bystate(peer, channel_state_wants_peercomms, |
| 3530 | NULL); |
| 3531 | if (channel && !*force) { |
| 3532 | return command_fail(cmd, LIGHTNINGD, |
| 3533 | "Peer has (at least one) channel in state %s", |
| 3534 | channel_state_name(channel)); |
| 3535 | } |
| 3536 | |
| 3537 | if (command_check_only(cmd)) |
| 3538 | return command_check_done(cmd); |
| 3539 | |
| 3540 | force_peer_disconnect(cmd->ld, peer, "disconnect command"); |
| 3541 | |
| 3542 | /* Connectd tells us when it's finally disconnected */ |
| 3543 | dc = tal(cmd, struct disconnect_command); |
| 3544 | dc->cmd = cmd; |
| 3545 | dc->id = peer->id; |
| 3546 | list_add_tail(&cmd->ld->disconnect_commands, &dc->list); |
| 3547 | tal_add_destructor(dc, destroy_disconnect_command); |
| 3548 | |
| 3549 | return command_still_pending(cmd); |
| 3550 | } |
| 3551 | |
| 3552 | static const struct json_command disconnect_command = { |
| 3553 | "disconnect", |
nothing calls this directly
no test coverage detected