tmp22/src/cache/mod.rs

54 lines
1.3 KiB
Rust
Raw Normal View History

pub use hashcache::HashCache;
use messages::*;
pub mod hashcache;
pub trait Save: actix::Actor + actix::Handler<Retrive> + actix::Handler<Cache> {}
pub mod messages {
use std::sync::Arc;
use actix::dev::*;
use serde::Serialize;
use crate::errors::*;
/// Message to decrement the visitor count
#[derive(Message)]
#[rtype(result = "CaptchaResult<()>")]
2021-03-07 19:54:41 +05:30
pub struct Cache(pub PoWConfig);
/// Message to decrement the visitor count
#[derive(Message)]
#[rtype(result = "CaptchaResult<Option<u32>>")]
2021-03-07 19:54:41 +05:30
pub struct Retrive(pub String);
/// PoW Config that will be sent to clients for generating PoW
#[derive(Clone, Serialize, Debug)]
pub struct PoWConfig {
pub string: String,
pub difficulty_factor: u32,
}
impl PoWConfig {
2021-03-07 19:54:41 +05:30
pub fn new(m: u32) -> Self {
use std::iter;
use rand::{distributions::Alphanumeric, rngs::ThreadRng, thread_rng, Rng};
let mut rng: ThreadRng = thread_rng();
let string = iter::repeat(())
.map(|()| rng.sample(Alphanumeric))
.map(char::from)
.take(32)
.collect::<String>();
PoWConfig {
2021-03-07 19:54:41 +05:30
string,
difficulty_factor: m,
}
}
}
}