Skip to content

Commit

Permalink
Migrate tokio and uses new features (#108)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zonyitoo authored May 15, 2018
1 parent b37103d commit 8be6da5
Show file tree
Hide file tree
Showing 51 changed files with 2,527 additions and 1,589 deletions.
860 changes: 627 additions & 233 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shadowsocks-rust"
version = "1.6.12"
version = "1.7.0-alpha.4"
authors = ["Y. T. CHUNG <zonyitoo@gmail.com>"]
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
repository = "https://github.com/zonyitoo/shadowsocks-rust"
Expand All @@ -23,6 +23,10 @@ path = "src/bin/server.rs"
name = "ssurl"
path = "src/bin/ssurl.rs"

[[bin]]
name = "ssdns"
path = "src/bin/ssdns.rs"

[profile.release]
lto = true

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

[dependencies]
log = "0.4"
byteorder = "1.1"
byteorder = "1.2"
rand = "0.4"
time = "0.1"
clap = "2"
env_logger = "0.5.0-rc.1"
openssl = "0.9"
env_logger = "0.5"
openssl = "0.10"
libc = "0.2"
futures = "0.1"
tokio-core = "0.1"
tokio-io = "0.1"
tokio = "0.1"
lazy_static = "1.0"
serde_json = "1.0"
base64 = "0.9"
bytes = "0.4"
scoped-tls = "0.1"
ring = "0.13.0-alpha"
ring = "0.12"
md-5 = "0.7"
digest = "0.7"
typenum = "1.9"
qrcode = { version = "0.5", default-features = false }
typenum = "1.10"
qrcode = { version = "0.7", default-features = false }
subprocess = "0.1"
serde_urlencoded = "0.5"
url = "1.5"
url = "1"
byte_string = "1.0"
libsodium-ffi = { version = "0.1", optional = true }
futures-cpupool = "0.1"
miscreant = { version = "0.3", optional = true }
lru-cache = "0.1"
dns-parser = "0.7"
trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns", features = ["dns-over-rustls"] }

[target.'cfg(unix)'.dependencies]
tokio-signal = "0.1"
tokio-signal = "0.2"

[target.'cfg(windows)'.dependencies]
tokio-signal = "0.1"
tokio-signal = "0.2"
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ make install TARGET=release

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

For Windows users, if you have encountered any problem in building, check and discuss in [#102](https://github.com/shadowsocks/shadowsocks-rust/issues/102).

### **Build standalone binaries**

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

DNS Local server

```bash
# Read configuration from file
$ ssdns -c /path/to/shadowsocks.json

# Pass all parameters via command line
$ ssdns -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --dns "8.8.8.8:53"
```

For DNS relay server, you can set remote DNS server in configuration file with `dns` key in root object.

```json
{
"dns": "8.8.8.8:53"
}
```

## Supported Ciphers

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

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

```plain
ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmQ@127.0.0.1:8388/?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dwww.baidu.com
```
```plain
ss://YWVzLTI1Ni1jZmI6cGFzc3dvcmQ@127.0.0.1:8388/?plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dwww.baidu.com
```

## Notes

Expand Down
10 changes: 2 additions & 8 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM ekidd/rust-musl-builder

#ENV HTTP_PROXY="http://192.168.0.106:8118"
#ENV HTTPS_PROXY="http://192.168.0.106:8118"
ARG TOOLCHAIN=stable
FROM ekidd/rust-musl-builder:$TOOLCHAIN

ENV SODIUM_VERS="1.0.16"

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

RUN rustup install nightly
RUN rustup default nightly
RUN rustup target add x86_64-unknown-linux-musl

ENV SODIUM_STATIC=yes
ENV SODIUM_LIB_DIR=/usr/local/musl/lib
18 changes: 14 additions & 4 deletions build/build-release
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ fi

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

IMAGE='shadowsocks-rust:latest'
if $BUILD_NIGHTLY; then
IMAGE='shadowsocks-rust:nightly'
else
IMAGE='shadowsocks-rust:stable'
fi

if $BUILD_DOCKER_IMG; then
echo "* Rebuild docker image ${IMAGE} ...";
docker build -t "${IMAGE}" "$CUR_DIR";
if $BUILD_NIGHTLY; then
docker build -t "${IMAGE}" "$CUR_DIR" --build-arg TOOLCHAIN=nightly;
else
docker build -t "${IMAGE}" "$CUR_DIR" --build-arg TOOLCHAIN=stable;
fi
fi

SRC_PATH="/home/rust/src"
Expand All @@ -59,6 +67,7 @@ if $BUILD_NIGHTLY; then
docker run \
-e CARGO_TARGET_DIR="${CARGO_TARGET_DIR}" \
-e CARGO_INSTALL_ROOT="${CARGO_INSTALL_ROOT}" \
-e RUSTFLAGS="-Ctarget-feature=+aes" \
-e HTTP_PROXY="$HTTP_PROXY" \
-e HTTPS_PROXY="$HTTPS_PROXY" \
-v "${CUR_DIR}"/..:"$SRC_PATH" \
Expand All @@ -67,7 +76,7 @@ if $BUILD_NIGHTLY; then
/bin/bash -c \
"sudo mkdir -p $CARGO_TARGET_DIR \
&& sudo rm -rf $CARGO_INSTALL_ROOT \
&& rustup run nightly cargo install -f --features miscreant \
&& cargo install -f --features miscreant \
&& sudo chown -R $LOCAL_USER $CARGO_INSTALL_ROOT";
else
docker run \
Expand Down Expand Up @@ -117,6 +126,7 @@ echo "* Packaging XZ in ${PKG_PATH} ..."
tar -cJf ${PKG_PATH} \
"sslocal" \
"ssserver" \
"ssurl"
"ssurl" \
"ssdns"

echo "* Done build package ${PKG_NAME}"
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ condense_wildcard_suffixes = true
#fn_call_style = "Visual"
#chain_indent = "Visual"
normalize_comments = true
use_try_shorthand = true
use_try_shorthand = true
31 changes: 14 additions & 17 deletions src/bin/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! 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 env_logger;
Expand All @@ -18,12 +18,12 @@ use std::env;
use std::io::{self, Write};
use std::net::SocketAddr;

use env_logger::Builder;
use env_logger::fmt::Formatter;
use env_logger::Builder;
use log::{LevelFilter, Record};

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

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

let mut config = match matches.value_of("CONFIG") {
Some(cpath) => {
match Config::load_from_file(cpath, ConfigType::Local) {
Ok(cfg) => {
has_provided_config = true;
cfg
}
Err(err) => {
error!("{:?}", err);
return;
}
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Local) {
Ok(cfg) => {
has_provided_config = true;
cfg
}
}
Err(err) => {
error!("{:?}", err);
return;
}
},
None => Config::new(),
};

Expand Down Expand Up @@ -201,8 +199,7 @@ 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 Down Expand Up @@ -232,5 +229,5 @@ fn main() {

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

run_local(config).unwrap();
run_local(config);
}
26 changes: 12 additions & 14 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use std::io::{self, Write};

use clap::{App, Arg};

use env_logger::Builder;
use env_logger::fmt::Formatter;
use env_logger::Builder;
use log::{LevelFilter, Record};

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

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

let mut has_provided_config = false;
let mut config = match matches.value_of("CONFIG") {
Some(cpath) => {
match Config::load_from_file(cpath, ConfigType::Server) {
Ok(cfg) => {
has_provided_config = true;
cfg
}
Err(err) => {
error!("{:?}", err);
return;
}
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Server) {
Ok(cfg) => {
has_provided_config = true;
cfg
}
}
Err(err) => {
error!("{:?}", err);
return;
}
},
None => Config::new(),
};

Expand Down Expand Up @@ -194,5 +192,5 @@ fn main() {

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

run_server(config).unwrap();
run_server(config);
}
Loading

0 comments on commit 8be6da5

Please sign in to comment.