Skip to content

Commit

Permalink
Reformatted with new rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Jan 19, 2018
1 parent bdbe4d7 commit 5c89e61
Show file tree
Hide file tree
Showing 42 changed files with 954 additions and 1,104 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ $ ssserver -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "obfs-serve
## Supported Ciphers

### Stream Ciphers

* `aes-128-cfb`, `aes-128-cfb1`, `aes-128-cfb8`, `aes-128-cfb128`
* `aes-256-cfb`, `aes-256-cfb1`, `aes-256-cfb8`, `aes-256-cfb128`
* `rc4`, `rc4-md5`
* `chacha20`, `salsa20`, `chacha20-ietf`
* `dummy` (No encryption, just for debugging)
* `plain` (No encryption, just for debugging)

### AEAD Ciphers

* `aes-128-gcm`, `aes-256-gcm`
* `chacha20-ietf-poly1305`
* `aes-128-pmac-siv`, `aes-256-pmac-siv` (experimental)
Expand Down
11 changes: 6 additions & 5 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
max_width = 120
fn_call_width = 120
indent_style = "Visual"
#fn_call_width = 120
reorder_imports = true
reorder_imports_in_group = true
reorder_imported_names = true
condense_wildcard_suffixes = true
fn_args_layout = "Visual"
fn_call_style = "Visual"
chain_indent = "Visual"
#fn_args_layout = "Visual"
#fn_call_style = "Visual"
#chain_indent = "Visual"
normalize_comments = true
use_try_shorthand = true
use_try_shorthand = true
42 changes: 24 additions & 18 deletions src/bin/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
//! You have to provide all needed configuration attributes via command line parameters,
//! or you could specify a configuration file. The format of configuration file is defined
//! in mod `config`.
//!
//!

extern crate clap;
extern crate shadowsocks;
extern crate env_logger;
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate shadowsocks;
extern crate time;

use clap::{App, Arg};
Expand All @@ -22,26 +22,35 @@ use env_logger::Builder;
use env_logger::fmt::Formatter;
use log::{LevelFilter, Record};

use shadowsocks::{Config, ConfigType, ServerAddr, ServerConfig, run_local};
use shadowsocks::{run_local, Config, ConfigType, ServerAddr, ServerConfig};
use shadowsocks::plugin::PluginConfig;

fn log_time(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
if without_time {
writeln!(fmt, "[{}] {}", record.level(), record.args())
} else {
writeln!(fmt, "[{}][{}] {}", time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(), record.level(), record.args())
writeln!(fmt,
"[{}][{}] {}",
time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(),
record.level(),
record.args())
}
}

fn log_time_module(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
if without_time {
writeln!(fmt, "[{}] [{}] {}", record.level(), record.module_path().unwrap_or("*"), record.args())
writeln!(fmt,
"[{}] [{}] {}",
record.level(),
record.module_path().unwrap_or("*"),
record.args())
} else {
writeln!(fmt, "[{}][{}] [{}] {}",
time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(),
record.level(),
record.module_path().unwrap_or("*"),
record.args())
writeln!(fmt,
"[{}][{}] [{}] {}",
time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(),
record.level(),
record.module_path().unwrap_or("*"),
record.args())
}
}

