diff --git a/conduit-config/src/rate_limiting.rs b/conduit-config/src/rate_limiting.rs index 28e05aca..b9523ef3 100644 --- a/conduit-config/src/rate_limiting.rs +++ b/conduit-config/src/rate_limiting.rs @@ -545,32 +545,10 @@ macro_rules! default_restriction_map { } } -impl ClientMediaConfig { - fn todo() -> Self { - Self { - download: MediaLimitation::new( - MediaTimeframe::PerHour(ByteSize::mb(200)), - ByteSize::mb(500), - ), - upload: MediaLimitation::new( - MediaTimeframe::PerHour(ByteSize::mb(20)), - ByteSize::mb(100), - ), - fetch: MediaLimitation::new( - MediaTimeframe::PerHour(ByteSize::mb(200)), - ByteSize::mb(500), - ), - } - } -} - -impl FederationMediaConfig { - fn todo() -> Self { - Self { - download: MediaLimitation::new( - MediaTimeframe::PerHour(ByteSize::mb(200)), - ByteSize::mb(500), - ), +macro_rules! media_config { + ($config_type:ident; $($key:ident: $timeframe:ident, $timeframe_value:expr, $burst_capacity:expr;)*) => { + $config_type { + $($key: MediaLimitation::new(MediaTimeframe::$timeframe($timeframe_value), $burst_capacity),)* } } } @@ -603,7 +581,9 @@ impl Config { } pub fn get_preset(preset: ConfigPreset) -> Self { - // The client target map shouldn't really differ between presets, but maybe I'm wrong. + // The client target map shouldn't really differ between presets, as individual user's + // behaviours shouldn't differ depending on the size of the server or whether it's private + // or public, but maybe I'm wrong. let target_client_map = default_restriction_map!( ClientRestriction; @@ -619,6 +599,14 @@ impl Config { MediaDownload, PerHour, 30, 100; MediaCreate, PerMinute, 4, 20; ); + // Same goes for media + let target_client_media = media_config! { + ClientMediaConfig; + + download: PerMinute, ByteSize::mb(100), ByteSize::mb(50); + upload: PerMinute, ByteSize::mb(10), ByteSize::mb(100); + fetch: PerMinute, ByteSize::mb(100), ByteSize::mb(50); + }; // Currently, these values are completely arbitrary, not informed by any sort of // knowledge. In the future, it would be good to have some sort of analytics to @@ -630,7 +618,7 @@ impl Config { target: ConfigFragment { client: ConfigFragmentFragment { map: target_client_map, - media: ClientMediaConfig::todo(), + media: target_client_media, additional_fields: AuthenticationFailures::new( Timeframe::PerHour(nz(1)), nz(20), @@ -645,7 +633,11 @@ impl Config { Invite, PerHour, 10, 10; MediaDownload, PerMinute, 10, 50; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(100), ByteSize::mb(100); + }, additional_fields: Nothing, }, }, @@ -666,7 +658,13 @@ impl Config { MediaDownload, PerMinute, 5, 150; MediaCreate, PerMinute, 20, 50; ), - media: ClientMediaConfig::todo(), + media: media_config! { + ClientMediaConfig; + + download: PerMinute, ByteSize::mb(250), ByteSize::mb(100); + upload: PerMinute, ByteSize::mb(50), ByteSize::mb(100); + fetch: PerMinute, ByteSize::mb(250), ByteSize::mb(100); + }, additional_fields: Nothing, }, federation: ConfigFragmentFragment { @@ -678,7 +676,11 @@ impl Config { Invite, PerMinute, 10, 10; MediaDownload, PerSecond, 10, 250; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(250), ByteSize::mb(250); + }, additional_fields: Nothing, }, }, @@ -687,7 +689,7 @@ impl Config { target: ConfigFragment { client: ConfigFragmentFragment { map: target_client_map, - media: ClientMediaConfig::todo(), + media: target_client_media, additional_fields: AuthenticationFailures::new( Timeframe::PerHour(nz(10)), nz(20), @@ -702,7 +704,11 @@ impl Config { Invite, PerHour, 30, 10; MediaDownload, PerMinute, 100, 50; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(200), ByteSize::mb(200); + }, additional_fields: Nothing, }, }, @@ -723,7 +729,13 @@ impl Config { MediaDownload, PerSecond, 1, 200; MediaCreate, PerSecond, 2, 20; ), - media: ClientMediaConfig::todo(), + media: media_config! { + ClientMediaConfig; + + download: PerMinute, ByteSize::mb(500), ByteSize::mb(200); + upload: PerMinute, ByteSize::mb(100), ByteSize::mb(200); + fetch: PerMinute, ByteSize::mb(500), ByteSize::mb(200); + }, additional_fields: Nothing, }, federation: ConfigFragmentFragment { @@ -735,7 +747,11 @@ impl Config { Invite, PerMinute, 25, 25; MediaDownload, PerSecond, 10, 100; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(500), ByteSize::mb(500); + }, additional_fields: Nothing, }, }, @@ -744,7 +760,7 @@ impl Config { target: ConfigFragment { client: ConfigFragmentFragment { map: target_client_map, - media: ClientMediaConfig::todo(), + media: target_client_media, additional_fields: AuthenticationFailures::new( Timeframe::PerHour(nz(10)), nz(20), @@ -759,7 +775,11 @@ impl Config { Invite, PerHour, 30, 10; MediaDownload, PerMinute, 100, 50; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(200), ByteSize::mb(200); + }, additional_fields: Nothing, }, }, @@ -783,7 +803,13 @@ impl Config { MediaDownload, PerSecond, 1, 200; MediaCreate, PerSecond, 2, 20; ), - media: ClientMediaConfig::todo(), + media: media_config! { + ClientMediaConfig; + + download: PerMinute, ByteSize::mb(500), ByteSize::mb(200); + upload: PerMinute, ByteSize::mb(100), ByteSize::mb(200); + fetch: PerMinute, ByteSize::mb(500), ByteSize::mb(200); + }, additional_fields: Nothing, }, federation: ConfigFragmentFragment { @@ -795,7 +821,11 @@ impl Config { Invite, PerMinute, 25, 25; MediaDownload, PerSecond, 10, 100; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(500), ByteSize::mb(500); + }, additional_fields: Nothing, }, }, @@ -804,7 +834,7 @@ impl Config { target: ConfigFragment { client: ConfigFragmentFragment { map: target_client_map, - media: ClientMediaConfig::todo(), + media: target_client_media, additional_fields: AuthenticationFailures::new( Timeframe::PerMinute(nz(1)), nz(20), @@ -819,7 +849,11 @@ impl Config { Invite, PerHour, 90, 30; MediaDownload, PerMinute, 100, 50; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::mb(600), ByteSize::mb(300); + }, additional_fields: Nothing, }, }, @@ -843,7 +877,13 @@ impl Config { MediaDownload, PerSecond, 25, 200; MediaCreate, PerSecond, 10, 30; ), - media: ClientMediaConfig::todo(), + media: media_config! { + ClientMediaConfig; + + download: PerMinute, ByteSize::gb(2), ByteSize::mb(500); + upload: PerMinute, ByteSize::mb(500), ByteSize::mb(500); + fetch: PerMinute, ByteSize::gb(2), ByteSize::mb(500); + }, additional_fields: Nothing, }, federation: ConfigFragmentFragment { @@ -855,7 +895,11 @@ impl Config { Invite, PerSecond, 1, 50; MediaDownload, PerSecond, 50, 100; ), - media: FederationMediaConfig::todo(), + media: media_config! { + FederationMediaConfig; + + download: PerMinute, ByteSize::gb(2), ByteSize::gb(1); + }, additional_fields: Nothing, }, },