feat: define interface to add user's traffic pattern

This commit is contained in:
realaravinth 2022-05-14 18:22:21 +05:30
parent 04b0073d7c
commit 2132ab5791
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 20 additions and 0 deletions

View file

@ -186,6 +186,25 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
/// Get captcha's cooldown period
async fn get_captcha_cooldown(&self, captcha_key: &str) -> DBResult<i32>;
/// Add traffic configuration
async fn add_traffic_pattern(
&self,
username: &str,
captcha_key: &str,
pattern: &TrafficPattern,
) -> DBResult<()>;
}
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
/// User's traffic pattern; used in generating a captcha configuration
pub struct TrafficPattern {
/// average traffic of user's website
pub avg_traffic: u32,
/// the peak traffic that the user's website can handle
pub peak_sustainable_traffic: u32,
/// trafic that bought the user's website down; optional
pub broke_my_site_traffic: Option<u32>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]

View file

@ -23,6 +23,7 @@ pub async fn database_works<'a, T: MCDatabase>(
p: &Register<'a>,
c: &CreateCaptcha<'a>,
l: &[Level],
tp: &TrafficPattern,
) {
assert!(db.ping().await, "ping test");
if db.username_exists(p.username).await.unwrap() {