Expand Down Expand Up @@ -192,9 +201,8 @@ fn main() {

let has_provided_local_config = match matches.value_of("LOCAL_ADDR") {
Some(local_addr) => {
let local_addr: SocketAddr =
local_addr.parse()
.expect("`local-addr` is not a valid IP address");
let local_addr: SocketAddr = local_addr.parse()
.expect("`local-addr` is not a valid IP address");

config.local = Some(local_addr);
true
Expand All @@ -211,10 +219,8 @@ fn main() {
config.enable_udp |= matches.is_present("ENABLE_UDP");

if let Some(p) = matches.value_of("PLUGIN") {
let plugin = PluginConfig {
plugin: p.to_owned(),
plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
};
let plugin = PluginConfig { plugin: p.to_owned(),
plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned), };

// Overrides config in file
for svr in config.server.iter_mut() {
Expand Down
107 changes: 52 additions & 55 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,72 @@ use env_logger::Builder;
use env_logger::fmt::Formatter;
use log::{LevelFilter, Record};

use shadowsocks::{Config, ConfigType, ServerAddr, ServerConfig, run_server};
use shadowsocks::{run_server, Config, ConfigType, ServerAddr, ServerConfig};
use shadowsocks::plugin::PluginConfig;

fn log_time(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
if without_time {
writeln!(fmt, "[{}] {}", record.level(), record.args())
} else {
writeln!(fmt, "[{}][{}] {}", time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(), record.level(), record.args())
writeln!(fmt,
"[{}][{}] {}",
time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(),
record.level(),
record.args())
}
}

fn log_time_module(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
if without_time {
writeln!(fmt, "[{}] [{}] {}", record.level(), record.module_path().unwrap_or("*"), record.args())
writeln!(fmt,
"[{}] [{}] {}",
record.level(),
record.module_path().unwrap_or("*"),
record.args())
} else {
writeln!(fmt, "[{}][{}] [{}] {}",
time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(),
record.level(),
record.module_path().unwrap_or("*"),
record.args())
writeln!(fmt,
"[{}][{}] [{}] {}",
time::now().strftime("%Y-%m-%d][%H:%M:%S.%f").unwrap(),
record.level(),
record.module_path().unwrap_or("*"),
record.args())
}
}

fn main() {
let matches = App::new("shadowsocks")
.version(shadowsocks::VERSION)
.about("A fast tunnel proxy that helps you bypass firewalls.")
.arg(Arg::with_name("VERBOSE")
.short("v")
.multiple(true)
.help("Set the level of debug"))
.arg(Arg::with_name("ENABLE_UDP")
.short("u")
.long("enable-udp")
.help("Enable UDP relay"))
.arg(Arg::with_name("CONFIG")
.short("c")
.long("config")
.takes_value(true)
.help("Specify config file"))
.arg(Arg::with_name("SERVER_ADDR")
.short("s")
.long("server-addr")
.takes_value(true)
.help("Server address"))
.arg(Arg::with_name("PASSWORD")
.short("k")
.long("password")
.takes_value(true)
.help("Password"))
.arg(Arg::with_name("ENCRYPT_METHOD")
.short("m")
.long("encrypt-method")
.takes_value(true)
.help("Encryption method"))
.arg(Arg::with_name("PLUGIN")
.long("plugin")
.takes_value(true)
.help("Enable SIP003 plugin"))
.arg(Arg::with_name("PLUGIN_OPT")
.long("plugin-opts")
.takes_value(true)
.help("Set SIP003 plugin options"))
.arg(Arg::with_name("LOG_WITHOUT_TIME")
.long("log-without-time")
.help("Disable time in log"))
.get_matches();
let matches = App::new("shadowsocks").version(shadowsocks::VERSION)
.about("A fast tunnel proxy that helps you bypass firewalls.")
.arg(Arg::with_name("VERBOSE").short("v")
.multiple(true)
.help("Set the level of debug"))
.arg(Arg::with_name("ENABLE_UDP").short("u")
.long("enable-udp")
.help("Enable UDP relay"))
.arg(Arg::with_name("CONFIG").short("c")
.long("config")
.takes_value(true)
.help("Specify config file"))
.arg(Arg::with_name("SERVER_ADDR").short("s")
.long("server-addr")
.takes_value(true)
.help("Server address"))
.arg(Arg::with_name("PASSWORD").short("k")
.long("password")
.takes_value(true)
.help("Password"))
.arg(Arg::with_name("ENCRYPT_METHOD").short("m")
.long("encrypt-method")
.takes_value(true)
.help("Encryption method"))
.arg(Arg::with_name("PLUGIN").long("plugin")
.takes_value(true)
.help("Enable SIP003 plugin"))
.arg(Arg::with_name("PLUGIN_OPT").long("plugin-opts")
.takes_value(true)
.help("Set SIP003 plugin options"))
.arg(Arg::with_name("LOG_WITHOUT_TIME").long("log-without-time")
.help("Disable time in log"))
.get_matches();

let mut log_builder = Builder::new();
log_builder.filter(None, LevelFilter::Info);
Expand Down Expand Up @@ -182,10 +181,8 @@ fn main() {
config.enable_udp |= matches.is_present("ENABLE_UDP");

if let Some(p) = matches.value_of("PLUGIN") {
let plugin = PluginConfig {
plugin: p.to_owned(),
plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
};
let plugin = PluginConfig { plugin: p.to_owned(),
plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned), };

// Overrides config in file
for svr in config.server.iter_mut() {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ssurl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! userinfo = websafe-base64-encode-utf8(method ":" password)

extern crate clap;
extern crate shadowsocks;
extern crate qrcode;
extern crate serde_json;
extern crate shadowsocks;

use clap::{App, Arg};

Expand Down
Loading

0 comments on commit 5c89e61

Please sign in to comment.