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
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions 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 @@ -872,7 +874,16 @@ impl Config {

// Ext servers
if let Some(servers) = config.servers {
for svr in servers {
// Filter out disabled servers
let enabled_servers = servers
.into_iter()
.filter(|ext_cfg| match ext_cfg.disable {
Some(true) => false,
_ => true,
})
.collect::<Vec<_>>();

for svr in enabled_servers {
spyophobia marked this conversation as resolved.
Show resolved Hide resolved
let address = svr.server;
let port = svr.server_port;

Expand Down Expand Up @@ -1263,9 +1274,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 +1301,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 +1317,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