Skip to content

Commit 857da6d

Browse files
committed
clippy --fix style & potential bugs
- DNS /etc/resolv.conf auto reloader exit directly if file not exists - socks5 PasswdAuthResponse::read_from didn't await
1 parent 85c99b9 commit 857da6d

File tree

18 files changed

+88
-111
lines changed

18 files changed

+88
-111
lines changed

crates/shadowsocks-service/src/acl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl ParsingRules {
269269
.size_limit(REGEX_SIZE_LIMIT)
270270
.unicode(false)
271271
.build()
272-
.map_err(|err| Error::new(ErrorKind::Other, format!("{} regex error: {}", name, err)))
272+
.map_err(|err| Error::new(ErrorKind::Other, format!("{name} regex error: {err}")))
273273
}
274274

275275
fn into_rules(self) -> io::Result<Rules> {

crates/shadowsocks-service/src/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ impl Config {
13591359
let err = Error::new(
13601360
ErrorKind::Malformed,
13611361
"`protocol` invalid",
1362-
Some(format!("unrecognized protocol {}", p)),
1362+
Some(format!("unrecognized protocol {p}")),
13631363
);
13641364
return Err(err);
13651365
}
@@ -1390,7 +1390,7 @@ impl Config {
13901390
let err = Error::new(
13911391
ErrorKind::Malformed,
13921392
"`protocol` invalid",
1393-
Some(format!("unrecognized protocol {}", p)),
1393+
Some(format!("unrecognized protocol {p}")),
13941394
);
13951395
return Err(err);
13961396
}
@@ -1549,7 +1549,7 @@ impl Config {
15491549
let err = Error::new(
15501550
ErrorKind::Invalid,
15511551
"acl loading failed",
1552-
Some(format!("file {}, error: {}", acl_path, err)),
1552+
Some(format!("file {acl_path}, error: {err}")),
15531553
);
15541554
return Err(err);
15551555
}
@@ -1587,7 +1587,7 @@ impl Config {
15871587
let err = Error::new(
15881588
ErrorKind::Invalid,
15891589
"unsupported method",
1590-
Some(format!("`{}` is not a supported method", m)),
1590+
Some(format!("`{m}` is not a supported method")),
15911591
);
15921592
return Err(err);
15931593
}
@@ -1603,7 +1603,7 @@ impl Config {
16031603
let err = Error::new(
16041604
ErrorKind::MissingField,
16051605
"`password` is required",
1606-
Some(format!("`password` is required for method {}", method)),
1606+
Some(format!("`password` is required for method {method}")),
16071607
);
16081608
return Err(err);
16091609
}
@@ -1692,7 +1692,7 @@ impl Config {
16921692
let err = Error::new(
16931693
ErrorKind::MissingField,
16941694
"`password` is required",
1695-
Some(format!("`password` is required for method {}", method)),
1695+
Some(format!("`password` is required for method {method}")),
16961696
);
16971697
return Err(err);
16981698
}
@@ -1794,7 +1794,7 @@ impl Config {
17941794
let err = Error::new(
17951795
ErrorKind::Invalid,
17961796
"acl loading failed",
1797-
Some(format!("file {}, error: {}", acl_path, err)),
1797+
Some(format!("file {acl_path}, error: {err}")),
17981798
);
17991799
return Err(err);
18001800
}
@@ -1849,7 +1849,7 @@ impl Config {
18491849
let err = Error::new(
18501850
ErrorKind::Invalid,
18511851
"unsupported method",
1852-
Some(format!("`{}` is not a supported method", m)),
1852+
Some(format!("`{m}` is not a supported method")),
18531853
);
18541854
return Err(err);
18551855
}
@@ -1954,7 +1954,7 @@ impl Config {
19541954
let err = Error::new(
19551955
ErrorKind::Invalid,
19561956
"acl loading failed",
1957-
Some(format!("file {}, error: {}", acl_path, err)),
1957+
Some(format!("file {acl_path}, error: {err}")),
19581958
);
19591959
return Err(err);
19601960
}

crates/shadowsocks-service/src/local/http/dispatcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl HttpDispatcher {
192192
method, self.client_addr, host, err
193193
);
194194

195-
let mut resp = Response::new(Body::from(format!("relay failed to {}", host)));
195+
let mut resp = Response::new(Body::from(format!("relay failed to {host}")));
196196
*resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
197197
return Ok(resp);
198198
}

