From d3a9d5d3ebff98e342dff1df0ebad86f346719f5 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 19 Oct 2026 23:44:20 +0200 Subject: initial commit --- src/api/debug.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/api/debug.rs (limited to 'src/api/debug.rs') diff --git a/src/api/debug.rs b/src/api/debug.rs new file mode 100644 index 0000000..3c24f62 --- /dev/null +++ b/src/api/debug.rs @@ -0,0 +1,41 @@ +//! /debug/* handlers (only routed with --debug-api). + +use std::collections::HashSet; + +use axum::{body::Bytes, extract::State, http::StatusCode, Json}; +use tracing::{info, warn}; + +use crate::firewall::FirewallRules; +use crate::state::AppState; + +pub(crate) async fn get_debug_firewall(State(state): State) -> Json { + Json(state.firewall.rules()) +} + +pub(crate) async fn put_debug_firewall( + State(state): State, + Json(rules): Json, +) -> StatusCode { + info!(inbound = ?rules.inbound, outbound = ?rules.outbound, "Firewall rules replaced"); + state.firewall.set_rules(rules); + StatusCode::NO_CONTENT +} + +/// Compatibility for the existing harness: block a set of peers in both directions. +/// Parses the body without requiring a Content-Type header, as before. +pub(crate) async fn put_debug_blacklist(State(state): State, body: Bytes) -> StatusCode { + match serde_json::from_slice::>(&body) { + Ok(peers) => { + info!(peers = ?peers, "Blacklist replaced (both directions)"); + state.firewall.set_rules(FirewallRules { + inbound: peers.clone(), + outbound: peers, + }); + StatusCode::NO_CONTENT + } + Err(error) => { + warn!(error = %error, "Invalid blacklist body"); + StatusCode::BAD_REQUEST + } + } +} -- cgit v1.3.1