diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 2932dc4a..d80e49c0 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -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; + + /// 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, } #[derive(Clone, Debug, Default, Deserialize, Serialize)] diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 8637fe90..00557afc 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -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() {