summaryrefslogtreecommitdiffstats
path: root/src/api/peers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/peers.rs')
-rw-r--r--src/api/peers.rs12
1 files changed, 7 insertions, 5 deletions
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<String>,
}
#[utoipa::path(
@@ -197,12 +197,12 @@ pub(crate) async fn list_peers(
tag = "Peers",
params(
("peer" = String, Path, description = "Peer public key"),
- ("force" = Option<bool>, Query, description = "Also forget a peer that is currently alive; it returns on its next message")
+ ("force" = Option<String>, 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);
}