refactor unix domain configuration
It is now possible to specify multiple domains with varying configuration.
This commit is contained in:
1 parent
fcc2b1ab7d
commit
712089a5de
4 files changed
+54
-33
No files matched your search
+32
-9
@@ -78,9 +78,9 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub pty: PtySystemSelection,
|
||||
|
||||
/// When using the MuxServer, this specifies the path to the unix
|
||||
/// domain socket to use to communicate with the mux server.
|
||||
pub mux_server_unix_domain_socket_path: Option<String>,
|
||||
/// The set of unix domains
|
||||
#[serde(default = "UnixDomain::default_unix_domains")]
|
||||
pub unix_domains: Vec<UnixDomain>,
|
||||
|
||||
/// When using the MuxServer with the NetListener, specifies
|
||||
/// the address and port combination on which it should listen
|
||||
@@ -403,6 +403,34 @@ fn default_dpi() -> f64 {
|
||||
96.0
|
||||
}
|
||||
|
||||
/// Configures an instance of a multiplexer that can be communicated
|
||||
/// with via a unix domain socket
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
pub struct UnixDomain {
|
||||
/// The path to the socket. If unspecified, a resonable default
|
||||
/// value will be computed.
|
||||
pub socket_path: Option<PathBuf>,
|
||||
|
||||
/// If true, connect to this domain automatically at startup
|
||||
pub connect_automatically: bool,
|
||||
}
|
||||
|
||||
impl UnixDomain {
|
||||
pub fn socket_path(&self) -> PathBuf {
|
||||
self.socket_path
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("sock"))
|
||||
}
|
||||
|
||||
fn default_unix_domains() -> Vec<Self> {
|
||||
vec![UnixDomain {
|
||||
socket_path: None,
|
||||
connect_automatically: false,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -418,7 +446,6 @@ impl Default for Config {
|
||||
hyperlink_rules: default_hyperlink_rules(),
|
||||
term: default_term(),
|
||||
default_prog: None,
|
||||
mux_server_unix_domain_socket_path: None,
|
||||
mux_server_bind_address: None,
|
||||
mux_server_pem_private_key: None,
|
||||
mux_server_pem_cert: None,
|
||||
@@ -433,6 +460,7 @@ impl Default for Config {
|
||||
ratelimit_mux_output_pushes_per_second: None,
|
||||
ratelimit_mux_output_scans_per_second: None,
|
||||
mux_pem_root_certs: None,
|
||||
unix_domains: UnixDomain::default_unix_domains(),
|
||||
keys: vec![],
|
||||
}
|
||||
}
|
||||
@@ -687,11 +715,6 @@ impl Config {
|
||||
fn compute_extra_defaults(&self) -> Self {
|
||||
let mut cfg = self.clone();
|
||||
|
||||
if cfg.mux_server_unix_domain_socket_path.is_none() {
|
||||
cfg.mux_server_unix_domain_socket_path =
|
||||
RUNTIME_DIR.join("sock").to_str().map(str::to_owned);
|
||||
}
|
||||
|
||||
if cfg.font_rules.is_empty() {
|
||||
// Expand out some reasonable default font rules
|
||||
let bold = self.font.make_bold();
|
||||
|
||||
+2
-2
@@ -147,7 +147,7 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<
|
||||
};
|
||||
|
||||
let domain: Arc<dyn Domain> = if opts.mux_client_as_default_domain {
|
||||
let client = Client::new_unix_domain(&config)?;
|
||||
let client = Client::new_default_unix_domain(&config)?;
|
||||
Arc::new(ClientDomain::new(client))
|
||||
} else if opts.mux_tls_client_as_default_domain {
|
||||
let client = Client::new_tls(&config)?;
|
||||
@@ -211,7 +211,7 @@ fn main() -> Result<(), Error> {
|
||||
run_terminal_gui(config, &start)
|
||||
}
|
||||
SubCommand::Cli(cli) => {
|
||||
let client = Client::new_unix_domain(&config)?;
|
||||
let client = Client::new_default_unix_domain(&config)?;
|
||||
match cli.sub {
|
||||
CliSubCommand::List => {
|
||||
let cols = vec![
|
||||
|
||||
+10
-8
@@ -1,5 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
use crate::config::Config;
|
||||
use crate::config::{Config, UnixDomain};
|
||||
use crate::frontend::gui_executor;
|
||||
use crate::mux::Mux;
|
||||
use crate::server::codec::*;
|
||||
@@ -144,13 +144,15 @@ impl Client {
|
||||
Self { sender }
|
||||
}
|
||||
|
||||
pub fn new_unix_domain(config: &Arc<Config>) -> Fallible<Self> {
|
||||
let sock_path = Path::new(
|
||||
config
|
||||
.mux_server_unix_domain_socket_path
|
||||
.as_ref()
|
||||
.ok_or_else(|| err_msg("no mux_server_unix_domain_socket_path"))?,
|
||||
);
|
||||
pub fn new_default_unix_domain(config: &Arc<Config>) -> Fallible<Self> {
|
||||
for unix_dom in &config.unix_domains {
|
||||
return Self::new_unix_domain(config, unix_dom);
|
||||
}
|
||||
bail!("no default unix domain is configured");
|
||||
}
|
||||
|
||||
pub fn new_unix_domain(_config: &Arc<Config>, unix_dom: &UnixDomain) -> Fallible<Self> {
|
||||
let sock_path = unix_dom.socket_path();
|
||||
info!("connect to {}", sock_path.display());
|
||||
let stream = Box::new(UnixStream::connect(sock_path)?);
|
||||
Ok(Self::new(stream))
|
||||
|
||||
+10
-14
@@ -854,9 +854,7 @@ impl Drop for UmaskSaver {
|
||||
/// we need to be sure that the directory that we create it in
|
||||
/// is owned by the user and has appropriate file permissions
|
||||
/// that prevent other users from manipulating its contents.
|
||||
fn safely_create_sock_path(sock_path: &str) -> Result<UnixListener, Error> {
|
||||
let sock_path = Path::new(sock_path);
|
||||
|
||||
fn safely_create_sock_path(sock_path: &Path) -> Result<UnixListener, Error> {
|
||||
debug!("setting up {}", sock_path.display());
|
||||
|
||||
let _saver = UmaskSaver::new();
|
||||
@@ -939,17 +937,15 @@ fn spawn_tls_listener(config: &Arc<Config>, executor: Box<dyn Executor>) -> Fall
|
||||
}
|
||||
|
||||
pub fn spawn_listener(config: &Arc<Config>, executor: Box<dyn Executor>) -> Fallible<()> {
|
||||
let sock_path = config
|
||||
.mux_server_unix_domain_socket_path
|
||||
.as_ref()
|
||||
.ok_or_else(|| err_msg("no mux_server_unix_domain_socket_path"))?;
|
||||
let mut listener = LocalListener::new(
|
||||
safely_create_sock_path(sock_path)?,
|
||||
executor.clone_executor(),
|
||||
);
|
||||
thread::spawn(move || {
|
||||
listener.run();
|
||||
});
|
||||
for unix_dom in &config.unix_domains {
|
||||
let mut listener = LocalListener::new(
|
||||
safely_create_sock_path(&unix_dom.socket_path())?,
|
||||
executor.clone_executor(),
|
||||
);
|
||||
thread::spawn(move || {
|
||||
listener.run();
|
||||
});
|
||||
}
|
||||
|
||||
spawn_tls_listener(config, executor.clone_executor())?;
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user