Skip to content

Commit 39bb429

Browse files
committed
feat: split tx and rx
1 parent dc76ca5 commit 39bb429

File tree

5 files changed

+195
-278
lines changed

5 files changed

+195
-278
lines changed

src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ pub struct TcpSynArg {
3434
#[arg(short, long, default_value_t = 12)]
3535
pub thread: usize,
3636

37-
#[arg(short, long, default_value_t = 30000)]
38-
pub send_buffer_size: usize,
37+
#[arg(short, long, default_value_t = 10000)]
38+
pub rate: u64,
3939

40-
#[arg(short, long, default_value_t = false)]
41-
pub wait_idle: bool,
40+
#[arg(short, long, default_value_t = 2)]
41+
pub timeout: u64,
4242
}
4343

4444
fn parse_range(s: &str) -> Result<Vec<u16>> {

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub enum Error {
2525
#[error("flume try recv failed: {0}")]
2626
FlumeTryRecvFailed(#[from] flume::TryRecvError),
2727

28+
#[error("flume recv failed: {0}")]
29+
FlumeRecvFailed(#[from] flume::RecvError),
30+
2831
#[error("insufficient buffer size")]
2932
InsufficientBufferSize,
3033

src/main.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ async fn list_interfaces() -> Result<()> {
6565
}
6666

6767
async fn tcp_syn(arg: TcpSynArg) -> Result<()> {
68-
let pool = ThreadPoolBuilder::new().num_threads(arg.thread).build()?;
68+
if arg.rate <= arg.timeout {
69+
bail!("rate must be greater than timeout");
70+
}
6971

7072
let dest_ips = arg
7173
.dest_nets
@@ -101,6 +103,7 @@ async fn tcp_syn(arg: TcpSynArg) -> Result<()> {
101103
);
102104

103105
let (progress, progress_tx) = Progress::new(count);
106+
let pool = ThreadPoolBuilder::new().num_threads(arg.thread).build()?;
104107

105108
let scanner = tcp_syn::Scanner {
106109
pool: &pool,
@@ -109,11 +112,10 @@ async fn tcp_syn(arg: TcpSynArg) -> Result<()> {
109112
dest_ports: arg.dest_ports,
110113
src_ip,
111114
src_port: rand::random(),
112-
timeout: Duration::from_secs(2),
113-
wait_idle: arg.wait_idle,
114-
send_buffer_size: arg.send_buffer_size,
115-
send_progress_tx: None,
116-
recv_progress_tx: Some(progress_tx),
115+
timeout: Some(Duration::from_secs(arg.timeout)),
116+
wait: Some(Duration::from_secs_f64(1.0 / arg.rate as f64)),
117+
send_progress_tx: Some(progress_tx),
118+
recv_progress_tx: None,
117119
};
118120

119121
tokio::spawn(progress.run());
@@ -125,8 +127,10 @@ async fn tcp_syn(arg: TcpSynArg) -> Result<()> {
125127
.filter(|(_, result)| !result.opened.is_empty())
126128
{
127129
info!(
128-
"{}: opened: {:?}, unknown: {:?}",
129-
ip, result.opened, result.unknown
130+
"{}: opened: {:?}, number of unknown: {}",
131+
ip,
132+
result.opened,
133+
result.unknown.len()
130134
);
131135
}
132136
}
@@ -137,8 +141,10 @@ async fn tcp_syn(arg: TcpSynArg) -> Result<()> {
137141
.filter(|(_, result)| !result.opened.is_empty())
138142
{
139143
info!(
140-
"{}: opened: {:?}, unknown: {:?}",
141-
ip, result.opened, result.unknown
144+
"{}: opened: {:?}, number of unknown: {}",
145+
ip,
146+
result.opened,
147+
result.unknown.len()
142148
);
143149
}
144150
}
@@ -149,8 +155,10 @@ async fn tcp_syn(arg: TcpSynArg) -> Result<()> {
149155
.filter(|(_, result)| !result.opened.is_empty())
150156
{
151157
info!(
152-
"{}: opened: {:?}, unknown: {:?}",
153-
ip, result.opened, result.unknown
158+
"{}: opened: {:?}, number of unknown: {}",
159+
ip,
160+
result.opened,
161+
result.unknown.len()
154162
);
155163
}
156164
}

0 commit comments

Comments
 (0)