mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-01 07:21:39 +00:00
Handle timeouts like excessive errors
This commit is contained in:
parent
1a90d2f9d5
commit
c42452a41a
@ -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"),
|
||||
|
||||
19
src/main.rs
19
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user