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

add disable opt for local servers #543

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/shadowsocks-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ struct SSLocalExtConfig {
local_address: Option<String>,
local_port: u16,

#[serde(skip_serializing_if = "Option::is_none")]
disabled: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
mode: Option<String>,

Expand Down Expand Up @@ -998,6 +1001,10 @@ impl Config {
// `locals` are only effective in local server
if let Some(locals) = config.locals {
for local in locals {
if local.disabled.unwrap_or(false) {
continue;
}

if local.local_port == 0 {
let err = Error::new(ErrorKind::Malformed, "`local_port` cannot be 0", None);
return Err(err);
Expand Down Expand Up @@ -1667,6 +1674,7 @@ impl fmt::Display for Config {
ServerAddr::SocketAddr(ref sa) => sa.port(),
ServerAddr::DomainName(.., port) => port,
},
disabled: None,
local_udp_address: local.udp_addr.as_ref().map(|udp_addr| match udp_addr {
ServerAddr::SocketAddr(sa) => sa.ip().to_string(),
ServerAddr::DomainName(dm, ..) => dm.to_string(),
Expand Down