ssmanager support default --plugin and --plugin-opts

- fixes #421
This commit is contained in:
zonyitoo
2021-08-17 17:35:36 +08:00
parent a5bf57a1de
commit fc40cef2c3
3 changed files with 51 additions and 4 deletions
+12
View File
@@ -21,6 +21,7 @@ use shadowsocks_service::{
shadowsocks::{
config::{ManagerAddr, Mode},
crypto::v1::{available_ciphers, CipherKind},
plugin::PluginConfig,
},
};
@@ -55,6 +56,9 @@ fn main() {
(@arg ENCRYPT_METHOD: -m --("encrypt-method") +takes_value possible_values(available_ciphers()) "Default encryption method")
(@arg TIMEOUT: --timeout +takes_value {validator::validate_u64} "Default timeout seconds for TCP relay")
(@arg PLUGIN: --plugin +takes_value requires[SERVER_ADDR] "Default SIP003 (https://shadowsocks.org/en/spec/Plugin.html) plugin")
(@arg PLUGIN_OPT: --("plugin-opts") +takes_value requires[PLUGIN] "Default SIP003 plugin options")
(@arg ACL: --acl +takes_value "Path to ACL (Access Control List)")
(@arg DNS: --dns +takes_value "DNS nameservers, formatted like [(tcp|udp)://]host[:port][,host[:port]]..., or unix:///path/to/dns, or predefined keys like \"google\", \"cloudflare\"")
@@ -198,6 +202,14 @@ fn main() {
if let Some(sh) = matches.value_of("SERVER_HOST") {
manager_config.server_host = sh.parse::<ManagerServerHost>().unwrap();
}
if let Some(p) = matches.value_of("PLUGIN") {
manager_config.plugin = Some(PluginConfig {
plugin: p.to_owned(),
plugin_opts: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
plugin_args: Vec::new(),
});
}
}
// Overrides
+37 -4
View File
@@ -514,6 +514,8 @@ pub struct ManagerConfig {
pub addr: ManagerAddr,
/// Manager's default method
pub method: Option<CipherKind>,
/// Manager's default plugin
pub plugin: Option<PluginConfig>,
/// Timeout for TCP connections, setting to manager's created servers
pub timeout: Option<Duration>,
/// IP/Host for servers to bind (inbound)
@@ -530,6 +532,7 @@ impl ManagerConfig {
ManagerConfig {
addr,
method: None,
plugin: None,
timeout: None,
server_host: ManagerServerHost::default(),
mode: Mode::TcpOnly,
@@ -1190,14 +1193,14 @@ impl Config {
let mut nsvr = ServerConfig::new(addr, pwd, method);
nsvr.set_mode(global_mode);
if let Some(p) = config.plugin {
if let Some(ref p) = config.plugin {
// SIP008 allows "plugin" to be an empty string
// Empty string implies "no plugin"
if !p.is_empty() {
let plugin = PluginConfig {
plugin: p,
plugin_opts: config.plugin_opts,
plugin_args: config.plugin_args.unwrap_or_default(),
plugin: p.clone(),
plugin_opts: config.plugin_opts.clone(),
plugin_args: config.plugin_args.clone().unwrap_or_default(),
};
nsvr.set_plugin(plugin);
}
@@ -1362,6 +1365,18 @@ impl Config {
}
}
if let Some(p) = config.plugin {
// SIP008 allows "plugin" to be an empty string
// Empty string implies "no plugin"
if !p.is_empty() {
manager_config.plugin = Some(PluginConfig {
plugin: p,
plugin_opts: config.plugin_opts,
plugin_args: config.plugin_args.unwrap_or_default(),
});
}
}
nconfig.manager = Some(manager_config);
}
@@ -1870,6 +1885,24 @@ impl fmt::Display for Config {
if jconf.mode.is_none() {
jconf.mode = Some(m.mode.to_string());
}
if jconf.method.is_none() {
if let Some(ref m) = m.method {
jconf.method = Some(m.to_string());
}
}
if jconf.plugin.is_none() {
if let Some(ref p) = m.plugin {
jconf.plugin = Some(p.plugin.clone());
if let Some(ref o) = p.plugin_opts {
jconf.plugin_opts = Some(o.clone());
}
if !p.plugin_args.is_empty() {
jconf.plugin_args = Some(p.plugin_args.clone());
}
}
}
}
if self.no_delay {
@@ -237,6 +237,8 @@ impl Manager {
plugin_args: Vec::new(),
};
svr_cfg.set_plugin(p);
} else if let Some(ref plugin) = self.svr_cfg.plugin {
svr_cfg.set_plugin(plugin.clone());
}
let mode = match req.mode {