implement session cache

This commit is contained in:
postscriptum 2026-03-22 12:30:09 +02:00
parent e5268e49f1
commit 8de35ff3a6
5 changed files with 123 additions and 31 deletions

View file

@ -26,7 +26,7 @@ async fn allow(rule: &str, list: &State<Arc<List>>, totals: &State<Arc<Total>>)
let result = list.allow(rule).await;
totals.set_entries(list.entries().await);
info!("Delete `{rule}` from the in-memory rules (operation status: {result:?})");
Json(result)
Json(result.is_ok_and(|v| v))
}
#[rocket::get("/block/<rule>")]
@ -34,7 +34,7 @@ async fn block(rule: &str, list: &State<Arc<List>>, totals: &State<Arc<Total>>)
let result = list.block(rule).await;
totals.set_entries(list.entries().await);
info!("Add `{rule}` to the in-memory rules (operation status: {result:?})");
Json(result)
Json(result.is_ok_and(|v| v))
}
#[rocket::launch]
@ -44,11 +44,11 @@ async fn rocket() -> _ {
let opt: &'static Opt = Box::leak(Box::new(Opt::from_args()));
let list = Arc::new(
List::from_opt(&opt.allow_list)
List::from_opt(&opt.allow_list, opt.cache.clone())
.await
.map_err(|err| {
error!("Can't parse whitelist: `{err}`");
SocksError::ArgumentInputError("Can't parse whitelist")
error!("Can't parse list: `{err}`");
SocksError::ArgumentInputError("Can't parse list")
})
.unwrap(),
);