From e3855b4a8d0b6b1e485341c9bacd69ce60cfcd16 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Sun, 18 Dec 2022 11:32:46 +0800 Subject: [PATCH] clippy --fix --- bin/ssurl.rs | 14 +++++----- crates/shadowsocks-service/src/config.rs | 9 ++++++- .../shadowsocks-service/src/manager/server.rs | 16 +++++++++--- src/daemonize/unix.rs | 4 +-- src/password.rs | 4 +-- src/service/genkey.rs | 2 +- src/service/local.rs | 26 ++++++++++++------- src/service/manager.rs | 12 ++++----- src/service/server.rs | 17 ++++++------ src/sys.rs | 1 - tests/socks4.rs | 3 ++- tests/socks5.rs | 3 ++- tests/tunnel.rs | 5 ++-- tests/udp.rs | 3 ++- 14 files changed, 73 insertions(+), 46 deletions(-) diff --git a/bin/ssurl.rs b/bin/ssurl.rs index d16625361e3f..2118a8744fcb 100644 --- a/bin/ssurl.rs +++ b/bin/ssurl.rs @@ -21,25 +21,25 @@ fn print_qrcode(encoded: &str) { let qrcode = QrCode::new(encoded.as_bytes()).unwrap(); for _ in 0..qrcode.width() + 2 { - print!("{}", WHITE); + print!("{WHITE}"); } println!(); for y in 0..qrcode.width() { - print!("{}", WHITE); + print!("{WHITE}"); for x in 0..qrcode.width() { let color = match qrcode[(x, y)] { Color::Light => WHITE, Color::Dark => BLACK, }; - print!("{}", color); + print!("{color}"); } - println!("{}", WHITE); + println!("{WHITE}"); } for _ in 0..qrcode.width() + 2 { - print!("{}", WHITE); + print!("{WHITE}"); } println!(); } @@ -50,7 +50,7 @@ fn encode(filename: &str, need_qrcode: bool) { for svr in config.server { let encoded = svr.config.to_url(); - println!("{}", encoded); + println!("{encoded}"); if need_qrcode { let encoded = svr.config.to_qrcode_url(); @@ -65,7 +65,7 @@ fn decode(encoded: &str, need_qrcode: bool) { let mut config = Config::new(ConfigType::Server); config.server.push(ServerInstanceConfig::with_server_config(svrconfig)); - println!("{}", config); + println!("{config}"); if need_qrcode { print_qrcode(encoded); diff --git a/crates/shadowsocks-service/src/config.rs b/crates/shadowsocks-service/src/config.rs index 83c95d8c9da6..a89fd290e0d2 100644 --- a/crates/shadowsocks-service/src/config.rs +++ b/crates/shadowsocks-service/src/config.rs @@ -66,7 +66,14 @@ use serde::{Deserialize, Serialize}; use shadowsocks::relay::socks5::Address; use shadowsocks::{ config::{ - ManagerAddr, Mode, ReplayAttackPolicy, ServerAddr, ServerConfig, ServerUser, ServerUserManager, ServerWeight, + ManagerAddr, + Mode, + ReplayAttackPolicy, + ServerAddr, + ServerConfig, + ServerUser, + ServerUserManager, + ServerWeight, }, crypto::CipherKind, plugin::PluginConfig, diff --git a/crates/shadowsocks-service/src/manager/server.rs b/crates/shadowsocks-service/src/manager/server.rs index af5ef3a64931..0d0558d65111 100644 --- a/crates/shadowsocks-service/src/manager/server.rs +++ b/crates/shadowsocks-service/src/manager/server.rs @@ -11,12 +11,22 @@ use shadowsocks::{ crypto::CipherKind, dns_resolver::DnsResolver, manager::protocol::{ - self, AddRequest, AddResponse, ErrorResponse, ListResponse, ManagerRequest, PingResponse, RemoveRequest, - RemoveResponse, ServerUserConfig, StatRequest, + self, + AddRequest, + AddResponse, + ErrorResponse, + ListResponse, + ManagerRequest, + PingResponse, + RemoveRequest, + RemoveResponse, + ServerUserConfig, + StatRequest, }, net::{AcceptOpts, ConnectOpts}, plugin::PluginConfig, - ManagerListener, ServerAddr, + ManagerListener, + ServerAddr, }; use tokio::{sync::Mutex, task::JoinHandle}; diff --git a/src/daemonize/unix.rs b/src/daemonize/unix.rs index 70f9f64b1c78..4ecf8b73d418 100644 --- a/src/daemonize/unix.rs +++ b/src/daemonize/unix.rs @@ -9,9 +9,9 @@ use log::error; /// and follow the exact behavior in shadowsocks-libev pub fn daemonize>(pid_path: Option) { let pwd = current_dir() - .unwrap_or_else(|err| panic!("cannot get current working directory, {:?}", err)) + .unwrap_or_else(|err| panic!("cannot get current working directory, {err:?}")) .canonicalize() - .unwrap_or_else(|err| panic!("cannot get absolute path to working directory, {:?}", err)); + .unwrap_or_else(|err| panic!("cannot get absolute path to working directory, {err:?}")); let mut d = Daemonize::new().umask(0).working_directory(pwd); if let Some(p) = pid_path { diff --git a/src/password.rs b/src/password.rs index a2088774bd79..f4cf0485d549 100644 --- a/src/password.rs +++ b/src/password.rs @@ -16,8 +16,8 @@ pub fn read_server_password(server_name: &str) -> io::Result { } // read from TTY - let tty_prompt = format!("({}) Password: ", server_name); - if let Ok(pwd) = rpassword::prompt_password(&tty_prompt) { + let tty_prompt = format!("({server_name}) Password: "); + if let Ok(pwd) = rpassword::prompt_password(tty_prompt) { debug!("got server {} password from tty prompt", server_name); return Ok(pwd); } diff --git a/src/service/genkey.rs b/src/service/genkey.rs index b01fdf271f1d..1be4ba1b00d8 100644 --- a/src/service/genkey.rs +++ b/src/service/genkey.rs @@ -37,7 +37,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { rng.fill_bytes(&mut key); let encoded_key = base64::encode(&key); - println!("{}", encoded_key); + println!("{encoded_key}"); } ExitCode::SUCCESS diff --git a/src/service/local.rs b/src/service/local.rs index 8cfdc168e9ba..64c493d112b5 100644 --- a/src/service/local.rs +++ b/src/service/local.rs @@ -14,7 +14,12 @@ use shadowsocks_service::shadowsocks::relay::socks5::Address; use shadowsocks_service::{ acl::AccessControl, config::{ - read_variable_field_value, Config, ConfigType, LocalConfig, LocalInstanceConfig, ProtocolType, + read_variable_field_value, + Config, + ConfigType, + LocalConfig, + LocalInstanceConfig, + ProtocolType, ServerInstanceConfig, }, create_local, @@ -30,7 +35,8 @@ use shadowsocks_service::{ use crate::logging; use crate::{ config::{Config as ServiceConfig, RuntimeMode}, - monitor, vparser, + monitor, + vparser, }; #[cfg(feature = "local-dns")] @@ -489,7 +495,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { match crate::config::get_default_config_path() { None => None, Some(p) => { - println!("loading default config {:?}", p); + println!("loading default config {p:?}"); Some(p) } } @@ -502,7 +508,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some(ref config_path) => match ServiceConfig::load_from_file(config_path) { Ok(c) => c, Err(err) => { - eprintln!("loading config {:?}, {}", config_path, err); + eprintln!("loading config {config_path:?}, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } }, @@ -526,7 +532,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some(cpath) => match Config::load_from_file(&cpath, ConfigType::Local) { Ok(cfg) => cfg, Err(err) => { - eprintln!("loading config {:?}, {}", cpath, err); + eprintln!("loading config {cpath:?}, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } }, @@ -549,7 +555,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } else { match crate::password::read_server_password(svr_addr) { Ok(pwd) => pwd, - Err(..) => panic!("`password` is required for server {}", svr_addr), + Err(..) => panic!("`password` is required for server {svr_addr}"), } } } @@ -615,7 +621,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some("dns") => ProtocolType::Dns, #[cfg(feature = "local-tun")] Some("tun") => ProtocolType::Tun, - Some(p) => panic!("not supported `protocol` \"{}\"", p), + Some(p) => panic!("not supported `protocol` \"{p}\""), None => ProtocolType::Socks, }; @@ -757,7 +763,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { let acl = match AccessControl::load_from_file(acl_file) { Ok(acl) => acl, Err(err) => { - eprintln!("loading ACL \"{}\", {}", acl_file, err); + eprintln!("loading ACL \"{acl_file}\", {err}"); return crate::EXIT_CODE_LOAD_ACL_FAILURE.into(); } }; @@ -808,7 +814,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } if let Err(err) = config.check_integrity() { - eprintln!("config integrity check failed, {}", err); + eprintln!("config integrity check failed, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } @@ -866,7 +872,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } // Server future resolved with error, which are listener errors in most cases Either::Left((Err(err), ..)) => { - eprintln!("server aborted with {}", err); + eprintln!("server aborted with {err}"); crate::EXIT_CODE_SERVER_ABORTED.into() } // The abort signal future resolved. Means we should just exit. diff --git a/src/service/manager.rs b/src/service/manager.rs index 8d5dc0272dde..bd124bea345e 100644 --- a/src/service/manager.rs +++ b/src/service/manager.rs @@ -262,7 +262,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { match crate::config::get_default_config_path() { None => None, Some(p) => { - println!("loading default config {:?}", p); + println!("loading default config {p:?}"); Some(p) } } @@ -275,7 +275,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some(ref config_path) => match ServiceConfig::load_from_file(config_path) { Ok(c) => c, Err(err) => { - eprintln!("loading config {:?}, {}", config_path, err); + eprintln!("loading config {config_path:?}, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } }, @@ -299,7 +299,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some(cpath) => match Config::load_from_file(&cpath, ConfigType::Manager) { Ok(cfg) => cfg, Err(err) => { - eprintln!("loading config {:?}, {}", cpath, err); + eprintln!("loading config {cpath:?}, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } }, @@ -401,7 +401,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { let acl = match AccessControl::load_from_file(acl_file) { Ok(acl) => acl, Err(err) => { - eprintln!("loading ACL \"{}\", {}", acl_file, err); + eprintln!("loading ACL \"{acl_file}\", {err}"); return crate::EXIT_CODE_LOAD_ACL_FAILURE.into(); } }; @@ -452,7 +452,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } if let Err(err) = config.check_integrity() { - eprintln!("config integrity check failed, {}", err); + eprintln!("config integrity check failed, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } @@ -507,7 +507,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } // Server future resolved with error, which are listener errors in most cases Either::Left((Err(err), ..)) => { - eprintln!("server aborted with {}", err); + eprintln!("server aborted with {err}"); crate::EXIT_CODE_SERVER_ABORTED.into() } // The abort signal future resolved. Means we should just exit. diff --git a/src/service/server.rs b/src/service/server.rs index c06b5973b5e8..7510c24a83a8 100644 --- a/src/service/server.rs +++ b/src/service/server.rs @@ -22,7 +22,8 @@ use shadowsocks_service::{ use crate::logging; use crate::{ config::{Config as ServiceConfig, RuntimeMode}, - monitor, vparser, + monitor, + vparser, }; /// Defines command line options @@ -273,7 +274,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { match crate::config::get_default_config_path() { None => None, Some(p) => { - println!("loading default config {:?}", p); + println!("loading default config {p:?}"); Some(p) } } @@ -286,7 +287,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some(ref config_path) => match ServiceConfig::load_from_file(config_path) { Ok(c) => c, Err(err) => { - eprintln!("loading config {:?}, {}", config_path, err); + eprintln!("loading config {config_path:?}, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } }, @@ -310,7 +311,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { Some(cpath) => match Config::load_from_file(&cpath, ConfigType::Server) { Ok(cfg) => cfg, Err(err) => { - eprintln!("loading config {:?}, {}", cpath, err); + eprintln!("loading config {cpath:?}, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } }, @@ -333,7 +334,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } else { match crate::password::read_server_password(svr_addr) { Ok(pwd) => pwd, - Err(..) => panic!("`password` is required for server {}", svr_addr), + Err(..) => panic!("`password` is required for server {svr_addr}"), } } } @@ -419,7 +420,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { let acl = match AccessControl::load_from_file(acl_file) { Ok(acl) => acl, Err(err) => { - eprintln!("loading ACL \"{}\", {}", acl_file, err); + eprintln!("loading ACL \"{acl_file}\", {err}"); return crate::EXIT_CODE_LOAD_ACL_FAILURE.into(); } }; @@ -471,7 +472,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } if let Err(err) = config.check_integrity() { - eprintln!("config integrity check failed, {}", err); + eprintln!("config integrity check failed, {err}"); return crate::EXIT_CODE_LOAD_CONFIG_FAILURE.into(); } @@ -526,7 +527,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode { } // Server future resolved with error, which are listener errors in most cases Either::Left((Err(err), ..)) => { - eprintln!("server aborted with {}", err); + eprintln!("server aborted with {err}"); crate::EXIT_CODE_SERVER_ABORTED.into() } // The abort signal future resolved. Means we should just exit. diff --git a/src/sys.rs b/src/sys.rs index 254e4b3d4e1b..cebd86031b2b 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -142,7 +142,6 @@ pub fn run_as_user(uname: &str) { pwd.pw_uid, err ); - return; } } } diff --git a/tests/socks4.rs b/tests/socks4.rs index cdce51f5dca5..66cf6f50435d 100644 --- a/tests/socks4.rs +++ b/tests/socks4.rs @@ -13,7 +13,8 @@ use tokio::{ use shadowsocks_service::{ config::{Config, ConfigType, LocalConfig, LocalInstanceConfig, ProtocolType, ServerInstanceConfig}, local::socks::client::Socks4TcpClient, - run_local, run_server, + run_local, + run_server, shadowsocks::{ config::{ServerAddr, ServerConfig}, crypto::CipherKind, diff --git a/tests/socks5.rs b/tests/socks5.rs index 74e6034ef3ff..c09299dc6f36 100644 --- a/tests/socks5.rs +++ b/tests/socks5.rs @@ -13,7 +13,8 @@ use tokio::{ use shadowsocks_service::{ config::{Config, ConfigType, LocalConfig, LocalInstanceConfig, ProtocolType, ServerInstanceConfig}, local::socks::client::socks5::Socks5TcpClient, - run_local, run_server, + run_local, + run_server, shadowsocks::{ config::{Mode, ServerAddr, ServerConfig}, crypto::CipherKind, diff --git a/tests/tunnel.rs b/tests/tunnel.rs index 2ad6c045a47a..d0ffdaa429bb 100644 --- a/tests/tunnel.rs +++ b/tests/tunnel.rs @@ -11,7 +11,8 @@ use tokio::{ use shadowsocks_service::{ config::{Config, ConfigType}, - run_local, run_server, + run_local, + run_server, }; #[tokio::test] @@ -137,7 +138,7 @@ async fn udp_tunnel() { let n = socket.recv(&mut buf).await.unwrap(); let recv_payload = &buf[..n]; - println!("Got reply from server: {:?}", ByteStr::new(&recv_payload)); + println!("Got reply from server: {:?}", ByteStr::new(recv_payload)); assert_eq!(MESSAGE, recv_payload); } diff --git a/tests/udp.rs b/tests/udp.rs index dba2bcabea77..1e71622ca6db 100644 --- a/tests/udp.rs +++ b/tests/udp.rs @@ -9,7 +9,8 @@ use tokio::time::{self, Duration}; use shadowsocks_service::{ config::{Config, ConfigType, LocalConfig, LocalInstanceConfig, ProtocolType, ServerInstanceConfig}, local::socks::client::socks5::Socks5UdpClient, - run_local, run_server, + run_local, + run_server, shadowsocks::{config::Mode, crypto::CipherKind, relay::socks5::Address, ServerConfig}, };