crates/shadowsocks-service/src/local/http/http_stream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl ProxyHttpStream {
3434
let cx = match TlsConnector::builder().request_alpns(&["h2", "http/1.1"]).build() {
3535
Ok(c) => c,
3636
Err(err) => {
37-
return Err(io::Error::new(ErrorKind::Other, format!("tls build: {}", err)));
37+
return Err(io::Error::new(ErrorKind::Other, format!("tls build: {err}")));
3838
}
3939
};
4040
let cx = tokio_native_tls::TlsConnector::from(cx);
@@ -45,15 +45,15 @@ impl ProxyHttpStream {
4545
Ok(Some(alpn)) => alpn == b"h2",
4646
Ok(None) => false,
4747
Err(err) => {
48-
let ierr = io::Error::new(ErrorKind::Other, format!("tls alpn negotiate: {}", err));
48+
let ierr = io::Error::new(ErrorKind::Other, format!("tls alpn negotiate: {err}"));
4949
return Err(ierr);
5050
}
5151
};
5252

5353
Ok(ProxyHttpStream::Https(s, negotiated_h2))
5454
}
5555
Err(err) => {
56-
let ierr = io::Error::new(ErrorKind::Other, format!("tls connect: {}", err));
56+
let ierr = io::Error::new(ErrorKind::Other, format!("tls connect: {err}"));
5757
Err(ierr)
5858
}
5959
}

crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,17 @@ impl PingBalancerContext {
457457
"chose best TCP server {}",
458458
ServerConfigFormatter::new(servers[best_idx].server_config())
459459
);
460+
} else if best_idx != old_best_idx {
461+
info!(
462+
"switched best TCP server from {} to {}",
463+
ServerConfigFormatter::new(servers[old_best_idx].server_config()),
464+
ServerConfigFormatter::new(servers[best_idx].server_config())
465+
);
460466
} else {
461-
if best_idx != old_best_idx {
462-
info!(
463-
"switched best TCP server from {} to {}",
464-
ServerConfigFormatter::new(servers[old_best_idx].server_config()),
465-
ServerConfigFormatter::new(servers[best_idx].server_config())
466-
);
467-
} else {
468-
debug!(
469-
"kept best TCP server {}",
470-
ServerConfigFormatter::new(servers[old_best_idx].server_config())
471-
);
472-
}
467+
debug!(
468+
"kept best TCP server {}",
469+
ServerConfigFormatter::new(servers[old_best_idx].server_config())
470+
);
473471
}
474472
}
475473

@@ -492,19 +490,17 @@ impl PingBalancerContext {
492490
"chose best UDP server {}",
493491
ServerConfigFormatter::new(servers[best_idx].server_config())
494492
);
493+
} else if best_idx != old_best_idx {
494+
info!(
495+
"switched best UDP server from {} to {}",
496+
ServerConfigFormatter::new(servers[old_best_idx].server_config()),
497+
ServerConfigFormatter::new(servers[best_idx].server_config())
498+
);
495499
} else {
496-
if best_idx != old_best_idx {
497-
info!(
498-
"switched best UDP server from {} to {}",
499-
ServerConfigFormatter::new(servers[old_best_idx].server_config()),
500-
ServerConfigFormatter::new(servers[best_idx].server_config())
501-
);
502-
} else {
503-
debug!(
504-
"kept best UDP server {}",
505-
ServerConfigFormatter::new(servers[old_best_idx].server_config())
506-
);
507-
}
500+
debug!(
501+
"kept best UDP server {}",
502+
ServerConfigFormatter::new(servers[old_best_idx].server_config())
503+
);
508504
}
509505
}
510506
}

