Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy server disable implementation #401

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Create a ShadowSocks' configuration file. Example

Detailed explanation could be found in [shadowsocks' documentation](https://github.com/shadowsocks/shadowsocks/wiki).

In shadowsocks-rust, we also have an extended configuration file format, which is able to define more than one servers:
In shadowsocks-rust, we also have an extended configuration file format, which is able to define more than one server. You can also disable individual servers.

```json
{
Expand All @@ -142,6 +142,13 @@ In shadowsocks-rust, we also have an extended configuration file format, which i
"port": 1081,
"password": "hello-kitty",
"method": "chacha20-ietf-poly1305"
},
{
"disable": true,
"address": "eg.disable.me",
"port": 1080,
"password": "hello-internet",
"method": "chacha20-ietf-poly1305"
}
],
"local_port": 8388,
Expand Down Expand Up @@ -304,6 +311,9 @@ Example configuration:
"servers": [
{
// Fields are the same as the single server's configuration

// Individual server can be disabled
// "disable": true,
"address": "0.0.0.0",
"port": 8389,
"method": "aes-256-gcm",
Expand Down
11 changes: 10 additions & 1 deletion crates/shadowsocks-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ struct SSServerExtConfig {
password: String,
method: String,
#[serde(skip_serializing_if = "Option::is_none")]
disable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
plugin: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
plugin_opts: Option<String>,
Expand Down Expand Up @@ -873,6 +875,11 @@ impl Config {
// Ext servers
if let Some(servers) = config.servers {
for svr in servers {
// Skip if server is disabled
if svr.disable.unwrap_or(false) {
continue;
}

let address = svr.server;
let port = svr.server_port;

Expand Down Expand Up @@ -1263,9 +1270,9 @@ impl fmt::Display for Config {
}

// Servers
// For 1 servers, uses standard configure format
match self.server.len() {
0 => {}
// For 1 server, uses standard configure format
1 if self.server[0].id().is_none() && self.server[0].remarks().is_none() => {
let svr = &self.server[0];

Expand All @@ -1290,6 +1297,7 @@ impl fmt::Display for Config {
});
jconf.timeout = svr.timeout().map(|t| t.as_secs());
}
// For >1 servers, uses extended multiple server format
_ => {
let mut vsvr = Vec::new();

Expand All @@ -1305,6 +1313,7 @@ impl fmt::Display for Config {
},
password: svr.password().to_string(),
method: svr.method().to_string(),
disable: None,
plugin: svr.plugin().map(|p| p.plugin.to_string()),
plugin_opts: svr.plugin().and_then(|p| p.plugin_opts.clone()),
plugin_args: svr.plugin().and_then(|p| {
Expand Down