Expand description

Counter actor module that manages defense levels

Usage:

use libmcaptcha::{
    master::embedded::counter::{Counter, AddVisitor},
    MCaptchaBuilder,
    cache::hashcache::HashCache,
    LevelBuilder,
    DefenseBuilder
};
// traits from actix needs to be in scope for starting actor
use actix::prelude::*;

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    // configure defense
    let defense = DefenseBuilder::default()
        // add as many levels as you see fit
        .add_level(
            LevelBuilder::default()
                // visitor_threshold is the threshold/limit at which
                // mCaptcha will adjust difficulty levels
                // it is advisable to set small values for the first
                // levels visitor_threshold and difficulty_factor
                // as this will be the work that clients will be
                // computing when there's no load
                .visitor_threshold(50)
                .difficulty_factor(500)
                .unwrap()
                .build()
                .unwrap(),
        )
        .unwrap()
        .add_level(
            LevelBuilder::default()
                .visitor_threshold(5000)
                .difficulty_factor(50000)
                .unwrap()
                .build()
                .unwrap(),
        )
        .unwrap()
        .build()
        .unwrap();

    // create and start Counter actor
    //let cache = HashCache::default().start();
    let mcaptcha = MCaptchaBuilder::default()
        .defense(defense)
        // leaky bucket algorithm's emission interval
        .duration(30)
        .build()
        .unwrap();

    let counter: Counter = mcaptcha.into();
    let counter = counter.start();

    // increment count when user visits protected routes
    counter.send(AddVisitor).await.unwrap();

    Ok(())
}

Structs