Skip to content

Commit

Permalink
feat: Send error message when connection is denied (#27)
Browse files Browse the repository at this point in the history
* feat: Send error message when connection is denied

* Update breakwater-core/src/lib.rs

* Update breakwater-core/src/lib.rs
  • Loading branch information
sbernauer committed May 31, 2024
1 parent 12d799a commit bbef8cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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 as connection limit is reached";
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

0 comments on commit bbef8cf

Please sign in to comment.