Skip to content

Commit

Permalink
support "protocol" in basic configuration format
Browse files Browse the repository at this point in the history
- fixes #485
  • Loading branch information
zonyitoo committed Apr 7, 2021
1 parent fff5600 commit c4f0687
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/shadowsocks-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct SSConfig {
#[serde(skip_serializing_if = "Option::is_none")]
local_port: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
protocol: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
manager_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
manager_port: Option<u16>,
Expand Down Expand Up @@ -923,6 +925,20 @@ impl Config {
// shadowsocks uses SOCKS5 by default
let mut local_config = LocalConfig::new(local_addr, ProtocolType::Socks);
local_config.mode = global_mode;
local_config.protocol = match config.protocol {
None => ProtocolType::Socks,
Some(p) => match p.parse::<ProtocolType>() {
Ok(p) => p,
Err(..) => {
let err = Error::new(
ErrorKind::Malformed,
"`protocol` invalid",
Some(format!("unrecognized protocol {}", p)),
);
return Err(err);
}
},
};
nconfig.local.push(local_config);
}

Expand Down Expand Up @@ -1546,6 +1562,9 @@ impl fmt::Display for Config {
ServerAddr::SocketAddr(ref sa) => sa.port(),
ServerAddr::DomainName(.., port) => port,
});
if local.protocol != ProtocolType::Socks {
jconf.protocol = Some(local.protocol.as_str().to_owned());
}
} else {
let mut jlocals = Vec::with_capacity(self.local.len());
for local in &self.local {
Expand Down

0 comments on commit c4f0687

Please sign in to comment.