node: notify the peer on manual disconnect so teardown is symmetric

A manual disconnect tore down only the local side and sent the peer nothing, so
the peer kept its session and never re-emitted its tree and filter
announcements; on reconnect it was never re-adopted as a child and its bloom
filter was never recorded. Send the disconnected peer a scoped Disconnect, the
same message graceful shutdown sends to all peers, so both sides tear down and
re-handshake cleanly on the next connection.
This commit is contained in:
Johnathan Corgan
2026-06-12 23:32:56 +00:00
parent 1f457d84f9
commit fd30ab0994
3 changed files with 100 additions and 20 deletions
+3 -3
View File
@@ -12,7 +12,7 @@ use tracing::debug;
pub async fn dispatch(node: &mut Node, command: &str, params: Option<&Value>) -> Response {
match command {
"connect" => connect(node, params).await,
"disconnect" => disconnect(node, params),
"disconnect" => disconnect(node, params).await,
_ => Response::error(format!("unknown command: {command}")),
}
}
@@ -49,7 +49,7 @@ async fn connect(node: &mut Node, params: Option<&Value>) -> Response {
/// Disconnect a peer.
///
/// Params: `{"npub": "npub1..."}`
fn disconnect(node: &mut Node, params: Option<&Value>) -> Response {
async fn disconnect(node: &mut Node, params: Option<&Value>) -> Response {
let Some(params) = params else {
return Response::error("missing params for disconnect");
};
@@ -61,7 +61,7 @@ fn disconnect(node: &mut Node, params: Option<&Value>) -> Response {
debug!(npub = %npub, "API disconnect requested");
match node.api_disconnect(npub) {
match node.api_disconnect(npub).await {
Ok(data) => Response::ok(data),
Err(msg) => Response::error(msg),
}