mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +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
|
|
@ -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<()> {
|
|||
});
|
||||
}
|
||||
|
||||
let state = glommio::common::State::default();
|
||||
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();
|
||||
|
||||
::std::thread::spawn(move || glommio::run_inner(config, state));
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue