Skip to content

Commit

Permalink
clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Dec 18, 2022
1 parent 26a04b9 commit e3855b4
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 46 deletions.
14 changes: 7 additions & 7 deletions bin/ssurl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
Expand All @@ -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();
Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion crates/shadowsocks-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions crates/shadowsocks-service/src/manager/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions src/daemonize/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use log::error;
/// and follow the exact behavior in shadowsocks-libev
pub fn daemonize<F: AsRef<Path>>(pid_path: Option<F>) {
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub fn read_server_password(server_name: &str) -> io::Result<String> {
}

// 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/genkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions src/service/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")]
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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();
}
},
Expand All @@ -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();
}
},
Expand All @@ -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}"),
}
}
}
Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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();
}
};
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/service/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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();
}
},
Expand All @@ -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();
}
},
Expand Down Expand Up @@ -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();
}
};
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.
Expand Down
17 changes: 9 additions & 8 deletions src/service/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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();
}
},
Expand All @@ -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();
}
},
Expand All @@ -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}"),
}
}
}
Expand Down Expand Up @@ -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();
}
};
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ pub fn run_as_user(uname: &str) {
pwd.pw_uid,
err
);
return;
}
}
}
3 changes: 2 additions & 1 deletion tests/socks4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tests/socks5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions tests/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use tokio::{

use shadowsocks_service::{
config::{Config, ConfigType},
run_local, run_server,
run_local,
run_server,
};

#[tokio::test]
Expand Down Expand Up @@ -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);
}
Loading

0 comments on commit e3855b4

Please sign in to comment.