diff --git a/aquatic_udp/Cargo.toml b/aquatic_udp/Cargo.toml index b283860..4dfed44 100644 --- a/aquatic_udp/Cargo.toml +++ b/aquatic_udp/Cargo.toml @@ -15,7 +15,9 @@ path = "src/lib/lib.rs" name = "aquatic_udp" [features] -io_uring = ["glommio", "futures-lite"] +default = ["with-mio"] +with-glommio = ["glommio", "futures-lite"] +with-mio = ["crossbeam-channel", "histogram", "mio", "socket2"] [dependencies] anyhow = "1" @@ -24,20 +26,23 @@ aquatic_common = "0.1.0" aquatic_udp_protocol = "0.1.0" cfg-if = "1" core_affinity = "0.5" -crossbeam-channel = "0.5" hashbrown = "0.11.2" hex = "0.4" -histogram = "0.6" indexmap = "1" log = "0.4" mimalloc = { version = "0.1", default-features = false } -mio = { version = "0.7", features = ["udp", "os-poll", "os-util"] } parking_lot = "0.11" privdrop = "0.5" rand = { version = "0.8", features = ["small_rng"] } serde = { version = "1", features = ["derive"] } -socket2 = { version = "0.4.1", features = ["all"] } +# mio +crossbeam-channel = { version = "0.5", optional = true } +histogram = { version = "0.6", optional = true } +mio = { version = "0.7", features = ["udp", "os-poll", "os-util"], optional = true } +socket2 = { version = "0.4.1", features = ["all"], optional = true } + +# glommio glommio = { git = "https://github.com/DataDog/glommio.git", rev = "4e6b14772da2f4325271fbcf12d24cf91ed466e5", optional = true } futures-lite = { version = "1", optional = true } diff --git a/aquatic_udp/src/lib/config.rs b/aquatic_udp/src/lib/config.rs index 5e7b6f6..d05b338 100644 --- a/aquatic_udp/src/lib/config.rs +++ b/aquatic_udp/src/lib/config.rs @@ -18,7 +18,9 @@ pub struct Config { pub log_level: LogLevel, pub network: NetworkConfig, pub protocol: ProtocolConfig, + #[cfg(feature = "with-mio")] pub handlers: HandlerConfig, + #[cfg(feature = "with-mio")] pub statistics: StatisticsConfig, pub cleaning: CleaningConfig, pub privileges: PrivilegeConfig, @@ -52,6 +54,7 @@ pub struct NetworkConfig { /// $ sudo sysctl -w net.core.rmem_max=104857600 /// $ sudo sysctl -w net.core.rmem_default=104857600 pub socket_recv_buffer_size: usize, + #[cfg(feature = "with-mio")] pub poll_event_capacity: usize, } @@ -66,6 +69,7 @@ pub struct ProtocolConfig { pub peer_announce_interval: i32, } +#[cfg(feature = "with-mio")] #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(default)] pub struct HandlerConfig { @@ -75,6 +79,7 @@ pub struct HandlerConfig { pub channel_recv_timeout_microseconds: u64, } +#[cfg(feature = "with-mio")] #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(default)] pub struct StatisticsConfig { @@ -119,7 +124,9 @@ impl Default for Config { log_level: LogLevel::Error, network: NetworkConfig::default(), protocol: ProtocolConfig::default(), + #[cfg(feature = "with-mio")] handlers: HandlerConfig::default(), + #[cfg(feature = "with-mio")] statistics: StatisticsConfig::default(), cleaning: CleaningConfig::default(), privileges: PrivilegeConfig::default(), @@ -133,8 +140,9 @@ impl Default for NetworkConfig { fn default() -> Self { Self { address: SocketAddr::from(([0, 0, 0, 0], 3000)), - poll_event_capacity: 4096, socket_recv_buffer_size: 4096 * 128, + #[cfg(feature = "with-mio")] + poll_event_capacity: 4096, } } } @@ -149,6 +157,7 @@ impl Default for ProtocolConfig { } } +#[cfg(feature = "with-mio")] impl Default for HandlerConfig { fn default() -> Self { Self { @@ -158,6 +167,7 @@ impl Default for HandlerConfig { } } +#[cfg(feature = "with-mio")] impl Default for StatisticsConfig { fn default() -> Self { Self { interval: 0 } diff --git a/aquatic_udp/src/lib/lib.rs b/aquatic_udp/src/lib/lib.rs index a4a3a55..e3eea68 100644 --- a/aquatic_udp/src/lib/lib.rs +++ b/aquatic_udp/src/lib/lib.rs @@ -10,8 +10,9 @@ use cfg_if::cfg_if; pub mod common; pub mod config; -#[cfg(all(feature = "io_uring", target_os = "linux"))] +#[cfg(all(feature = "with-glommio", target_os = "linux"))] pub mod glommio; +#[cfg(feature = "with-mio")] pub mod mio; use config::Config; @@ -21,7 +22,7 @@ pub const APP_NAME: &str = "aquatic_udp: UDP BitTorrent tracker"; pub fn run(config: Config) -> ::anyhow::Result<()> { cfg_if! { - if #[cfg(all(feature = "io_uring", target_os = "linux"))] { + if #[cfg(all(feature = "with-glommio", target_os = "linux"))] { glommio::run(config) } else { mio::run(config)