From 186bf476aeab0ff0838d1ae26a9dbcb2e40a8eb5 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 28 Aug 2023 15:02:14 +0200 Subject: what i invented here already existed: semaphore --- src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5230434..4d14bec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ pub mod config; pub mod error; pub mod files; pub mod helper; -pub mod limiter; pub mod proxy; use crate::{ @@ -26,16 +25,15 @@ use hyper::{ service::service_fn, Request, Response, StatusCode, }; -use limiter::Limiter; use log::{debug, error, info, warn}; use std::{fs::File, io::BufReader, net::SocketAddr, path::Path, process::exit, sync::Arc}; -use tokio::{net::TcpListener, signal::ctrl_c}; +use tokio::{net::TcpListener, signal::ctrl_c, sync::Semaphore}; use tokio_rustls::TlsAcceptor; pub struct State { pub config: Config, - pub l_incoming: Limiter, - pub l_outgoing: Limiter, + pub l_incoming: Semaphore, + pub l_outgoing: Semaphore, } #[tokio::main] @@ -54,8 +52,8 @@ async fn main() -> anyhow::Result<()> { } }; let state = Arc::new(State { - l_incoming: Limiter::new(config.limits.max_incoming_connections), - l_outgoing: Limiter::new(config.limits.max_outgoing_connections), + l_incoming: Semaphore::new(config.limits.max_incoming_connections), + l_outgoing: Semaphore::new(config.limits.max_outgoing_connections), config, }); @@ -153,7 +151,7 @@ pub async fn serve_stream