apply new rustfmt.toml changes, fix some clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0317cc8cc5
commit
77e0b76408
296 changed files with 7147 additions and 4300 deletions
|
@ -41,7 +41,11 @@ pub(crate) fn build(services: &Arc<Services>) -> Result<(Router, Guard)> {
|
|||
#[cfg(feature = "sentry_telemetry")]
|
||||
let layers = layers.layer(sentry_tower::NewSentryLayer::<http::Request<_>>::new_from_top());
|
||||
|
||||
#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))]
|
||||
#[cfg(any(
|
||||
feature = "zstd_compression",
|
||||
feature = "gzip_compression",
|
||||
feature = "brotli_compression"
|
||||
))]
|
||||
let layers = layers.layer(compression_layer(server));
|
||||
|
||||
let layers = layers
|
||||
|
@ -88,7 +92,11 @@ pub(crate) fn build(services: &Arc<Services>) -> Result<(Router, Guard)> {
|
|||
Ok((router.layer(layers), guard))
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))]
|
||||
#[cfg(any(
|
||||
feature = "zstd_compression",
|
||||
feature = "gzip_compression",
|
||||
feature = "brotli_compression"
|
||||
))]
|
||||
fn compression_layer(server: &Server) -> tower_http::compression::CompressionLayer {
|
||||
let mut compression_layer = tower_http::compression::CompressionLayer::new();
|
||||
|
||||
|
@ -148,11 +156,15 @@ fn cors_layer(_server: &Server) -> CorsLayer {
|
|||
.max_age(Duration::from_secs(86400))
|
||||
}
|
||||
|
||||
fn body_limit_layer(server: &Server) -> DefaultBodyLimit { DefaultBodyLimit::max(server.config.max_request_size) }
|
||||
fn body_limit_layer(server: &Server) -> DefaultBodyLimit {
|
||||
DefaultBodyLimit::max(server.config.max_request_size)
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "panic", level = "error", skip_all)]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn catch_panic(err: Box<dyn Any + Send + 'static>) -> http::Response<http_body_util::Full<bytes::Bytes>> {
|
||||
fn catch_panic(
|
||||
err: Box<dyn Any + Send + 'static>,
|
||||
) -> http::Response<http_body_util::Full<bytes::Bytes>> {
|
||||
//TODO: XXX
|
||||
/*
|
||||
conduwuit_service::services()
|
||||
|
|
|
@ -17,7 +17,9 @@ conduwuit::mod_dtor! {}
|
|||
conduwuit::rustc_flags_capture! {}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn start(server: &Arc<Server>) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> {
|
||||
pub extern "Rust" fn start(
|
||||
server: &Arc<Server>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> {
|
||||
AssertUnwindSafe(run::start(server.clone()))
|
||||
.catch_unwind()
|
||||
.map_err(Error::from_panic)
|
||||
|
@ -26,7 +28,9 @@ pub extern "Rust" fn start(server: &Arc<Server>) -> Pin<Box<dyn Future<Output =
|
|||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn stop(services: Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
||||
pub extern "Rust" fn stop(
|
||||
services: Arc<Services>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
||||
AssertUnwindSafe(run::stop(services))
|
||||
.catch_unwind()
|
||||
.map_err(Error::from_panic)
|
||||
|
@ -35,7 +39,9 @@ pub extern "Rust" fn stop(services: Arc<Services>) -> Pin<Box<dyn Future<Output
|
|||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn run(services: &Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
||||
pub extern "Rust" fn run(
|
||||
services: &Arc<Services>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
||||
AssertUnwindSafe(run::run(services.clone()))
|
||||
.catch_unwind()
|
||||
.map_err(Error::from_panic)
|
||||
|
|
|
@ -14,7 +14,9 @@ use http::{Method, StatusCode, Uri};
|
|||
skip_all,
|
||||
)]
|
||||
pub(crate) async fn spawn(
|
||||
State(services): State<Arc<Services>>, req: http::Request<axum::body::Body>, next: axum::middleware::Next,
|
||||
State(services): State<Arc<Services>>,
|
||||
req: http::Request<axum::body::Body>,
|
||||
next: axum::middleware::Next,
|
||||
) -> Result<Response, StatusCode> {
|
||||
let server = &services.server;
|
||||
if !server.running() {
|
||||
|
@ -40,7 +42,9 @@ pub(crate) async fn spawn(
|
|||
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
pub(crate) async fn handle(
|
||||
State(services): State<Arc<Services>>, req: http::Request<axum::body::Body>, next: axum::middleware::Next,
|
||||
State(services): State<Arc<Services>>,
|
||||
req: http::Request<axum::body::Body>,
|
||||
next: axum::middleware::Next,
|
||||
) -> Result<Response, StatusCode> {
|
||||
let server = &services.server;
|
||||
if !server.running() {
|
||||
|
|
|
@ -33,9 +33,10 @@ pub(crate) async fn run(services: Arc<Services>) -> Result<()> {
|
|||
.runtime()
|
||||
.spawn(signal(server.clone(), tx.clone(), handle.clone()));
|
||||
|
||||
let mut listener = server
|
||||
.runtime()
|
||||
.spawn(serve::serve(services.clone(), handle.clone(), tx.subscribe()));
|
||||
let mut listener =
|
||||
server
|
||||
.runtime()
|
||||
.spawn(serve::serve(services.clone(), handle.clone(), tx.subscribe()));
|
||||
|
||||
// Focal point
|
||||
debug!("Running");
|
||||
|
@ -63,7 +64,8 @@ pub(crate) async fn start(server: Arc<Server>) -> Result<Arc<Services>> {
|
|||
let services = Services::build(server).await?.start().await?;
|
||||
|
||||
#[cfg(feature = "systemd")]
|
||||
sd_notify::notify(true, &[sd_notify::NotifyState::Ready]).expect("failed to notify systemd of ready state");
|
||||
sd_notify::notify(true, &[sd_notify::NotifyState::Ready])
|
||||
.expect("failed to notify systemd of ready state");
|
||||
|
||||
debug!("Started");
|
||||
Ok(services)
|
||||
|
@ -98,7 +100,8 @@ pub(crate) async fn stop(services: Arc<Services>) -> Result<()> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "systemd")]
|
||||
sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]).expect("failed to notify systemd of stopping state");
|
||||
sd_notify::notify(true, &[sd_notify::NotifyState::Stopping])
|
||||
.expect("failed to notify systemd of stopping state");
|
||||
|
||||
info!("Shutdown complete.");
|
||||
Ok(())
|
||||
|
@ -121,7 +124,12 @@ async fn signal(server: Arc<Server>, tx: Sender<()>, handle: axum_server::Handle
|
|||
}
|
||||
}
|
||||
|
||||
async fn handle_shutdown(server: &Arc<Server>, tx: &Sender<()>, handle: &axum_server::Handle, sig: &str) {
|
||||
async fn handle_shutdown(
|
||||
server: &Arc<Server>,
|
||||
tx: &Sender<()>,
|
||||
handle: &axum_server::Handle,
|
||||
sig: &str,
|
||||
) {
|
||||
debug!("Received signal {sig}");
|
||||
if let Err(e) = tx.send(()) {
|
||||
error!("failed sending shutdown transaction to channel: {e}");
|
||||
|
@ -139,7 +147,9 @@ async fn handle_shutdown(server: &Arc<Server>, tx: &Sender<()>, handle: &axum_se
|
|||
}
|
||||
|
||||
async fn handle_services_poll(
|
||||
server: &Arc<Server>, result: Result<()>, listener: JoinHandle<Result<()>>,
|
||||
server: &Arc<Server>,
|
||||
result: Result<()>,
|
||||
listener: JoinHandle<Result<()>>,
|
||||
) -> Result<()> {
|
||||
debug!("Service manager finished: {result:?}");
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ use super::layers;
|
|||
|
||||
/// Serve clients
|
||||
pub(super) async fn serve(
|
||||
services: Arc<Services>, handle: ServerHandle, shutdown: broadcast::Receiver<()>,
|
||||
services: Arc<Services>,
|
||||
handle: ServerHandle,
|
||||
shutdown: broadcast::Receiver<()>,
|
||||
) -> Result<()> {
|
||||
let server = &services.server;
|
||||
let config = &server.config;
|
||||
|
|
|
@ -9,12 +9,16 @@ use conduwuit::{debug_info, info, Result, Server};
|
|||
use tokio::task::JoinSet;
|
||||
|
||||
pub(super) async fn serve(
|
||||
server: &Arc<Server>, app: Router, handle: ServerHandle, addrs: Vec<SocketAddr>,
|
||||
server: &Arc<Server>,
|
||||
app: Router,
|
||||
handle: ServerHandle,
|
||||
addrs: Vec<SocketAddr>,
|
||||
) -> Result<()> {
|
||||
let app = app.into_make_service_with_connect_info::<SocketAddr>();
|
||||
let mut join_set = JoinSet::new();
|
||||
for addr in &addrs {
|
||||
join_set.spawn_on(bind(*addr).handle(handle.clone()).serve(app.clone()), server.runtime());
|
||||
join_set
|
||||
.spawn_on(bind(*addr).handle(handle.clone()).serve(app.clone()), server.runtime());
|
||||
}
|
||||
|
||||
info!("Listening on {addrs:?}");
|
||||
|
|
|
@ -10,7 +10,12 @@ use conduwuit::{err, Result, Server};
|
|||
use tokio::task::JoinSet;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
pub(super) async fn serve(server: &Arc<Server>, app: Router, handle: ServerHandle, addrs: Vec<SocketAddr>) -> Result {
|
||||
pub(super) async fn serve(
|
||||
server: &Arc<Server>,
|
||||
app: Router,
|
||||
handle: ServerHandle,
|
||||
addrs: Vec<SocketAddr>,
|
||||
) -> Result {
|
||||
let tls = &server.config.tls;
|
||||
let certs = tls
|
||||
.certs
|
||||
|
@ -29,7 +34,8 @@ pub(super) async fn serve(server: &Arc<Server>, app: Router, handle: ServerHandl
|
|||
|
||||
debug!("Using direct TLS. Certificate path {certs} and certificate private key path {key}",);
|
||||
info!(
|
||||
"Note: It is strongly recommended that you use a reverse proxy instead of running conduwuit directly with TLS."
|
||||
"Note: It is strongly recommended that you use a reverse proxy instead of running \
|
||||
conduwuit directly with TLS."
|
||||
);
|
||||
let conf = RustlsConfig::from_pem_file(certs, key).await?;
|
||||
|
||||
|
@ -58,8 +64,8 @@ pub(super) async fn serve(server: &Arc<Server>, app: Router, handle: ServerHandl
|
|||
|
||||
if tls.dual_protocol {
|
||||
warn!(
|
||||
"Listening on {addrs:?} with TLS certificate {certs} and supporting plain text (HTTP) connections too \
|
||||
(insecure!)",
|
||||
"Listening on {addrs:?} with TLS certificate {certs} and supporting plain text \
|
||||
(HTTP) connections too (insecure!)",
|
||||
);
|
||||
} else {
|
||||
info!("Listening on {addrs:?} with TLS certificate {certs}");
|
||||
|
|
|
@ -10,7 +10,9 @@ use axum::{
|
|||
extract::{connect_info::IntoMakeServiceWithConnectInfo, Request},
|
||||
Router,
|
||||
};
|
||||
use conduwuit::{debug, debug_error, info, result::UnwrapInfallible, trace, warn, Err, Result, Server};
|
||||
use conduwuit::{
|
||||
debug, debug_error, info, result::UnwrapInfallible, trace, warn, Err, Result, Server,
|
||||
};
|
||||
use hyper::{body::Incoming, service::service_fn};
|
||||
use hyper_util::{
|
||||
rt::{TokioExecutor, TokioIo},
|
||||
|
@ -31,7 +33,11 @@ const NULL_ADDR: net::SocketAddr = net::SocketAddr::new(IpAddr::V4(Ipv4Addr::new
|
|||
const FINI_POLL_INTERVAL: Duration = Duration::from_millis(750);
|
||||
|
||||
#[tracing::instrument(skip_all, level = "debug")]
|
||||
pub(super) async fn serve(server: &Arc<Server>, app: Router, mut shutdown: broadcast::Receiver<()>) -> Result<()> {
|
||||
pub(super) async fn serve(
|
||||
server: &Arc<Server>,
|
||||
app: Router,
|
||||
mut shutdown: broadcast::Receiver<()>,
|
||||
) -> Result<()> {
|
||||
let mut tasks = JoinSet::<()>::new();
|
||||
let executor = TokioExecutor::new();
|
||||
let app = app.into_make_service_with_connect_info::<net::SocketAddr>();
|
||||
|
@ -55,8 +61,12 @@ pub(super) async fn serve(server: &Arc<Server>, app: Router, mut shutdown: broad
|
|||
}
|
||||
|
||||
async fn accept(
|
||||
server: &Arc<Server>, listener: &UnixListener, tasks: &mut JoinSet<()>, mut app: MakeService,
|
||||
builder: server::conn::auto::Builder<TokioExecutor>, conn: (UnixStream, SocketAddr),
|
||||
server: &Arc<Server>,
|
||||
listener: &UnixListener,
|
||||
tasks: &mut JoinSet<()>,
|
||||
mut app: MakeService,
|
||||
builder: server::conn::auto::Builder<TokioExecutor>,
|
||||
conn: (UnixStream, SocketAddr),
|
||||
) {
|
||||
let (socket, remote) = conn;
|
||||
let socket = TokioIo::new(socket);
|
||||
|
@ -103,7 +113,8 @@ async fn init(server: &Arc<Server>) -> Result<UnixListener> {
|
|||
}
|
||||
|
||||
let socket_perms = config.unix_socket_perms.to_string();
|
||||
let octal_perms = u32::from_str_radix(&socket_perms, 8).expect("failed to convert octal permissions");
|
||||
let octal_perms =
|
||||
u32::from_str_radix(&socket_perms, 8).expect("failed to convert octal permissions");
|
||||
let perms = std::fs::Permissions::from_mode(octal_perms);
|
||||
if let Err(e) = fs::set_permissions(&path, perms).await {
|
||||
return Err!("Failed to set socket {path:?} permissions: {e}");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue