mcaptcha decrement by count
This commit is contained in:
parent
afaad883cd
commit
68f95f99c2
2 changed files with 24 additions and 0 deletions
|
@ -264,6 +264,18 @@ pub mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mcaptcha_decrement_by_works() {
|
||||||
|
let mut m = get_mcaptcha();
|
||||||
|
for _ in 0..100 {
|
||||||
|
m.add_visitor();
|
||||||
|
}
|
||||||
|
m.decrement_visitor_by(50);
|
||||||
|
assert_eq!(m.get_visitors(), 50);
|
||||||
|
m.decrement_visitor_by(500);
|
||||||
|
assert_eq!(m.get_visitors(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn counter_defense_tightenup_works() {
|
async fn counter_defense_tightenup_works() {
|
||||||
let addr: MyActor = get_counter().start();
|
let addr: MyActor = get_counter().start();
|
||||||
|
|
|
@ -98,6 +98,18 @@ impl MCaptcha {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// decrements the visitor count by specified count
|
||||||
|
#[inline]
|
||||||
|
pub fn decrement_visitor_by(&mut self, count: u32) {
|
||||||
|
if self.visitor_threshold > 0 {
|
||||||
|
if self.visitor_threshold >= count {
|
||||||
|
self.visitor_threshold -= count;
|
||||||
|
} else {
|
||||||
|
self.visitor_threshold = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// get current difficulty factor
|
/// get current difficulty factor
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_difficulty(&self) -> u32 {
|
pub fn get_difficulty(&self) -> u32 {
|
||||||
|
|
Loading…
Reference in a new issue