Tentative fix client setup
This commit is contained in:
parent
c38b24a8ed
commit
66d8aeb4a5
2 changed files with 280 additions and 254 deletions
|
|
@ -29,7 +29,7 @@ use tokio_rustls::{
|
||||||
};
|
};
|
||||||
use tokio_util::codec::Framed;
|
use tokio_util::codec::Framed;
|
||||||
|
|
||||||
const TIMEOUT: Duration = Duration::from_secs(60);
|
const TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct DummyCertVerifier;
|
struct DummyCertVerifier;
|
||||||
|
|
@ -98,13 +98,31 @@ pub async fn play(
|
||||||
sync_receiver.await.unwrap();
|
sync_receiver.await.unwrap();
|
||||||
// Semaphore used to limit the number of concurrent clients.
|
// Semaphore used to limit the number of concurrent clients.
|
||||||
// Its handle is released when the task panics.
|
// 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 counter = Arc::new(AtomicU32::new(0));
|
||||||
let running = Arc::new(Mutex::new(HashSet::new()));
|
let running = Arc::new(Mutex::new(HashSet::new()));
|
||||||
let total = records.len() * repeat as usize;
|
let total = records.len() * repeat as usize;
|
||||||
let mut handles = Vec::new();
|
|
||||||
let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap();
|
let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap();
|
||||||
let debug_mutex = Arc::new(Mutex::new(()));
|
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 {
|
match tls_mode {
|
||||||
TlsMode::Both | TlsMode::Client => {
|
TlsMode::Both | TlsMode::Client => {
|
||||||
let mut config = tokio_rustls::rustls::ClientConfig::builder()
|
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());
|
config.key_log = Arc::new(tokio_rustls::rustls::KeyLogFile::new());
|
||||||
let config = Arc::new(config);
|
let config = Arc::new(config);
|
||||||
|
for _i in 0..repeat {
|
||||||
|
let mut handles = Vec::new();
|
||||||
for (id, (server_name, records)) in records.iter() {
|
for (id, (server_name, records)) in records.iter() {
|
||||||
let connector = TlsConnector::from(config.clone());
|
let connector = TlsConnector::from(config.clone());
|
||||||
let counter = counter.clone();
|
let counter = counter.clone();
|
||||||
|
|
@ -138,13 +158,14 @@ pub async fn play(
|
||||||
let server_name =
|
let server_name =
|
||||||
ServerName::try_from(String::from_utf8(server_name.clone()).unwrap())
|
ServerName::try_from(String::from_utf8(server_name.clone()).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
'repeat: for _i in 0..repeat {
|
'repeat: for _i in 0..1 {
|
||||||
let stream = TcpStream::connect(connect_to).await.unwrap();
|
let stream = TcpStream::connect(connect_to).await.unwrap();
|
||||||
let stream = connector
|
let stream = connector
|
||||||
.connect(server_name.clone(), stream)
|
.connect(server_name.clone(), stream)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.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()) {
|
for (direction, data_list) in ResponseStreamer::new(records.iter()) {
|
||||||
match direction {
|
match direction {
|
||||||
Direction::ClientToServer => {
|
Direction::ClientToServer => {
|
||||||
|
|
@ -177,10 +198,8 @@ pub async fn play(
|
||||||
//let mut buf = vec![0; data.len().saturating_sub(50).max(1)];
|
//let mut buf = vec![0; data.len().saturating_sub(50).max(1)];
|
||||||
//let resp = stream.next().await.unwrap().unwrap();
|
//let resp = stream.next().await.unwrap().unwrap();
|
||||||
while total_recv < reduced_len {
|
while total_recv < reduced_len {
|
||||||
let resp = match tokio::time::timeout(
|
let resp =
|
||||||
TIMEOUT,
|
match tokio::time::timeout(TIMEOUT, stream.next())
|
||||||
stream.next(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(v) => v.unwrap().unwrap(),
|
Ok(v) => v.unwrap().unwrap(),
|
||||||
|
|
@ -219,8 +238,15 @@ pub async fn play(
|
||||||
}));
|
}));
|
||||||
//tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
//tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for handle in handles {
|
||||||
|
handle.await.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TlsMode::None | TlsMode::Server => {
|
TlsMode::None | TlsMode::Server => {
|
||||||
|
for _i in 0..repeat {
|
||||||
|
let mut handles = Vec::new();
|
||||||
for (id, (_server_name, records)) in records.iter() {
|
for (id, (_server_name, records)) in records.iter() {
|
||||||
/*if *id != 33 {
|
/*if *id != 33 {
|
||||||
continue
|
continue
|
||||||
|
|
@ -235,9 +261,10 @@ pub async fn play(
|
||||||
drop(running_guard);
|
drop(running_guard);
|
||||||
let limiter = limiter.acquire().await.unwrap();
|
let limiter = limiter.acquire().await.unwrap();
|
||||||
//let mut buf = Vec::new();
|
//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 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;
|
/*let mut skip_recv = false;
|
||||||
for (direction, data) in records {
|
for (direction, data) in records {
|
||||||
match direction {
|
match direction {
|
||||||
|
|
@ -322,11 +349,10 @@ pub async fn play(
|
||||||
//let mut buf = Vec::new();
|
//let mut buf = Vec::new();
|
||||||
//stream.read_buf(&mut buf).await.ok();
|
//stream.read_buf(&mut buf).await.ok();
|
||||||
//let mut buf = vec![0; data.len().saturating_sub(50).max(1)];
|
//let mut buf = vec![0; data.len().saturating_sub(50).max(1)];
|
||||||
|
let mut resp = Vec::new();
|
||||||
while total_recv < reduced_len {
|
while total_recv < reduced_len {
|
||||||
let resp = match tokio::time::timeout(
|
resp =
|
||||||
TIMEOUT,
|
match tokio::time::timeout(TIMEOUT, stream.next())
|
||||||
stream.next(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(None) => break,
|
Ok(None) => break,
|
||||||
|
|
@ -363,6 +389,9 @@ pub async fn play(
|
||||||
"({}) RECV NOT ENOUGH {} / {}",
|
"({}) RECV NOT ENOUGH {} / {}",
|
||||||
id, total_recv, total_len
|
id, total_recv, total_len
|
||||||
);
|
);
|
||||||
|
if resp.len() < 1024 {
|
||||||
|
print_bin(&resp);
|
||||||
|
}
|
||||||
} else if debug {
|
} else if debug {
|
||||||
println!("[CLT] ({id}) << {total_len} OK");
|
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::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 {
|
for handle in handles {
|
||||||
handle.await.unwrap();
|
handle.await.unwrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
println!("Unfinished: {:?}", running.lock().await);
|
println!("Unfinished: {:?}", running.lock().await);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,8 +212,19 @@ pub async fn play(
|
||||||
.map_err(|e| panic!("{e:?} with name `{server_name}`"))
|
.map_err(|e| panic!("{e:?} with name `{server_name}`"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut stream = Framed::new(stream, crate::http::HttpServerCodec::new());
|
let mut stream = Framed::new(stream, crate::http::HttpServerCodec::new());
|
||||||
|
let mut break_next = false;
|
||||||
//let mut previous = Vec::new();
|
//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();
|
let req = req.unwrap();
|
||||||
//println!("REQUEST");
|
//println!("REQUEST");
|
||||||
//print_bin(&req);
|
//print_bin(&req);
|
||||||
|
|
@ -265,7 +276,7 @@ pub async fn play(
|
||||||
stream.flush().await.unwrap();
|
stream.flush().await.unwrap();
|
||||||
}
|
}
|
||||||
if *last {
|
if *last {
|
||||||
break;
|
break_next = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("No response found for SNI=`{server_name}`");
|
println!("No response found for SNI=`{server_name}`");
|
||||||
|
|
@ -385,7 +396,7 @@ pub async fn play(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if *last {
|
if *last {
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("[SRV] No response found");
|
println!("[SRV] No response found");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue