This commit is contained in:
1 parent
0b43530651
commit
217dc5f92b
4 files changed
+14
-25
No files matched your search
@@ -20,13 +20,7 @@ pub async fn cleanup_loop(state: Arc<AppState>) {
|
|||||||
|
|
||||||
// Evict stale rate-limiter entries to prevent unbounded HashMap growth.
|
// Evict stale rate-limiter entries to prevent unbounded HashMap growth.
|
||||||
{
|
{
|
||||||
let window_secs = {
|
let window_secs = state.get_config().rate_limit_window_secs;
|
||||||
if let Ok(config) = state.config.read() {
|
|
||||||
config.rate_limit_window_secs
|
|
||||||
} else {
|
|
||||||
10 // fallback default
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let mut rl = state.rate_limiter.lock().await;
|
let mut rl = state.rate_limiter.lock().await;
|
||||||
rl.evict_stale(window_secs);
|
rl.evict_stale(window_secs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,8 @@ pub async fn handler(
|
|||||||
// Rate limiting
|
// Rate limiting
|
||||||
{
|
{
|
||||||
let (limit, window_secs) = {
|
let (limit, window_secs) = {
|
||||||
if let Ok(cfg) = state.config.read() {
|
let cfg = state.get_config();
|
||||||
(cfg.rate_limit_count, cfg.rate_limit_window_secs)
|
(cfg.rate_limit_count, cfg.rate_limit_window_secs)
|
||||||
} else {
|
|
||||||
(5, 10)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let mut rl = state.rate_limiter.lock().await;
|
let mut rl = state.rate_limiter.lock().await;
|
||||||
if !rl.check(&payload.session_id, limit, window_secs) {
|
if !rl.check(&payload.session_id, limit, window_secs) {
|
||||||
@@ -29,13 +26,7 @@ pub async fn handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = {
|
let config = state.get_config();
|
||||||
if let Ok(cfg) = state.config.read() {
|
|
||||||
cfg.clone()
|
|
||||||
} else {
|
|
||||||
crate::config::Config::default()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let conn = match state.db_pool.get() {
|
let conn = match state.db_pool.get() {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -8,13 +8,7 @@ pub async fn handler(
|
|||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Json(payload): Json<InitRequest>,
|
Json(payload): Json<InitRequest>,
|
||||||
) -> Result<Json<InitResponse>, SessionError> {
|
) -> Result<Json<InitResponse>, SessionError> {
|
||||||
let config = {
|
let config = state.get_config();
|
||||||
if let Ok(cfg) = state.config.read() {
|
|
||||||
cfg.clone()
|
|
||||||
} else {
|
|
||||||
crate::config::Config::default()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let conn = state.db_pool.get()?;
|
let conn = state.db_pool.get()?;
|
||||||
let resp = crate::session::create_session(&conn, &config, &payload.public_key)?;
|
let resp = crate::session::create_session(&conn, &config, &payload.public_key)?;
|
||||||
Ok(Json(resp))
|
Ok(Json(resp))
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ pub struct AppState {
|
|||||||
pub config: std::sync::RwLock<crate::config::Config>,
|
pub config: std::sync::RwLock<crate::config::Config>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
pub fn get_config(&self) -> crate::config::Config {
|
||||||
|
if let Ok(cfg) = self.config.read() {
|
||||||
|
cfg.clone()
|
||||||
|
} else {
|
||||||
|
crate::config::Config::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use crate::{crypto, fingerprint, storage, trust, vm};
|
use crate::{crypto, fingerprint, storage, trust, vm};
|
||||||
use rusqlite::params;
|
use rusqlite::params;
|
||||||
use shared::protocol::{HeartbeatRequest, InitResponse};
|
use shared::protocol::{HeartbeatRequest, InitResponse};
|
||||||
|
|||||||
Reference in new issue
Block a user