Skip to content

Commit

Permalink
fix: updated dependencies, fixed tcpconnect timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Nereuxofficial committed Oct 13, 2023
1 parent be90143 commit 877d25b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ color-eyre = "0.6.2"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
# Futures
tokio = { version = "1.32.0", features = ["full"] }
tokio = { version = "1.33.0", features = ["full"] }
futures = "0.3.28"
# Hex en/decoding
hex = "0.4.3"
Expand All @@ -26,15 +26,15 @@ mqtt-protocol = "0.11.2"
rand = "0.8.5"
rand_xoshiro = "0.6.0"
# Command line interface
clap = { version = "4.4.3", features = ["derive"] }
clap = { version = "4.4.6", features = ["derive"] }
# For serialization
serde = { version = "1.0.186", features = ["derive"] }
toml = "0.8.0"
serde = { version = "1.0.189", features = ["derive"] }
toml = "0.8.2"
# For serialization of raw bytes
serde_with = {version="3.1.0", features = ["hex"]}
serde_with = {version="3.3.0", features = ["hex"]}

# Tokio Console Support
console-subscriber = "0.1.10"
console-subscriber = "0.2.0"
[profile.release]
debug = true
codegen-units = 1
Expand Down
5 changes: 5 additions & 0 deletions lib/packet_pool.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[inner."16,96,0,4,77,81,84,84,5,192,93,85,34,21,0,15,98,99,82,85,100,109,83,68,89,117,119,98,86,54,50,22,0,6,72,55,70,79,120,77,23,0,25,1,34,234,35,0,25,118,116,78,87,72,80,101,56,48,98,52,99,86,120,102,85,107,110,114,116,86,89,68,122,88,0,14,86,52,86,108,79,115,54,55,73,100,84,81,70,68,0,6,90,48,53,99,79,57,112,4,122,230,236,0,112,24,205,229,136,20,38,12,49,107,51,69,111,109,83,86,119,70,114,0,3,50,75,86,64,54,206,187,210,50,38,0,24,57,105,111,113,118,80,115,53,68,85,111,97,56,115,79,43,81,54,86,103,77,49,54,112,21,100,50,84,116,114,75,66,73,116,88,103,106,56,97,84,84,81,89,107,81,118"]
inner = ["16,96,0,4,77,81,84,84,5,192,93,85,34,21,0,15,98,99,82,85,100,109,83,68,89,117,119,98,86,54,50,22,0,6,72,55,70,79,120,77,23,0,25,1,34,234,35,0,25,118,116,78,87,72,80,101,56,48,98,52,99,86,120,102,85,107,110,114,116,86,89,68,122,88,0,14,86,52,86,108,79,115,54,55,73,100,84,81,70,68,0,6,90,48,53,99,79,57,112,4,122,230,236,0,112,24,205,229,136,20,38,12,49,107,51,69,111,109,83,86,119,70,114,0,3,50,75,86,64,54,206,187,210,50,38,0,24,57,105,111,113,118,80,115,53,68,85,111,97,56,115,79,43,81,54,86,103,77,49,54,112,21,100,50,84,116,114,75,66,73,116,88,103,106,56,97,84,84,81,89,107,81,118", "", "", "", "", "", "", "", "", ""]

[inner."48,10,0,0,116,101,115,116,116,101,115,116"]
inner = ["16,60,0,4,77,81,84,84,4,4,0,0,0,17,72,101,108,108,111,32,77,81,84,84,32,66,114,111,107,101,114,0,5,116,111,112,105,99,0,22,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,72,255,50,0,0,0", "48,10,0,0,116,101,115,116,116,101,115,116", "224", "", "", "", "", "", "", ""]
4 changes: 2 additions & 2 deletions lib/src/mqtt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub(crate) fn generate_pingreq_packet() -> [u8; 2] {
[192, 0]
}

pub async fn test_conn_from_address(address: &str) -> color_eyre::Result<()> {
let mut stream = connect_to_broker(address).await?;
pub async fn test_conn_from_address(address: &str, timeout: u16) -> color_eyre::Result<()> {
let mut stream = connect_to_broker(address, timeout).await?;
test_connection(&mut stream).await?;
Ok(())
}
Expand Down
11 changes: 8 additions & 3 deletions lib/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ pub use tcp::*;
#[cfg(feature = "tcp")]
mod tcp {
use super::*;
use std::time::Duration;
use tokio::net::{TcpStream, ToSocketAddrs};

pub async fn connect_to_broker(address: impl ToSocketAddrs) -> Result<TcpStream> {
let tcpstream = TcpStream::connect(address).await?;
Ok(tcpstream)
pub async fn connect_to_broker(address: impl ToSocketAddrs, timeout: u16) -> Result<TcpStream> {
let tcp_stream = tokio::time::timeout(
Duration::from_millis(timeout as u64),
TcpStream::connect(address),
)
.await;
Ok(tcp_stream??)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn run_thread(
let mut counter: u64 = 0;
let mut rng = Xoshiro256PlusPlus::seed_from_u64(seed);
while counter < iterations {
let new_stream = connect_to_broker(&address.clone()).await;
let new_stream = connect_to_broker(&address.clone(), timeout).await;
if new_stream.is_err() {
// Workaround for connections not being closed fast enough. See https://stackoverflow.com/questions/76238841/cant-assign-requested-address-in-request
error!(
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct Cli {

#[derive(Subcommand, Debug)]
enum SubCommands {
// TODO: Do Fuzzing args like threads, chances etc
Fuzz {
#[arg(short, long, default_value_t = 100)]
threads: u64,
Expand Down Expand Up @@ -59,7 +58,7 @@ async fn main() -> color_eyre::Result<()> {
}
start_supervised_process(sender, cli.broker_command).await?;
let address = cli.target.clone();
test_conn_from_address(&address).await?;
test_conn_from_address(&address, cli.timeout).await?;
info!("Connection established, starting fuzzing!");
let mut rng = thread_rng();
let _ = fs::create_dir("./threads").await;
Expand Down Expand Up @@ -101,7 +100,7 @@ async fn main() -> color_eyre::Result<()> {
subscribers.push(sender.subscribe());
}
start_supervised_process(sender, cli.broker_command).await?;
test_conn_from_address(&cli.target).await?;
test_conn_from_address(&cli.target, cli.timeout).await?;
debug!("Starting replay with {} seeds", filtered_files.len());
let mut threads = vec![];
let unused_it_channel = mpsc_channel::<u64>(filtered_files.len()).0;
Expand Down

0 comments on commit 877d25b

Please sign in to comment.