feat(config): Dynamic min rate calculation
This commit is contained in:
1 file changed
+31
-12
+31
-12
@@ -61,8 +61,10 @@ pub struct Config {
|
|||||||
pub download_interface: String,
|
pub download_interface: String,
|
||||||
pub upload_interface: String,
|
pub upload_interface: String,
|
||||||
pub download_base_kbits: f64,
|
pub download_base_kbits: f64,
|
||||||
|
pub download_min_percent: f64,
|
||||||
pub download_min_kbits: f64,
|
pub download_min_kbits: f64,
|
||||||
pub upload_base_kbits: f64,
|
pub upload_base_kbits: f64,
|
||||||
|
pub upload_min_percent: f64,
|
||||||
pub upload_min_kbits: f64,
|
pub upload_min_kbits: f64,
|
||||||
|
|
||||||
// Output section
|
// Output section
|
||||||
@@ -86,7 +88,7 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new() -> Result<Self> {
|
pub fn new() -> Result<Self> {
|
||||||
Ok(Self {
|
let config = Self {
|
||||||
// Network section
|
// Network section
|
||||||
download_base_kbits: Self::get::<f64>(
|
download_base_kbits: Self::get::<f64>(
|
||||||
"SQMA_DOWNLOAD_BASE_KBITS",
|
"SQMA_DOWNLOAD_BASE_KBITS",
|
||||||
@@ -98,11 +100,8 @@ impl Config {
|
|||||||
"sqm-autorate.@network[0].download_interface",
|
"sqm-autorate.@network[0].download_interface",
|
||||||
None,
|
None,
|
||||||
)?,
|
)?,
|
||||||
download_min_kbits: Self::get::<f64>(
|
download_min_percent: 0.0, // placeholder, computed below
|
||||||
"SQMA_DOWNLOAD_MIN_KBITS",
|
download_min_kbits: 0.0, // placeholder, computed below
|
||||||
"sqm-autorate.@network[0].download_min_kbits",
|
|
||||||
None,
|
|
||||||
)?,
|
|
||||||
upload_base_kbits: Self::get::<f64>(
|
upload_base_kbits: Self::get::<f64>(
|
||||||
"SQMA_UPLOAD_BASE_KBITS",
|
"SQMA_UPLOAD_BASE_KBITS",
|
||||||
"sqm-autorate.@network[0].upload_base_kbits",
|
"sqm-autorate.@network[0].upload_base_kbits",
|
||||||
@@ -113,11 +112,8 @@ impl Config {
|
|||||||
"sqm-autorate.@network[0].upload_interface",
|
"sqm-autorate.@network[0].upload_interface",
|
||||||
None,
|
None,
|
||||||
)?,
|
)?,
|
||||||
upload_min_kbits: Self::get::<f64>(
|
upload_min_percent: 0.0, // placeholder, computed below
|
||||||
"SQMA_UPLOAD_MIN_KBITS",
|
upload_min_kbits: 0.0, // placeholder, computed below
|
||||||
"sqm-autorate.@network[0].upload_min_kbits",
|
|
||||||
None,
|
|
||||||
)?,
|
|
||||||
// Output section
|
// Output section
|
||||||
log_level: Self::get::<Level>(
|
log_level: Self::get::<Level>(
|
||||||
"SQMA_LOG_LEVEL",
|
"SQMA_LOG_LEVEL",
|
||||||
@@ -190,7 +186,30 @@ impl Config {
|
|||||||
"sqm-autorate.@advanced_settings[0].upload_delay_ms",
|
"sqm-autorate.@advanced_settings[0].upload_delay_ms",
|
||||||
Some(15.0),
|
Some(15.0),
|
||||||
)?,
|
)?,
|
||||||
})
|
};
|
||||||
|
|
||||||
|
let mut config = config;
|
||||||
|
|
||||||
|
config.download_min_percent = Self::get::<f64>(
|
||||||
|
"SQMA_DOWNLOAD_MIN_PERCENT",
|
||||||
|
"sqm-autorate.@network[0].download_min_percent",
|
||||||
|
Some(20.0),
|
||||||
|
)?
|
||||||
|
.clamp(1.0, 80.0);
|
||||||
|
|
||||||
|
config.upload_min_percent = Self::get::<f64>(
|
||||||
|
"SQMA_UPLOAD_MIN_PERCENT",
|
||||||
|
"sqm-autorate.@network[0].upload_min_percent",
|
||||||
|
Some(20.0),
|
||||||
|
)?
|
||||||
|
.clamp(1.0, 80.0);
|
||||||
|
|
||||||
|
config.download_min_kbits =
|
||||||
|
(config.download_base_kbits * config.download_min_percent / 100.0).floor();
|
||||||
|
config.upload_min_kbits =
|
||||||
|
(config.upload_base_kbits * config.upload_min_percent / 100.0).floor();
|
||||||
|
|
||||||
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get<T: FromStr>(env_key: &str, uci_key: &str, default: Option<T>) -> Result<T, ConfigError> {
|
fn get<T: FromStr>(env_key: &str, uci_key: &str, default: Option<T>) -> Result<T, ConfigError> {
|
||||||
|
|||||||
Reference in new issue
Block a user