From 714debc94b0ef2b543949241f1eb04ae5738ad0c Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2026 13:39:44 +0100 Subject: add force module usable by API and CLI --- src/api/peers.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/api') diff --git a/src/api/peers.rs b/src/api/peers.rs index 919f187..dc4bd3b 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -100,8 +100,8 @@ pub(crate) struct PeerListResponse { #[derive(Debug, Deserialize)] pub(crate) struct DeletePeerQuery { - #[serde(default)] - force: bool, + /// The checks to override (`force`): `alive`. + force: Option, } #[utoipa::path( @@ -197,12 +197,12 @@ pub(crate) async fn list_peers( tag = "Peers", params( ("peer" = String, Path, description = "Peer public key"), - ("force" = Option, Query, description = "Also forget a peer that is currently alive; it returns on its next message") + ("force" = Option, Query, description = "`true` or `alive`: also forget a peer that is currently alive; it returns on its next message") ), responses( (status = 204, description = "Swarm-wide forget recorded"), (status = 400, description = "Not a public key, or the local node's own key"), - (status = 409, description = "Peer is alive; pass force=true"), + (status = 409, description = "Peer is alive; pass force=alive"), (status = 503, description = "Node is not ready") ) )] @@ -217,6 +217,8 @@ pub(crate) async fn delete_peer( if peer.is_empty() || peer == state.local_id() { return Err(StatusCode::BAD_REQUEST); } + let force = crate::force::Force::parse(query.force.as_deref(), &["alive"]) + .map_err(|_| StatusCode::BAD_REQUEST)?; // Unknown locally is fine: other nodes may still know the peer. if let Some(peer_state_mutex) = state.get_peer_state(&peer).await { @@ -224,7 +226,7 @@ pub(crate) async fn delete_peer( .lock() .await .is_alive(&state.timing, Instant::now()) - && !query.force + && !force.allows("alive") { return Err(StatusCode::CONFLICT); } -- cgit v1.3.1