Skip to content

Commit ffee22c

Browse files
committed
support TFO on Linux, FreeBSD, macOS and Windows
- ref #184
1 parent 468207e commit ffee22c

File tree

35 files changed

+1808
-672
lines changed

35 files changed

+1808
-672
lines changed

.github/workflows/build-and-test.yml

+20-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ jobs:
3030
profile: minimal
3131
- name: Build & Test (Default)
3232
run: cargo test --verbose --no-fail-fast
33+
- name: Build & Test (Default) - shadowsocks
34+
run: cargo test --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --no-fail-fast
3335
- name: Build & Test (--no-default-features)
3436
run: cargo test --verbose --no-default-features --no-fail-fast
37+
- name: Build & Test (--no-default-features) - shadowsocks
38+
run: cargo test --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --no-default-features --no-fail-fast
3539
- name: Build with All Features Enabled
36-
run: cargo build --verbose --features "local-redir local-dns dns-over-tls dns-over-https stream-cipher"
40+
run: cargo build --verbose --features "local-dns dns-over-tls dns-over-https stream-cipher"
41+
- name: Build with All Features Enabled - shadowsocks
42+
run: cargo build --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --features "stream-cipher"
3743

3844
build-windows:
3945
runs-on: windows-latest
@@ -53,10 +59,16 @@ jobs:
5359
profile: minimal
5460
- name: Build & Test (Default)
5561
run: cargo test --verbose --no-fail-fast
62+
- name: Build & Test (Default) - shadowsocks
63+
run: cargo test --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --no-fail-fast
5664
- name: Build & Test (--no-default-features)
5765
run: cargo test --verbose --no-default-features --no-fail-fast
66+
- name: Build & Test (--no-default-features) - shadowsocks
67+
run: cargo test --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --no-default-features --no-fail-fast
5868
- name: Build with All Features Enabled
5969
run: cargo build --verbose --features "local-dns dns-over-tls dns-over-https stream-cipher"
70+
- name: Build with All Features Enabled - shadowsocks
71+
run: cargo build --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --features "stream-cipher"
6072

6173
build-macos:
6274
runs-on: macos-latest
@@ -81,7 +93,13 @@ jobs:
8193
profile: minimal
8294
- name: Build & Test (Default)
8395
run: cargo test --verbose --no-fail-fast
96+
- name: Build & Test (Default) - shadowsocks
97+
run: cargo test --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --no-fail-fast
8498
- name: Build & Test (--no-default-features)
8599
run: cargo test --verbose --no-default-features --no-fail-fast
100+
- name: Build & Test (--no-default-features) - shadowsocks
101+
run: cargo test --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --no-default-features --no-fail-fast
86102
- name: Build with All Features Enabled
87-
run: cargo build --verbose --features "local-redir local-dns dns-over-tls dns-over-https stream-cipher"
103+
run: cargo build --verbose --features "local-dns dns-over-tls dns-over-https stream-cipher"
104+
- name: Build with All Features Enabled - shadowsocks
105+
run: cargo build --manifest-path ./crates/shadowsocks/Cargo.toml --verbose --features "stream-cipher"

