mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 09:45:31 +00:00
WIP: ws: split into features, other fixes
This commit is contained in:
parent
465cf5920d
commit
2bed6ccdc5
10 changed files with 76 additions and 25 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -240,6 +240,7 @@ dependencies = [
|
|||
"aquatic_common",
|
||||
"aquatic_ws_protocol",
|
||||
"async-tungstenite",
|
||||
"cfg-if",
|
||||
"core_affinity",
|
||||
"crossbeam-channel",
|
||||
"either",
|
||||
|
|
|
|||
|
|
@ -15,36 +15,44 @@ path = "src/lib/lib.rs"
|
|||
name = "aquatic_ws"
|
||||
path = "src/bin/main.rs"
|
||||
|
||||
[features]
|
||||
default = ["with-mio"]
|
||||
with-glommio = ["async-tungstenite", "futures-lite", "futures", "futures-rustls", "glommio", "rustls-pemfile"]
|
||||
with-mio = ["crossbeam-channel", "histogram", "mio", "native-tls", "parking_lot", "socket2"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
async-tungstenite = "0.15"
|
||||
aquatic_cli_helpers = "0.1.0"
|
||||
aquatic_common = "0.1.0"
|
||||
aquatic_ws_protocol = "0.1.0"
|
||||
cfg-if = "1"
|
||||
core_affinity = "0.5"
|
||||
either = "1"
|
||||
futures-lite = "1"
|
||||
futures = "0.3"
|
||||
futures-rustls = "0.22"
|
||||
glommio = { git = "https://github.com/DataDog/glommio.git", rev = "4e6b14772da2f4325271fbcf12d24cf91ed466e5" }
|
||||
hashbrown = { version = "0.11.2", features = ["serde"] }
|
||||
log = "0.4"
|
||||
mimalloc = { version = "0.1", default-features = false }
|
||||
privdrop = "0.5"
|
||||
rand = { version = "0.8", features = ["small_rng"] }
|
||||
rustls-pemfile = "0.2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
signal-hook = { version = "0.3" }
|
||||
slab = "0.4"
|
||||
tungstenite = "0.15"
|
||||
|
||||
# mio
|
||||
crossbeam-channel = { version = "0.5", optional = true }
|
||||
histogram = { version = "0.6", optional = true }
|
||||
mio = { version = "0.7", features = ["tcp", "os-poll", "os-util"], optional = true }
|
||||
native-tls = { version = "0.2", optional = true }
|
||||
parking_lot = { version = "0.11", optional = true }
|
||||
socket2 = { version = "0.4.1", features = ["all"], optional = true }
|
||||
|
||||
crossbeam-channel = "0.5"
|
||||
histogram = "0.6"
|
||||
mio = { version = "0.7", features = ["tcp", "os-poll", "os-util"] }
|
||||
native-tls = "0.2"
|
||||
parking_lot = "0.11"
|
||||
socket2 = { version = "0.4.1", features = ["all"] }
|
||||
# glommio
|
||||
async-tungstenite = { version = "0.15", optional = true }
|
||||
futures-lite = { version = "1", optional = true }
|
||||
futures = { version = "0.3", optional = true }
|
||||
futures-rustls = { version = "0.22", optional = true }
|
||||
glommio = { git = "https://github.com/DataDog/glommio.git", rev = "4e6b14772da2f4325271fbcf12d24cf91ed466e5", optional = true }
|
||||
rustls-pemfile = { version = "0.2", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = "1.0"
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ use aquatic_ws_protocol::*;
|
|||
|
||||
use crate::config::Config;
|
||||
|
||||
pub type TlsConfig = futures_rustls::rustls::ServerConfig;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct PendingScrapeId(pub usize);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use std::net::SocketAddr;
|
||||
#[cfg(feature = "with-glommio")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
use aquatic_common::cpu_pinning::CpuPinningConfig;
|
||||
|
|
@ -20,11 +21,13 @@ pub struct Config {
|
|||
pub log_level: LogLevel,
|
||||
pub network: NetworkConfig,
|
||||
pub protocol: ProtocolConfig,
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub handlers: HandlerConfig,
|
||||
pub cleaning: CleaningConfig,
|
||||
pub privileges: PrivilegeConfig,
|
||||
pub access_list: AccessListConfig,
|
||||
pub cpu_pinning: CpuPinningConfig,
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub statistics: StatisticsConfig,
|
||||
}
|
||||
|
||||
|
|
@ -40,16 +43,23 @@ pub struct NetworkConfig {
|
|||
/// Bind to this address
|
||||
pub address: SocketAddr,
|
||||
pub ipv6_only: bool,
|
||||
|
||||
pub tls_certificate_path: PathBuf,
|
||||
pub tls_private_key_path: PathBuf,
|
||||
pub websocket_max_message_size: usize,
|
||||
pub websocket_max_frame_size: usize,
|
||||
|
||||
#[cfg(feature = "with-glommio")]
|
||||
pub tls_certificate_path: PathBuf,
|
||||
#[cfg(feature = "with-glommio")]
|
||||
pub tls_private_key_path: PathBuf,
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub use_tls: bool,
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub tls_pkcs12_path: String,
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub tls_pkcs12_password: String,
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub poll_event_capacity: usize,
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub poll_timeout_microseconds: u64,
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +74,7 @@ pub struct ProtocolConfig {
|
|||
pub peer_announce_interval: usize,
|
||||
}
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct HandlerConfig {
|
||||
|
|
@ -82,9 +93,11 @@ pub struct CleaningConfig {
|
|||
pub max_peer_age: u64,
|
||||
|
||||
/// Remove connections that are older than this (seconds)
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub max_connection_age: u64,
|
||||
}
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct StatisticsConfig {
|
||||
|
|
@ -100,11 +113,13 @@ impl Default for Config {
|
|||
log_level: LogLevel::default(),
|
||||
network: NetworkConfig::default(),
|
||||
protocol: ProtocolConfig::default(),
|
||||
#[cfg(feature = "with-mio")]
|
||||
handlers: Default::default(),
|
||||
cleaning: CleaningConfig::default(),
|
||||
privileges: PrivilegeConfig::default(),
|
||||
access_list: AccessListConfig::default(),
|
||||
cpu_pinning: Default::default(),
|
||||
#[cfg(feature = "with-mio")]
|
||||
statistics: Default::default(),
|
||||
}
|
||||
}
|
||||
|
|
@ -115,15 +130,23 @@ impl Default for NetworkConfig {
|
|||
Self {
|
||||
address: SocketAddr::from(([0, 0, 0, 0], 3000)),
|
||||
ipv6_only: false,
|
||||
tls_certificate_path: "".into(),
|
||||
tls_private_key_path: "".into(),
|
||||
websocket_max_message_size: 64 * 1024,
|
||||
websocket_max_frame_size: 16 * 1024,
|
||||
|
||||
#[cfg(feature = "with-glommio")]
|
||||
tls_certificate_path: "".into(),
|
||||
#[cfg(feature = "with-glommio")]
|
||||
tls_private_key_path: "".into(),
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
use_tls: false,
|
||||
#[cfg(feature = "with-mio")]
|
||||
tls_pkcs12_path: "".into(),
|
||||
#[cfg(feature = "with-mio")]
|
||||
tls_pkcs12_password: "".into(),
|
||||
#[cfg(feature = "with-mio")]
|
||||
poll_event_capacity: 4096,
|
||||
#[cfg(feature = "with-mio")]
|
||||
poll_timeout_microseconds: 200_000,
|
||||
}
|
||||
}
|
||||
|
|
@ -139,6 +162,7 @@ impl Default for ProtocolConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
impl Default for HandlerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -154,11 +178,13 @@ impl Default for CleaningConfig {
|
|||
torrent_cleaning_interval: 30,
|
||||
max_peer_age: 1800,
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
max_connection_age: 1800,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "with-mio")]
|
||||
impl Default for StatisticsConfig {
|
||||
fn default() -> Self {
|
||||
Self { interval: 0 }
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ use std::sync::Arc;
|
|||
|
||||
use aquatic_common::access_list::AccessListArcSwap;
|
||||
|
||||
pub type TlsConfig = futures_rustls::rustls::ServerConfig;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct State {
|
||||
pub access_list: Arc<AccessListArcSwap>,
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ use std::{
|
|||
use crate::config::Config;
|
||||
use aquatic_common::privileges::drop_privileges_after_socket_binding;
|
||||
|
||||
use self::common::State;
|
||||
use self::common::*;
|
||||
|
||||
use super::common::TlsConfig;
|
||||
use glommio::{channels::channel_mesh::MeshBuilder, prelude::*};
|
||||
|
||||
const SHARED_CHANNEL_SIZE: usize = 1024;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use crate::config::Config;
|
|||
|
||||
use crate::common::*;
|
||||
|
||||
use super::common::State;
|
||||
use super::common::*;
|
||||
|
||||
struct PendingScrapeResponse {
|
||||
pending_worker_out_messages: usize,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
use aquatic_common::access_list::update_access_list;
|
||||
use cfg_if::cfg_if;
|
||||
use signal_hook::{consts::SIGUSR1, iterator::Signals};
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
pub mod common;
|
||||
pub mod config;
|
||||
#[cfg(feature = "with-glommio")]
|
||||
pub mod glommio;
|
||||
#[cfg(feature = "with-mio")]
|
||||
pub mod mio;
|
||||
|
||||
pub const APP_NAME: &str = "aquatic_ws: WebTorrent tracker";
|
||||
|
|
@ -17,7 +20,13 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
});
|
||||
}
|
||||
|
||||
cfg_if!(
|
||||
if #[cfg(feature = "with-glommio")] {
|
||||
let state = glommio::common::State::default();
|
||||
} else {
|
||||
let state = mio::common::State::default();
|
||||
}
|
||||
);
|
||||
|
||||
update_access_list(&config.access_list, &state.access_list)?;
|
||||
|
||||
|
|
@ -27,7 +36,13 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let config = config.clone();
|
||||
let state = state.clone();
|
||||
|
||||
cfg_if!(
|
||||
if #[cfg(feature = "with-glommio")] {
|
||||
::std::thread::spawn(move || glommio::run_inner(config, state));
|
||||
} else {
|
||||
::std::thread::spawn(move || mio::run(config, state));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
for signal in &mut signals {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use common::*;
|
|||
pub const APP_NAME: &str = "aquatic_ws: WebTorrent tracker";
|
||||
|
||||
pub fn run(config: Config, state: State) -> anyhow::Result<()> {
|
||||
start_workers(config.clone(), state.clone())?;
|
||||
start_workers(config.clone(), state.clone()).expect("couldn't start workers");
|
||||
|
||||
// TODO: privdrop here instead
|
||||
|
||||
|
|
|
|||
|
|
@ -14,3 +14,5 @@ sudo cp cert.crt /usr/local/share/ca-certificates/snakeoil.crt
|
|||
sudo update-ca-certificates
|
||||
|
||||
openssl pkcs8 -in key.pem -topk8 -nocrypt -out key.pk8
|
||||
|
||||
# openssl pkcs12 -export -passout "pass:p" -out identity.pfx -inkey key.pem -in cert.crt
|
||||
Loading…
Add table
Add a link
Reference in a new issue