use proper enum return type

This commit is contained in:
Pierre Dubouilh
2021-10-17 20:49:37 +02:00
parent 283653a775
commit 4d2aee5178
5 changed files with 73 additions and 29 deletions
+5 -3
View File
@@ -5,6 +5,8 @@ use std::sync::Mutex;
use anyhow::*;
use crate::utils::JailStatus;
pub struct Jail {
jailtime: u32,
allowance: u8,
@@ -91,7 +93,7 @@ impl Jail {
})
}
pub fn probe(&self, ip: IpAddr) -> Result<bool> {
pub fn probe(&self, ip: IpAddr) -> Result<JailStatus> {
let should_ban = {
let mut locked_map = self.remand.lock().map_err(|_| anyhow!("cant lock"))?;
@@ -108,9 +110,9 @@ impl Jail {
if should_ban {
ipset_block(self.jailtime, ip)?;
Ok(true)
Ok(JailStatus::Jailed(ip))
} else {
Ok(false)
Ok(JailStatus::Remand)
}
}
}