Skip to content

Commit 2127354

Browse files
committed
Fixed bug, UDP relay must be started before plugin
1 parent 8be6da5 commit 2127354

File tree

5 files changed

+52
-32
lines changed

5 files changed

+52
-32
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-rust"
3-
version = "1.7.0-alpha.4"
3+
version = "1.7.0-alpha.5"
44
authors = ["Y. T. CHUNG <zonyitoo@gmail.com>"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/zonyitoo/shadowsocks-rust"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ For DNS relay server, you can set remote DNS server in configuration file with `
176176

177177
```json
178178
{
179-
"dns": "8.8.8.8:53"
179+
"dns": "8.8.8.8"
180180
}
181181
```
182182

src/relay/local.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,30 @@ use relay::udprelay::local::run as run_udp;
2828
/// run(config);
2929
/// ```
3030
pub fn run(mut config: Config) {
31-
// Hold it here, kill all plugins when Core is finished
31+
let mut vf = Vec::new();
32+
33+
if config.enable_udp {
34+
// Clone config here, because the config for TCP relay will be modified
35+
// after plugins started
36+
let udp_config = Arc::new(config.clone());
37+
38+
// Run UDP relay before starting plugins
39+
// Because plugins doesn't support UDP relay
40+
let udp_fut = run_udp(udp_config);
41+
vf.push(boxed_future(udp_fut));
42+
}
43+
44+
// Hold it here, kill all plugins when `tokio::run` is finished
3245
let plugins = launch_plugin(&mut config, PluginMode::Client).expect("Failed to launch plugins");
3346
let mon = ::monitor::monitor_signal(plugins);
3447

48+
// Recreate shared config here
3549
let config = Arc::new(config);
3650

37-
let enable_udp = config.enable_udp;
38-
3951
let tcp_fut = run_tcp(config.clone());
40-
let mut vf = vec![boxed_future(mon), boxed_future(tcp_fut)];
41-
if enable_udp {
42-
let udp_fut = run_udp(config);
43-
vf.push(boxed_future(udp_fut));
44-
}
4552

53+
vf.push(boxed_future(mon));
54+
vf.push(boxed_future(tcp_fut));
4655
tokio::run(join_all(vf).then(|res| match res {
4756
Ok(..) => Ok(()),
4857
Err(err) => panic!("Failed to run server, err: {}", err),

src/relay/server.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,30 @@ use relay::udprelay::server::run as run_udp;
2828
/// ```
2929
///
3030
pub fn run(mut config: Config) {
31-
// Hold it here, kill all plugins when Core is finished
31+
let mut vf = Vec::new();
32+
33+
if config.enable_udp {
34+
// Clone config here, because the config for TCP relay will be modified
35+
// after plugins started
36+
let udp_config = Arc::new(config.clone());
37+
38+
// Run UDP relay before starting plugins
39+
// Because plugins doesn't support UDP relay
40+
let udp_fut = run_udp(udp_config);
41+
vf.push(boxed_future(udp_fut));
42+
}
43+
44+
// Hold it here, kill all plugins when `tokio::run` is finished
3245
let plugins = launch_plugin(&mut config, PluginMode::Server).expect("Failed to launch plugins");
3346
let mon = ::monitor::monitor_signal(plugins);
3447

48+
// Recreate shared config here
3549
let config = Arc::new(config);
36-
let enable_udp = config.enable_udp;
3750

3851
let tcp_fut = run_tcp(config.clone());
39-
let mut vf = vec![boxed_future(mon), boxed_future(tcp_fut)];
40-
if enable_udp {
41-
let udp_fut = run_udp(config);
42-
vf.push(boxed_future(udp_fut));
43-
}
52+
53+
vf.push(boxed_future(mon));
54+
vf.push(boxed_future(tcp_fut));
4455

4556
tokio::run(join_all(vf).then(|res| match res {
4657
Ok(..) => Ok(()),

0 commit comments

Comments
 (0)