Skip to content

Commit

Permalink
Possible stream shutdown improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Jul 12, 2024
1 parent 633bb82 commit 37b1b3a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/bin/chorus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fs::OpenOptions;
use std::io::Read;
use std::sync::atomic::Ordering;
use std::time::Duration;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener;
use tokio::signal::unix::{signal, SignalKind};

Expand Down Expand Up @@ -86,14 +87,12 @@ async fn main() -> Result<(), Error> {

// Accepts network connections and spawn a task to serve each one
v = listener.accept() => {
let (tcp_stream, hashed_peer) = {
let (mut tcp_stream, hashed_peer) = {
let (tcp_stream, peer_addr) = v?;
let hashed_peer = HashedPeer::new(peer_addr);
(tcp_stream, hashed_peer)
};

let counting_stream = CountingStream(tcp_stream);

// Possibly IP block
if GLOBALS.config.read().enable_ip_blocking {
let ip_data = chorus::get_ip_data(GLOBALS.store.get().unwrap(), hashed_peer.ip())?;
Expand All @@ -102,10 +101,13 @@ async fn main() -> Result<(), Error> {
"{}: Blocking reconnection until {}",
hashed_peer.ip(),
ip_data.ban_until);
let _ = tcp_stream.shutdown().await;
continue;
}
}

let counting_stream = CountingStream(tcp_stream);

let maybe_tls_acceptor_clone = maybe_tls_acceptor.clone();
tokio::spawn(async move {
match maybe_tls_acceptor_clone {
Expand Down

0 comments on commit 37b1b3a

Please sign in to comment.