Skip to content

Commit c4f0687

Browse files
committed
support "protocol" in basic configuration format
- fixes #485
1 parent fff5600 commit c4f0687

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/shadowsocks-service/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ struct SSConfig {
9292
#[serde(skip_serializing_if = "Option::is_none")]
9393
local_port: Option<u16>,
9494
#[serde(skip_serializing_if = "Option::is_none")]
95+
protocol: Option<String>,
96+
#[serde(skip_serializing_if = "Option::is_none")]
9597
manager_address: Option<String>,
9698
#[serde(skip_serializing_if = "Option::is_none")]
9799
manager_port: Option<u16>,
@@ -923,6 +925,20 @@ impl Config {
923925
// shadowsocks uses SOCKS5 by default
924926
let mut local_config = LocalConfig::new(local_addr, ProtocolType::Socks);
925927
local_config.mode = global_mode;
928+
local_config.protocol = match config.protocol {
929+
None => ProtocolType::Socks,
930+
Some(p) => match p.parse::<ProtocolType>() {
931+
Ok(p) => p,
932+
Err(..) => {
933+
let err = Error::new(
934+
ErrorKind::Malformed,
935+
"`protocol` invalid",
936+
Some(format!("unrecognized protocol {}", p)),
937+
);
938+
return Err(err);
939+
}
940+
},
941+
};
926942
nconfig.local.push(local_config);
927943
}
928944

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

0 commit comments

Comments
 (0)