Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Send error message when connection is denied #27

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions breakwater-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ if cfg!(feature = "alpha") {
).as_bytes();

pub const ALT_HELP_TEXT: &[u8] = b"Stop spamming HELP!\n";
pub const CONNECTION_DENIED_TEXT: &[u8] = b"Connection denied because connection limit reached";
sbernauer marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion breakwater/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::{cmp::min, net::IpAddr, sync::Arc, time::Duration};

use breakwater_core::framebuffer::FrameBuffer;
use breakwater_core::CONNECTION_DENIED_TEXT;
use breakwater_parser::{original::OriginalParser, Parser, ParserError};
use log::{debug, error, info};
use memadvise::{Advice, MemAdviseError};
Expand Down Expand Up @@ -112,7 +113,10 @@ impl Server {
.send(StatisticsEvent::ConnectionDenied { ip })
.await
.context(WriteToStatisticsChannelSnafu)?;
// Errors if session is dropped prematurely

// Only best effort, it's ok if this message get's missed
let _ = socket.write_all(CONNECTION_DENIED_TEXT).await;
// This can error if a connection is dropped prematurely, which is totally fine
let _ = socket.shutdown().await;
continue;
}
Expand Down
Loading