Cargo.lock

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

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-rust"
3-
version = "1.10.5"
3+
version = "1.11.0"
44
authors = ["Shadowsocks Contributors"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/shadowsocks/shadowsocks-rust"
@@ -132,3 +132,6 @@ byteorder = "1.3"
132132
env_logger = "0.8"
133133
byte_string = "1.0"
134134
tokio = { version = "1", features = ["net", "time", "macros", "io-util"]}
135+
136+
[patch.crates-io]
137+
tokio = { git = "https://github.com/tokio-rs/tokio.git", features = ["full"] }

bin/sslocal.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ fn main() {
6666
(@arg DNS: --dns +takes_value "DNS nameservers, formatted like [(tcp|udp)://]host[:port][,host[:port]]..., or unix:///path/to/dns, or predefined keys like \"google\", \"cloudflare\"")
6767

6868
(@arg TCP_NO_DELAY: --("tcp-no-delay") !takes_value alias("no-delay") "Set TCP_NODELAY option for socket")
69+
(@arg TCP_FAST_OPEN: --("tcp-fast-open") !takes_value alias("fast-open") "Enable TCP Fast Open (TFO)")
6970

7071
(@arg UDP_TIMEOUT: --("udp-timeout") +takes_value {validator::validate_u64} "Timeout seconds for UDP relay")
7172
(@arg UDP_MAX_ASSOCIATIONS: --("udp-max-associations") +takes_value {validator::validate_u64} "Maximum associations to be kept simultaneously for UDP relay")
@@ -339,14 +340,18 @@ fn main() {
339340
config.no_delay = true;
340341
}
341342

343+
if matches.is_present("TCP_FAST_OPEN") {
344+
config.fast_open = true;
345+
}
346+
342347
#[cfg(any(target_os = "linux", target_os = "android"))]
343348
if let Some(mark) = matches.value_of("OUTBOUND_FWMARK") {
344349
config.outbound_fwmark = Some(mark.parse::<u32>().expect("an unsigned integer for `outbound-fwmark`"));
345350
}
346351

347352
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))]
348353
if let Some(iface) = matches.value_of("OUTBOUND_BIND_INTERFACE") {
349-
config.outbound_bind_interface = Some(From::from(iface.to_owned()));
354+
config.outbound_bind_interface = Some(iface.to_owned());
350355
}
351356

352357
if let Some(nofile) = matches.value_of("NOFILE") {

bin/ssmanager.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn main() {
6060
(@arg DNS: --dns +takes_value "DNS nameservers, formatted like [(tcp|udp)://]host[:port][,host[:port]]..., or unix:///path/to/dns, or predefined keys like \"google\", \"cloudflare\"")
6161

6262
(@arg TCP_NO_DELAY: --("tcp-no-delay") !takes_value alias("no-delay") "Set TCP_NODELAY option for socket")
63+
(@arg TCP_FAST_OPEN: --("tcp-fast-open") !takes_value alias("fast-open") "Enable TCP Fast Open (TFO)")
6364

6465
(@arg UDP_TIMEOUT: --("udp-timeout") +takes_value {validator::validate_u64} "Timeout seconds for UDP relay")
6566
(@arg UDP_MAX_ASSOCIATIONS: --("udp-max-associations") +takes_value {validator::validate_u64} "Maximum associations to be kept simultaneously for UDP relay")
@@ -147,14 +148,18 @@ fn main() {
147148
config.no_delay = true;
148149
}
149150

151+
if matches.is_present("TCP_FAST_OPEN") {
152+
config.fast_open = true;
153+
}
154+
150155
#[cfg(any(target_os = "linux", target_os = "android"))]
151156
if let Some(mark) = matches.value_of("OUTBOUND_FWMARK") {
152157
config.outbound_fwmark = Some(mark.parse::<u32>().expect("an unsigned integer for `outbound-fwmark`"));
153158
}
154159

155-
#[cfg(any(target_os = "linux", target_os = "android"))]
160+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))]
156161
if let Some(iface) = matches.value_of("OUTBOUND_BIND_INTERFACE") {
157-
config.outbound_bind_interface = Some(From::from(iface.to_owned()));
162+
config.outbound_bind_interface = Some(iface.to_owned());
158163
}
159164

160165
if let Some(m) = matches.value_of("MANAGER_ADDRESS") {

bin/ssserver.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn main() {
6161
(@arg DNS: --dns +takes_value "DNS nameservers, formatted like [(tcp|udp)://]host[:port][,host[:port]]..., or unix:///path/to/dns, or predefined keys like \"google\", \"cloudflare\"")
6262

6363
(@arg TCP_NO_DELAY: --("tcp-no-delay") !takes_value alias("no-delay") "Set TCP_NODELAY option for socket")
64+
(@arg TCP_FAST_OPEN: --("tcp-fast-open") !takes_value alias("fast-open") "Enable TCP Fast Open (TFO)")
6465

6566
(@arg UDP_TIMEOUT: --("udp-timeout") +takes_value {validator::validate_u64} "Timeout seconds for UDP relay")
6667
(@arg UDP_MAX_ASSOCIATIONS: --("udp-max-associations") +takes_value {validator::validate_u64} "Maximum associations to be kept simultaneously for UDP relay")
@@ -187,14 +188,18 @@ fn main() {
187188
config.no_delay = true;
188189
}
189190

191+
if matches.is_present("TCP_FAST_OPEN") {
192+
config.fast_open = true;
193+
}
194+
190195
#[cfg(any(target_os = "linux", target_os = "android"))]
191196
if let Some(mark) = matches.value_of("OUTBOUND_FWMARK") {
192197
config.outbound_fwmark = Some(mark.parse::<u32>().expect("an unsigned integer for `outbound-fwmark`"));
193198
}
194199

195-
#[cfg(any(target_os = "linux", target_os = "android"))]
200+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))]
196201
if let Some(iface) = matches.value_of("OUTBOUND_BIND_INTERFACE") {
197-
config.outbound_bind_interface = Some(From::from(iface.to_owned()));
202+
config.outbound_bind_interface = Some(iface.to_owned());
198203
}
199204

