mirror of
https://github.com/telemt/telemt.git
synced 2026-11-01 05:12:02 +03:00
Races in admission + accounting + publication,+ PID fixed
This commit is contained in:
@@ -196,6 +196,13 @@ pub(super) fn validate(config: &mut ProxyConfig) -> Result<()> {
|
||||
"access.user_rate_limits.{user} must set at least one non-zero direction"
|
||||
)));
|
||||
}
|
||||
for (direction, value) in [("up_bps", limit.up_bps), ("down_bps", limit.down_bps)] {
|
||||
if value > MAX_RATE_LIMIT_BPS {
|
||||
return Err(ProxyError::Config(format!(
|
||||
"access.user_rate_limits.{user}.{direction} must be within [0, {MAX_RATE_LIMIT_BPS}]"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (cidr, limit) in &config.access.cidr_rate_limits {
|
||||
@@ -204,6 +211,13 @@ pub(super) fn validate(config: &mut ProxyConfig) -> Result<()> {
|
||||
"access.cidr_rate_limits.{cidr} must set at least one non-zero direction"
|
||||
)));
|
||||
}
|
||||
for (direction, value) in [("up_bps", limit.up_bps), ("down_bps", limit.down_bps)] {
|
||||
if value > MAX_RATE_LIMIT_BPS {
|
||||
return Err(ProxyError::Config(format!(
|
||||
"access.cidr_rate_limits.{cidr}.{direction} must be within [0, {MAX_RATE_LIMIT_BPS}]"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut cidr_auto_templates = HashSet::new();
|
||||
for cidr in config.access.cidr_rate_limits.keys() {
|
||||
|
||||
@@ -288,6 +288,68 @@ fn cidr_rate_limits_reject_duplicate_normalized_auto_templates() {
|
||||
assert!(error.contains("duplicates normalized auto-template *6/128"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rate_limits_accept_the_packed_counter_maximum() {
|
||||
let cfg = load_config_from_temp_toml(
|
||||
r#"
|
||||
[censorship]
|
||||
tls_domain = "example.com"
|
||||
|
||||
[access.users]
|
||||
user = "00000000000000000000000000000000"
|
||||
|
||||
[access.user_rate_limits]
|
||||
user = { up_bps = 100000000000, down_bps = 0 }
|
||||
|
||||
[access.cidr_rate_limits]
|
||||
"203.0.113.0/24" = { up_bps = 0, down_bps = 100000000000 }
|
||||
"#,
|
||||
);
|
||||
|
||||
assert_eq!(cfg.access.user_rate_limits["user"].up_bps, 100_000_000_000);
|
||||
assert_eq!(
|
||||
cfg.access.cidr_rate_limits[&CidrRateLimitKey::Network("203.0.113.0/24".parse().unwrap())]
|
||||
.down_bps,
|
||||
100_000_000_000
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_rate_limits_reject_values_above_the_packed_counter_maximum() {
|
||||
let error = load_config_error_from_temp_toml(
|
||||
r#"
|
||||
[censorship]
|
||||
tls_domain = "example.com"
|
||||
|
||||
[access.users]
|
||||
user = "00000000000000000000000000000000"
|
||||
|
||||
[access.user_rate_limits]
|
||||
user = { up_bps = 100000000001, down_bps = 0 }
|
||||
"#,
|
||||
);
|
||||
|
||||
assert!(error.contains("access.user_rate_limits.user.up_bps must be within"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cidr_rate_limits_reject_values_above_the_packed_counter_maximum() {
|
||||
let error = load_config_error_from_temp_toml(
|
||||
r#"
|
||||
[censorship]
|
||||
tls_domain = "example.com"
|
||||
|
||||
[access.users]
|
||||
user = "00000000000000000000000000000000"
|
||||
|
||||
[access.cidr_rate_limits]
|
||||
"203.0.113.0/24" = { up_bps = 0, down_bps = 100000000001 }
|
||||
"#,
|
||||
);
|
||||
|
||||
assert!(error.contains("access.cidr_rate_limits.203.0.113.0/24.down_bps must be within"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_logging_requires_path() {
|
||||
let error = load_config_error_from_temp_toml(
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ mod web_debug;
|
||||
|
||||
pub use access::{AccessConfig, CidrRateLimitKey, RateLimitBps};
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use access::{CidrAutoTemplate, CidrAutoTemplateFamily};
|
||||
pub(crate) use access::{CidrAutoTemplate, CidrAutoTemplateFamily, MAX_RATE_LIMIT_BPS};
|
||||
pub use api::{ApiConfig, ApiGrayAction};
|
||||
pub use censorship::{
|
||||
AntiCensorshipConfig, ExclusiveMaskTarget, TlsFetchConfig, TlsFetchProfile, UnknownSniAction,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use super::*;
|
||||
|
||||
/// Highest rate that fits one packed 20 ms shaping epoch.
|
||||
pub(crate) const MAX_RATE_LIMIT_BPS: u64 = 100_000_000_000;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AccessConfig {
|
||||
#[serde(default = "default_access_users")]
|
||||
@@ -260,10 +263,10 @@ fn parse_cidr_auto_prefix(
|
||||
/// Transport rate limit in bits-per-second.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RateLimitBps {
|
||||
/// Upload direction limit in bits-per-second; `0` means unlimited.
|
||||
/// Upload limit in bits-per-second within `0..=100_000_000_000`; `0` means unlimited.
|
||||
#[serde(default)]
|
||||
pub up_bps: u64,
|
||||
/// Download direction limit in bits-per-second; `0` means unlimited.
|
||||
/// Download limit in bits-per-second within `0..=100_000_000_000`; `0` means unlimited.
|
||||
#[serde(default)]
|
||||
pub down_bps: u64,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user