Skip to content

Commit 8be6da5

Browse files
authored
Migrate tokio and uses new features (#108)
* Add #102 link in README * Migrating to tokio, #100 * Migrated to tokio-signal v0.2, reformatted * Should not call tokio::spawn before tokio::run * Build nightly and stable with different image tag * Removed unnecessary rustup install * Renamed version to v1.7.0-alpha * Removed deprecated calls of Buf * Updated dependencies * [#106] Fixed bug, should not hold UDP connections forever * Lower info log to debug * Bump version to v1.7.0-alpha.2 * Implement a simple DNS relay server, bump version to v1.7.0-alpha.3 * Better logging * Fixed build on travis * Add elapsed time in log * Should not exit if handler return error * reformatted * Add test for DNS * Updated ssdns param * Use `trust-dns` and impl Trait 1. Replaced `ToSocketAddrs` with `trust-dns` 2. Uses impl Trait for functions 3. Updated dependencies 4. Fixed bugs * Bug fixed, logging crate in ssdns
1 parent b37103d commit 8be6da5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2527
-1589
lines changed

Cargo.lock

+627-233
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-rust"
3-
version = "1.6.12"
3+
version = "1.7.0-alpha.4"
44
authors = ["Y. T. CHUNG <[email protected]>"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/zonyitoo/shadowsocks-rust"
@@ -23,6 +23,10 @@ path = "src/bin/server.rs"
2323
name = "ssurl"
2424
path = "src/bin/ssurl.rs"
2525

26+
[[bin]]
27+
name = "ssdns"
28+
path = "src/bin/ssdns.rs"
29+
2630
[profile.release]
2731
lto = true
2832

@@ -32,36 +36,37 @@ sodium = ["libsodium-ffi"]
3236

3337
[dependencies]
3438
log = "0.4"
35-
byteorder = "1.1"
39+
byteorder = "1.2"
3640
rand = "0.4"
3741
time = "0.1"
3842
clap = "2"
39-
env_logger = "0.5.0-rc.1"
40-
openssl = "0.9"
43+
env_logger = "0.5"
44+
openssl = "0.10"
4145
libc = "0.2"
4246
futures = "0.1"
43-
tokio-core = "0.1"
4447
tokio-io = "0.1"
48+
tokio = "0.1"
4549
lazy_static = "1.0"
4650
serde_json = "1.0"
4751
base64 = "0.9"
4852
bytes = "0.4"
49-
scoped-tls = "0.1"
50-
ring = "0.13.0-alpha"
53+
ring = "0.12"
5154
md-5 = "0.7"
5255
digest = "0.7"
53-
typenum = "1.9"
54-
qrcode = { version = "0.5", default-features = false }
56+
typenum = "1.10"
57+
qrcode = { version = "0.7", default-features = false }
5558
subprocess = "0.1"
5659
serde_urlencoded = "0.5"
57-
url = "1.5"
60+
url = "1"
5861
byte_string = "1.0"
5962
libsodium-ffi = { version = "0.1", optional = true }
60-
futures-cpupool = "0.1"
6163
miscreant = { version = "0.3", optional = true }
64+
lru-cache = "0.1"
65+
dns-parser = "0.7"
66+
trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns", features = ["dns-over-rustls"] }
6267

6368
[target.'cfg(unix)'.dependencies]
64-
tokio-signal = "0.1"
69+
tokio-signal = "0.2"
6570

6671
[target.'cfg(windows)'.dependencies]
67-
tokio-signal = "0.1"
72+
tokio-signal = "0.2"

README.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ make install TARGET=release
5757

5858
Then `sslocal`, `ssserver` and `ssurl` will be installed in `/usr/local/bin` (variable PREFIX).
5959

60+
For Windows users, if you have encountered any problem in building, check and discuss in [#102](https://github.com/shadowsocks/shadowsocks-rust/issues/102).
61+
6062
### **Build standalone binaries**
6163

6264
Requirements:
@@ -160,6 +162,24 @@ $ ssserver -c /path/to/shadowsocks.json
160162
$ ssserver -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "obfs-server" --plugin-opts "obfs=tls"
161163
```
162164

165+
DNS Local server
166+
167+
```bash
168+
# Read configuration from file
169+
$ ssdns -c /path/to/shadowsocks.json
170+
171+
# Pass all parameters via command line
172+
$ ssdns -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --dns "8.8.8.8:53"
173+
```
174+
175+
For DNS relay server, you can set remote DNS server in configuration file with `dns` key in root object.
176+
177+
```json
178+
{
179+
"dns": "8.8.8.8:53"
180+
}
181+
```
182+
163183
## Supported Ciphers
164184

165185
### Stream Ciphers
@@ -180,9 +200,9 @@ $ ssserver -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "obfs-serve
180200

181201
1. `ssurl` is for encoding and decoding ShadowSocks URLs (SIP002). Example:
182202

183-
```plain
184-
ss://[email protected]:8388/?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dwww.baidu.com
185-
```
203+
```plain
204+
ss://[email protected]:8388/?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dwww.baidu.com
205+
```
186206
187207
## Notes
188208

build/Dockerfile

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
FROM ekidd/rust-musl-builder
2-
3-
#ENV HTTP_PROXY="http://192.168.0.106:8118"
4-
#ENV HTTPS_PROXY="http://192.168.0.106:8118"
1+
ARG TOOLCHAIN=stable
2+
FROM ekidd/rust-musl-builder:$TOOLCHAIN
53

64
ENV SODIUM_VERS="1.0.16"
75

@@ -13,9 +11,5 @@ RUN cd /home/rust/libs && \
1311
make && sudo make install && \
1412
cd .. && rm -rf libsodium-$SODIUM_VERS.tar.gz libsodium-$SODIUM_VERS
1513

16-
RUN rustup install nightly
17-
RUN rustup default nightly
18-
RUN rustup target add x86_64-unknown-linux-musl
19-
2014
ENV SODIUM_STATIC=yes
2115
ENV SODIUM_LIB_DIR=/usr/local/musl/lib

build/build-release

+14-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ fi
4040

4141
echo "* Building ${RELEASE_NAME} package ${VERSION} ..."
4242

43-
IMAGE='shadowsocks-rust:latest'
43+
if $BUILD_NIGHTLY; then
44+
IMAGE='shadowsocks-rust:nightly'
45+
else
46+
IMAGE='shadowsocks-rust:stable'
47+
fi
4448

4549
if $BUILD_DOCKER_IMG; then
4650
echo "* Rebuild docker image ${IMAGE} ...";
47-
docker build -t "${IMAGE}" "$CUR_DIR";
51+
if $BUILD_NIGHTLY; then
52+
docker build -t "${IMAGE}" "$CUR_DIR" --build-arg TOOLCHAIN=nightly;
53+
else
54+
docker build -t "${IMAGE}" "$CUR_DIR" --build-arg TOOLCHAIN=stable;
55+
fi
4856
fi
4957

5058
SRC_PATH="/home/rust/src"
@@ -59,6 +67,7 @@ if $BUILD_NIGHTLY; then
5967
docker run \
6068
-e CARGO_TARGET_DIR="${CARGO_TARGET_DIR}" \
6169
-e CARGO_INSTALL_ROOT="${CARGO_INSTALL_ROOT}" \
70+
-e RUSTFLAGS="-Ctarget-feature=+aes" \
6271
-e HTTP_PROXY="$HTTP_PROXY" \
6372
-e HTTPS_PROXY="$HTTPS_PROXY" \
6473
-v "${CUR_DIR}"/..:"$SRC_PATH" \
@@ -67,7 +76,7 @@ if $BUILD_NIGHTLY; then
6776
/bin/bash -c \
6877
"sudo mkdir -p $CARGO_TARGET_DIR \
6978
&& sudo rm -rf $CARGO_INSTALL_ROOT \
70-
&& rustup run nightly cargo install -f --features miscreant \
79+
&& cargo install -f --features miscreant \
7180
&& sudo chown -R $LOCAL_USER $CARGO_INSTALL_ROOT";
7281
else
7382
docker run \
@@ -117,6 +126,7 @@ echo "* Packaging XZ in ${PKG_PATH} ..."
117126
tar -cJf ${PKG_PATH} \
118127
"sslocal" \
119128
"ssserver" \
120-
"ssurl"
129+
"ssurl" \
130+
"ssdns"
121131

122132
echo "* Done build package ${PKG_NAME}"

rustfmt.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ condense_wildcard_suffixes = true
99
#fn_call_style = "Visual"
1010
#chain_indent = "Visual"
1111
normalize_comments = true
12-
use_try_shorthand = true
12+
use_try_shorthand = true

src/bin/local.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! You have to provide all needed configuration attributes via command line parameters,
44
//! or you could specify a configuration file. The format of configuration file is defined
55
//! in mod `config`.
6-
//!
6+
//!
77
88
extern crate clap;
99
extern crate env_logger;
@@ -18,12 +18,12 @@ use std::env;
1818
use std::io::{self, Write};
1919
use std::net::SocketAddr;
2020

21-
use env_logger::Builder;
2221
use env_logger::fmt::Formatter;
22+
use env_logger::Builder;
2323
use log::{LevelFilter, Record};
2424

25-
use shadowsocks::{run_local, Config, ConfigType, ServerAddr, ServerConfig};
2625
use shadowsocks::plugin::PluginConfig;
26+
use shadowsocks::{run_local, Config, ConfigType, ServerAddr, ServerConfig};
2727

2828
fn log_time(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
2929
if without_time {
@@ -148,18 +148,16 @@ fn main() {
148148
let mut has_provided_config = false;
149149

150150
let mut config = match matches.value_of("CONFIG") {
151-
Some(cpath) => {
152-
match Config::load_from_file(cpath, ConfigType::Local) {
153-
Ok(cfg) => {
154-
has_provided_config = true;
155-
cfg
156-
}
157-
Err(err) => {
158-
error!("{:?}", err);
159-
return;
160-
}
151+
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Local) {
152+
Ok(cfg) => {
153+
has_provided_config = true;
154+
cfg
161155
}
162-
}
156+
Err(err) => {
157+
error!("{:?}", err);
158+
return;
159+
}
160+
},
163161
None => Config::new(),
164162
};
165163

@@ -201,8 +199,7 @@ fn main() {
201199

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

207204
config.local = Some(local_addr);
208205
true
@@ -232,5 +229,5 @@ fn main() {
232229

233230
debug!("Config: {:?}", config);
234231

235-
run_local(config).unwrap();
232+
run_local(config);
236233
}

src/bin/server.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use std::io::{self, Write};
1919

2020
use clap::{App, Arg};
2121

22-
use env_logger::Builder;
2322
use env_logger::fmt::Formatter;
23+
use env_logger::Builder;
2424
use log::{LevelFilter, Record};
2525

26-
use shadowsocks::{run_server, Config, ConfigType, ServerAddr, ServerConfig};
2726
use shadowsocks::plugin::PluginConfig;
27+
use shadowsocks::{run_server, Config, ConfigType, ServerAddr, ServerConfig};
2828

2929
fn log_time(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
3030
if without_time {
@@ -129,18 +129,16 @@ fn main() {
129129

130130
let mut has_provided_config = false;
131131
let mut config = match matches.value_of("CONFIG") {
132-
Some(cpath) => {
133-
match Config::load_from_file(cpath, ConfigType::Server) {
134-
Ok(cfg) => {
135-
has_provided_config = true;
136-
cfg
137-
}
138-
Err(err) => {
139-
error!("{:?}", err);
140-
return;
141-
}
132+
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Server) {
133+
Ok(cfg) => {
134+
has_provided_config = true;
135+
cfg
142136
}
143-
}
137+
Err(err) => {
138+
error!("{:?}", err);
139+
return;
140+
}
141+
},
144142
None => Config::new(),
145143
};
146144

@@ -194,5 +192,5 @@ fn main() {
194192

195193
debug!("Config: {:?}", config);
196194

197-
run_server(config).unwrap();
195+
run_server(config);
198196
}

0 commit comments

Comments
 (0)