mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
disconnect: add force option to disconnect even with a live channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4b77d803ef
commit
19ecf8c6fb
2 changed files with 12 additions and 3 deletions
|
@ -480,12 +480,13 @@ class LightningRpc(UnixDomainSocketRpc):
|
|||
payload={"id": peerid, "force": force}
|
||||
)
|
||||
|
||||
def disconnect(self, peer_id):
|
||||
def disconnect(self, peer_id, force=False):
|
||||
"""
|
||||
Disconnect from peer with {peer_id}
|
||||
Disconnect from peer with {peer_id}, optional {force} even if has active channel
|
||||
"""
|
||||
payload = {
|
||||
"id": peer_id,
|
||||
"force": force,
|
||||
}
|
||||
return self.call("disconnect", payload)
|
||||
|
||||
|
|
|
@ -1044,9 +1044,11 @@ static void json_disconnect(struct command *cmd,
|
|||
struct pubkey *id;
|
||||
struct peer *peer;
|
||||
struct channel *channel;
|
||||
bool *force;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("id", json_tok_pubkey, &id),
|
||||
p_opt_def("force", json_tok_bool, &force, false),
|
||||
NULL))
|
||||
return;
|
||||
|
||||
|
@ -1057,6 +1059,12 @@ static void json_disconnect(struct command *cmd,
|
|||
}
|
||||
channel = peer_active_channel(peer);
|
||||
if (channel) {
|
||||
if (*force) {
|
||||
channel_fail_transient(channel,
|
||||
"disconnect command force=true");
|
||||
command_success(cmd, null_response(cmd));
|
||||
return;
|
||||
}
|
||||
command_fail(cmd, LIGHTNINGD, "Peer is in state %s",
|
||||
channel_state_name(channel));
|
||||
return;
|
||||
|
@ -1073,7 +1081,7 @@ static void json_disconnect(struct command *cmd,
|
|||
static const struct json_command disconnect_command = {
|
||||
"disconnect",
|
||||
json_disconnect,
|
||||
"Disconnect from {id} that has previously been connected to using connect"
|
||||
"Disconnect from {id} that has previously been connected to using connect; with {force} set, even if it has a current channel"
|
||||
};
|
||||
AUTODATA(json_command, &disconnect_command);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue