diff --git a/src/error.rs b/src/error.rs index a3f8625..46e4166 100644 --- a/src/error.rs +++ b/src/error.rs @@ -103,6 +103,9 @@ pub enum ChorusError { // Rustls Rustls(tokio_rustls::rustls::Error), + // Timed Out + TimedOut, + // Tungstenite Tungstenite(hyper_tungstenite::tungstenite::error::Error), @@ -167,6 +170,7 @@ impl std::fmt::Display for ChorusError { ChorusError::NoPrivateKey => write!(f, "Private Key Not Found"), ChorusError::Restricted => write!(f, "Restricted"), ChorusError::Rustls(e) => write!(f, "{e}"), + ChorusError::TimedOut => write!(f, "Timed out"), ChorusError::Tungstenite(e) => write!(f, "{e}"), ChorusError::Scraper => write!(f, "Filter is underspecified. Scrapers are not allowed"), ChorusError::TooManyErrors => write!(f, "Too many errors"), diff --git a/src/main.rs b/src/main.rs index b66dda5..d129dfe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -299,12 +299,25 @@ async fn handle_http_request( // Ban for longer if they've had error-based bans already ban_seconds = 60 + 60 * number_of_error_bans as u64; - msg = "Banned (temporary)"; + msg = "Errored Out, temporarily banned (long and growing)"; + } + ChorusError::TimedOut => { + is_an_error_ban = true; + + let number_of_error_bans = match GLOBALS.ip_data.get(&peer.ip()) { + Some(ipdata) => ipdata.number_of_error_bans, + None => 0, + }; + + // Ban for longer if they've had error-based bans already + ban_seconds = 60 + 60 * number_of_error_bans as u64; + + msg = "Timed Out, temporarily banned (long and growing)"; } _ => { log::error!("{}: {}", peer, e); ban_seconds = 15; - msg = "Banned (short, temporary)"; + msg = "Errored, temporarily banned (short, fixed)"; } } } @@ -373,7 +386,7 @@ impl WebSocketService { // And they are idle for 5 seconds with no subscriptions if last_message_at + Duration::from_secs(5) < instant { self.websocket.send(Message::Close(None)).await?; - break; + return Err(ChorusError::TimedOut.into()); } } }