Tentative fix client setup

This commit is contained in:
Pascal Engélibert 2026-02-03 11:33:24 +01:00
commit 66d8aeb4a5
2 changed files with 280 additions and 254 deletions

View file

@ -29,7 +29,7 @@ use tokio_rustls::{
};
use tokio_util::codec::Framed;
const TIMEOUT: Duration = Duration::from_secs(60);
const TIMEOUT: Duration = Duration::from_secs(30);
#[derive(Debug)]
struct DummyCertVerifier;
@ -98,13 +98,31 @@ pub async fn play(
sync_receiver.await.unwrap();
// Semaphore used to limit the number of concurrent clients.
// Its handle is released when the task panics.
let limiter = Arc::new(Semaphore::new(32));
let limiter = Arc::new(Semaphore::new(16));
let counter = Arc::new(AtomicU32::new(0));
let running = Arc::new(Mutex::new(HashSet::new()));
let total = records.len() * repeat as usize;
let mut handles = Vec::new();
let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap();
let debug_mutex = Arc::new(Mutex::new(()));
tokio::spawn({
let running = running.clone();
let counter = counter.clone();
async move {
let mut last_count = 0;
loop {
tokio::time::sleep(TIMEOUT).await;
println!("Running: {:?}", running.lock().await);
let new_count = counter.load(std::sync::atomic::Ordering::Relaxed);
if new_count == last_count {
println!("Stalled at {} / {}, stopping", new_count, total);
std::process::exit(0);
}
last_count = new_count;
}
}
});
match tls_mode {
TlsMode::Both | TlsMode::Client => {
let mut config = tokio_rustls::rustls::ClientConfig::builder()
@ -125,6 +143,8 @@ pub async fn play(
}
config.key_log = Arc::new(tokio_rustls::rustls::KeyLogFile::new());
let config = Arc::new(config);
for _i in 0..repeat {
let mut handles = Vec::new();
for (id, (server_name, records)) in records.iter() {
let connector = TlsConnector::from(config.clone());
let counter = counter.clone();
@ -138,13 +158,14 @@ pub async fn play(
let server_name =
ServerName::try_from(String::from_utf8(server_name.clone()).unwrap())
.unwrap();
'repeat: for _i in 0..repeat {
'repeat: for _i in 0..1 {
let stream = TcpStream::connect(connect_to).await.unwrap();
let stream = connector
.connect(server_name.clone(), stream)
.await
.unwrap();
let mut stream = Framed::new(stream, crate::http::HttpClientCodec::new());
let mut stream =
Framed::new(stream, crate::http::HttpClientCodec::new());
for (direction, data_list) in ResponseStreamer::new(records.iter()) {
match direction {
Direction::ClientToServer => {
@ -177,10 +198,8 @@ pub async fn play(
//let mut buf = vec![0; data.len().saturating_sub(50).max(1)];
//let resp = stream.next().await.unwrap().unwrap();
while total_recv < reduced_len {
let resp = match tokio::time::timeout(
TIMEOUT,
stream.next(),
)
let resp =
match tokio::time::timeout(TIMEOUT, stream.next())
.await
{
Ok(v) => v.unwrap().unwrap(),
@ -219,8 +238,15 @@ pub async fn play(
}));
//tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
for handle in handles {
handle.await.unwrap();
}
}
}
TlsMode::None | TlsMode::Server => {
for _i in 0..repeat {
let mut handles = Vec::new();
for (id, (_server_name, records)) in records.iter() {
/*if *id != 33 {
continue
@ -235,9 +261,10 @@ pub async fn play(
drop(running_guard);
let limiter = limiter.acquire().await.unwrap();
//let mut buf = Vec::new();
'repeat: for _i in 0..repeat {
'repeat: for _i in 0..1 {
let stream = TcpStream::connect(connect_to).await.unwrap();
let mut stream = Framed::new(stream, crate::http::HttpClientCodec::new());
let mut stream =
Framed::new(stream, crate::http::HttpClientCodec::new());
/*let mut skip_recv = false;
for (direction, data) in records {
match direction {
@ -322,11 +349,10 @@ pub async fn play(
//let mut buf = Vec::new();
//stream.read_buf(&mut buf).await.ok();
//let mut buf = vec![0; data.len().saturating_sub(50).max(1)];
let mut resp = Vec::new();
while total_recv < reduced_len {
let resp = match tokio::time::timeout(
TIMEOUT,
stream.next(),
)
resp =
match tokio::time::timeout(TIMEOUT, stream.next())
.await
{
Ok(None) => break,
@ -363,6 +389,9 @@ pub async fn play(
"({}) RECV NOT ENOUGH {} / {}",
id, total_recv, total_len
);
if resp.len() < 1024 {
print_bin(&resp);
}
} else if debug {
println!("[CLT] ({id}) << {total_len} OK");
}
@ -384,27 +413,13 @@ pub async fn play(
}));
//tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
}
}
tokio::spawn({
let running = running.clone();
async move {
let mut last_count = 0;
loop {
tokio::time::sleep(TIMEOUT).await;
println!("Running: {:?}", running.lock().await);
let new_count = counter.load(std::sync::atomic::Ordering::Relaxed);
if new_count == last_count {
println!("Stalled at {} / {}, stopping", new_count, total);
std::process::exit(0);
}
last_count = new_count;
}
}
});
for handle in handles {
handle.await.unwrap();
}
}
}
}
println!("Unfinished: {:?}", running.lock().await);
std::process::exit(0);
}

View file

@ -212,8 +212,19 @@ pub async fn play(
.map_err(|e| panic!("{e:?} with name `{server_name}`"))
.unwrap();
let mut stream = Framed::new(stream, crate::http::HttpServerCodec::new());
let mut break_next = false;
//let mut previous = Vec::new();
while let Some(req) = stream.next().await {
loop {
let Ok(req) = tokio::time::timeout(tokio::time::Duration::from_secs(1), stream.next()).await else {
if break_next {
break;
} else {
continue;
}
};
let Some(req) = req else {
break;
};
let req = req.unwrap();
//println!("REQUEST");
//print_bin(&req);
@ -265,7 +276,7 @@ pub async fn play(
stream.flush().await.unwrap();
}
if *last {
break;
break_next = true;
}
} else {
println!("No response found for SNI=`{server_name}`");
@ -385,7 +396,7 @@ pub async fn play(
}
}
if *last {
break;
//break;
}
} else {
println!("[SRV] No response found");