crates/shadowsocks-service/src/local/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ async fn flow_report_task(stat_addr: LocalFlowStatAddress, flow_stat: Arc<FlowSt
443443
let tx = flow_stat.tx();
444444
let rx = flow_stat.rx();
445445

446-
let buf: [u64; 2] = [tx as u64, rx as u64];
446+
let buf: [u64; 2] = [tx, rx];
447447
let buf = unsafe { slice::from_raw_parts(buf.as_ptr() as *const _, 16) };
448448

449449
match stat_addr {

crates/shadowsocks-service/src/local/net/udp/association.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,14 @@ where
441441
err
442442
);
443443
}
444-
} else {
445-
if let Err(err) = self.dispatch_received_proxied_packet(target_addr, data).await {
446-
error!(
447-
"udp relay {} -> {} (proxied) with {} bytes, error: {}",
448-
self.peer_addr,
449-
target_addr,
450-
data.len(),
451-
err
452-
);
453-
}
444+
} else if let Err(err) = self.dispatch_received_proxied_packet(target_addr, data).await {
445+
error!(
446+
"udp relay {} -> {} (proxied) with {} bytes, error: {}",
447+
self.peer_addr,
448+
target_addr,
449+
data.len(),
450+
err
451+
);
454452
}
455453
}
456454

crates/shadowsocks-service/src/local/redir/sys/unix/bsd_pf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,6 @@ pub static PF: Lazy<PacketFilter> = Lazy::new(|| match PacketFilter::open() {
273273
panic!("open /dev/pf permission denied, consider restart with root user");
274274
}
275275
Err(err) => {
276-
panic!("open /dev/pf {}", err);
276+
panic!("open /dev/pf {err}");
277277
}
278278
});

crates/shadowsocks-service/src/local/socks/server/socks5/tcprelay.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Socks5TcpHandler {
120120

121121
return Err(Error::new(
122122
ErrorKind::Other,
123-
format!("Username/Password Authentication Initial request failed: {}", err),
123+
format!("Username/Password Authentication Initial request failed: {err}"),
124124
));
125125
}
126126
};
@@ -174,8 +174,7 @@ impl Socks5TcpHandler {
174174
Err(Error::new(
175175
ErrorKind::Other,
176176
format!(
177-
"Username/Password Authentication failed, user: {}, password: {}",
178-
user_name, password
177+
"Username/Password Authentication failed, user: {user_name}, password: {password}"
179178
),
180179
))
181180
}

crates/shadowsocks-service/src/local/tun/tcp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl TcpTun {
291291
let mut sockets_to_remove = Vec::new();
292292

293293
for (socket_handle, control) in sockets.iter() {
294-
let socket_handle = socket_handle.clone();
294+
let socket_handle = *socket_handle;
295295
let socket = iface.get_socket::<TcpSocket>(socket_handle);
296296
let mut control = control.lock();
297297

@@ -308,7 +308,7 @@ impl TcpTun {
308308

309309
if !socket.is_open() || socket.state() == TcpState::Closed {
310310
sockets_to_remove.push(socket_handle);
311-
close_socket_control(&mut *control);
311+
close_socket_control(&mut control);
312312
continue;
313313
}
314314

@@ -335,7 +335,7 @@ impl TcpTun {
335335
Err(err) => {
336336
error!("socket recv error: {}", err);
337337
sockets_to_remove.push(socket_handle);
338-
close_socket_control(&mut *control);
338+
close_socket_control(&mut control);
339339
break;
340340
}
341341
}
@@ -362,7 +362,7 @@ impl TcpTun {
362362
Err(err) => {
363363
error!("socket send error: {}", err);
364364
sockets_to_remove.push(socket_handle);
365-
close_socket_control(&mut *control);
365+
close_socket_control(&mut control);
366366
break;
367367
}
368368
}

0 commit comments

Comments
 (0)