2021-03-07 11:49:52 +05:30
|
|
|
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);
|
2021-03-07 11:49:52 +05:30
|
|
|
|
|
|
|
/// 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);
|
2021-03-07 11:49:52 +05:30
|
|
|
|
|
|
|
/// 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>();
|
|
|
|
|
2021-03-07 11:49:52 +05:30
|
|
|
PoWConfig {
|
2021-03-07 19:54:41 +05:30
|
|
|
string,
|
|
|
|
difficulty_factor: m,
|
2021-03-07 11:49:52 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|