200205
if let Some(m) = matches.value_of("MANAGER_ADDRESS") {

crates/shadowsocks-service/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-service"
3-
version = "1.10.4"
3+
version = "1.11.0"
44
authors = ["Shadowsocks Contributors"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/shadowsocks/shadowsocks-rust"

crates/shadowsocks-service/src/config.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
//!
4242
//! These defined server will be used with a load balancing algorithm.
4343
44-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))]
45-
use std::ffi::OsString;
44+
#[cfg(any(unix, features = "local-flow-stat"))]
45+
use std::path::PathBuf;
4646
use std::{
4747
convert::{From, Infallible},
4848
default::Default,
@@ -51,7 +51,7 @@ use std::{
5151
io::Read,
5252
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
5353
option::Option,
54-
path::{Path, PathBuf},
54+
path::Path,
5555
str::FromStr,
5656
string::ToString,
5757
time::Duration,
@@ -127,6 +127,8 @@ struct SSConfig {
127127
nofile: Option<u64>,
128128
#[serde(skip_serializing_if = "Option::is_none")]
129129
ipv6_first: Option<bool>,
130+
#[serde(skip_serializing_if = "Option::is_none")]
131+
fast_open: Option<bool>,
130132
}
131133

132134
#[derive(Serialize, Deserialize, Debug, Default)]
@@ -717,6 +719,8 @@ pub struct Config {
717719

718720
/// Set `TCP_NODELAY` socket option
719721
pub no_delay: bool,
722+
/// Set `TCP_FASTOPEN` socket option
723+
pub fast_open: bool,
720724
/// `RLIMIT_NOFILE` option for *nix systems
721725
pub nofile: Option<u64>,
722726

@@ -725,7 +729,7 @@ pub struct Config {
725729
pub outbound_fwmark: Option<u32>,
726730
/// Set `SO_BINDTODEVICE` socket option for outbound sockets
727731
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))]
728-
pub outbound_bind_interface: Option<OsString>,
732+
pub outbound_bind_interface: Option<String>,
729733
/// Path to protect callback unix address, only for Android
730734
#[cfg(target_os = "android")]
731735
pub outbound_vpn_protect_path: Option<PathBuf>,
@@ -829,6 +833,7 @@ impl Config {
829833
ipv6_first: false,
830834

831835
no_delay: false,
836+
fast_open: false,
832837
nofile: None,
833838

834839
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -1275,6 +1280,11 @@ impl Config {
12751280
nconfig.no_delay = b;
12761281
}
12771282

1283+
// TCP fast open
1284+
if let Some(b) = config.fast_open {
1285+
nconfig.fast_open = b;
1286+
}
1287+
12781288
// UDP
12791289
nconfig.udp_timeout = config.udp_timeout.map(Duration::from_secs);
12801290

@@ -1758,6 +1768,10 @@ impl fmt::Display for Config {
17581768
jconf.no_delay = Some(self.no_delay);
17591769
}
17601770

1771+
if self.fast_open {
1772+
jconf.fast_open = Some(self.fast_open);
1773+
}
1774+
17611775
match self.dns {
17621776
DnsConfig::System => {}
17631777
#[cfg(feature = "trust-dns")]

0 commit comments

Comments
 (0)