Skip to content

Commit 62314d3

Browse files
Merge branch 'main' of github.com:shinnku-nikaidou/layer7benchmark
2 parents 279865c + 1c49934 commit 62314d3

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "layer7benchmark"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
description = "A simple benchmark tool for Layer 7 (HTTP) load testing"
66
license = "MIT"
@@ -12,7 +12,3 @@ clap = { version = "4.5.38", features = ["derive"] }
1212
rand = "0.9.1"
1313
reqwest = { version = "0.12.15", features = ["json"] }
1414
tokio = { version = "1.45.0", features = ["full"] }
15-
openssl = { version = "0.10", features = ["vendored"] }
16-
17-
[target.x86_64-unknown-linux-musl]
18-
linker = "x86_64-linux-musl-gcc"

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@
1111
url to download (default is https://www.google.com)
1212
-t or --time u32
1313
time to download (default is 60)
14+
-h or --help
15+
help for layer7benchmark
16+
-v or --version
17+
version for layer7benchmark
18+
--header string
19+
http header to send
20+
-i or --ip string
21+
ip to send the request to (default is automatically resolved from the url)
1422
```
15-

src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ pub struct Args {
1010

1111
#[arg(short = 't', long = "time", default_value_t = 60)]
1212
pub time: u64,
13+
14+
#[arg(short='i',long="ip", default_value = "")]
15+
pub ip: String,
1316
}

src/main.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,59 @@
11
mod args;
2+
use core::panic;
23
use std::time::Duration;
34

45
use args::Args;
56
use clap::Parser;
67
use reqwest::Client;
8+
use std::net::SocketAddr;
9+
use tokio::net::lookup_host;
710
use tokio::sync::broadcast;
11+
use url::Url;
812

913
#[tokio::main]
1014
async fn main() -> anyhow::Result<()> {
1115
let args = Args::parse();
1216
let mut handles = Vec::new();
13-
let client = Client::new();
17+
let url = args.url.clone();
18+
let parsed_url = Url::parse(&args.url)?;
19+
let domain = parsed_url.host_str().unwrap_or_default();
20+
21+
println!("the download url is: {}", url);
22+
println!("the domain is: {}", domain);
23+
let mut addrs = lookup_host((domain, 0)).await?;
24+
let ip;
25+
26+
match addrs.next() {
27+
Some(socket_addr) => {
28+
ip = socket_addr.ip();
29+
println!(
30+
"For domain '{}', no specific IP provided. System DNS lookup suggests: {}.",
31+
domain, ip
32+
);
33+
}
34+
None => {
35+
eprintln!(
36+
"Could not resolve IP for domain '{}' via system DNS lookup.",
37+
domain
38+
);
39+
panic!("Please check your command or computer.");
40+
}
41+
}
42+
43+
let client = if args.ip.is_empty() {
44+
// Client::new()
45+
Client::builder()
46+
.resolve(domain, SocketAddr::new(ip, 0))
47+
.build()?
48+
} else {
49+
Client::builder()
50+
.resolve(domain, format!("{}:0", args.ip).parse::<SocketAddr>()?)
51+
.build()?
52+
};
1453
let (shutdown_tx, _) = broadcast::channel(1);
1554

1655
for _ in 0..args.concurrent_count {
17-
let url = args.url.clone();
56+
let url = url.clone();
1857
let client = client.clone();
1958
let mut shutdown_rx = shutdown_tx.subscribe();
2059

0 commit comments

Comments
 (0)