server_security/security/
mod.rs

1use crate::proxy::ValidateType;
2use once_cell::sync::Lazy;
3use std::collections::HashMap;
4use std::net::SocketAddr;
5use std::sync::RwLock;
6
7static IP_TABLE: Lazy<RwLock<HashMap<String, ()>>> = Lazy::new(Default::default);
8
9pub fn validate(remote_addr: &SocketAddr) -> anyhow::Result<ValidateType> {
10    let remote_ip = remote_addr.ip().to_string();
11    let mut guard = IP_TABLE.write().unwrap();
12
13    // if guard.len() > 0 {
14    //     TODO change configuration
15    // return Err(anyhow::anyhow!("{} not exit error", remote_ip));
16    // }
17
18    if guard.get(&remote_ip).is_some() {
19        return Ok(ValidateType::Normal);
20    }
21
22    guard.insert(remote_ip, ());
23
24    Ok(ValidateType::Normal)
25}