From 5d6bc3882cfc2df688b2dfd8e3e155bfd00f6247 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 5 Aug 2019 11:04:56 -0700 Subject: [PATCH] require all domains to have names --- src/config.rs | 12 ++++++++++++ src/main.rs | 9 ++++++--- src/mux/domain.rs | 19 ++++++++++++++++--- src/server/domain.rs | 14 ++++++++++++++ src/ssh.rs | 12 +++++++++++- 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index aaab3313c..35e937a81 100644 --- a/src/config.rs +++ b/src/config.rs @@ -426,6 +426,10 @@ impl DaemonOptions { #[derive(Default, Debug, Clone, Deserialize)] pub struct SshDomain { + /// The name of this specific domain. Must be unique amongst + /// all types of domain in the configuration file. + pub name: String, + /// identifies the host:port pair of the remote server. pub remote_address: String, @@ -445,6 +449,10 @@ pub struct SshDomain { /// with via a unix domain socket #[derive(Default, Debug, Clone, Deserialize)] pub struct UnixDomain { + /// The name of this specific domain. Must be unique amongst + /// all types of domain in the configuration file. + pub name: String, + /// The path to the socket. If unspecified, a resonable default /// value will be computed. pub socket_path: Option, @@ -527,6 +535,10 @@ pub struct TlsDomainServer { #[derive(Default, Debug, Clone, Deserialize)] pub struct TlsDomainClient { + /// The name of this specific domain. Must be unique amongst + /// all types of domain in the configuration file. + pub name: String, + /// identifies the host:port pair of the remote server. pub remote_address: String, diff --git a/src/main.rs b/src/main.rs index 4b1865a7c..9d09868f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -259,8 +259,11 @@ fn run_ssh(config: Arc, opts: &SshCommand) -> Fallible<()> { let sess = ssh::ssh_connect(¶ms.host_and_port, ¶ms.username)?; let pty_system = Box::new(portable_pty::ssh::SshSession::new(sess)); - let domain: Arc = - Arc::new(ssh::RemoteSshDomain::with_pty_system(&config, pty_system)); + let domain: Arc = Arc::new(ssh::RemoteSshDomain::with_pty_system( + &opts.user_at_host_and_port, + &config, + pty_system, + )); let mux = Rc::new(mux::Mux::new(&config, &domain)); Mux::set_mux(&mux); @@ -313,7 +316,7 @@ fn run_terminal_gui(config: Arc, opts: &StartCommand) -> Fallibl None }; - let domain: Arc = Arc::new(LocalDomain::new(&config)?); + let domain: Arc = Arc::new(LocalDomain::new("local", &config)?); let mux = Rc::new(mux::Mux::new(&config, &domain)); Mux::set_mux(&mux); diff --git a/src/mux/domain.rs b/src/mux/domain.rs index 7d77160dd..3cc85cf4f 100644 --- a/src/mux/domain.rs +++ b/src/mux/domain.rs @@ -44,6 +44,9 @@ pub trait Domain: Downcast { /// a handle on the domain later. fn domain_id(&self) -> DomainId; + /// Returns the name of the domain + fn domain_name(&self) -> &str; + /// Re-attach to any tabs that might be pre-existing in this domain fn attach(&self) -> Fallible<()>; @@ -59,21 +62,27 @@ pub struct LocalDomain { pty_system: Box, config: Arc, id: DomainId, + name: String, } impl LocalDomain { - pub fn new(config: &Arc) -> Result { + pub fn new(name: &str, config: &Arc) -> Result { let pty_system = config.pty.get()?; - Ok(Self::with_pty_system(config, pty_system)) + Ok(Self::with_pty_system(name, config, pty_system)) } - pub fn with_pty_system(config: &Arc, pty_system: Box) -> Self { + pub fn with_pty_system( + name: &str, + config: &Arc, + pty_system: Box, + ) -> Self { let config = Arc::clone(config); let id = alloc_domain_id(); Self { pty_system, config, id, + name: name.to_string(), } } } @@ -118,6 +127,10 @@ impl Domain for LocalDomain { self.id } + fn domain_name(&self) -> &str { + &self.name + } + fn attach(&self) -> Fallible<()> { Ok(()) } diff --git a/src/server/domain.rs b/src/server/domain.rs index 9757ce415..cbdb8b9ca 100644 --- a/src/server/domain.rs +++ b/src/server/domain.rs @@ -61,6 +61,16 @@ pub enum ClientDomainConfig { Ssh(SshDomain), } +impl ClientDomainConfig { + fn name(&self) -> &str { + match self { + ClientDomainConfig::Unix(unix) => &unix.name, + ClientDomainConfig::Tls(tls) => &tls.name, + ClientDomainConfig::Ssh(ssh) => &ssh.name, + } + } +} + impl ClientInner { pub fn new(local_domain_id: DomainId, client: Client) -> Self { // Assumption: that the domain id on the other end is @@ -133,6 +143,10 @@ impl Domain for ClientDomain { self.local_domain_id } + fn domain_name(&self) -> &str { + self.config.name() + } + fn spawn( &self, size: PtySize, diff --git a/src/ssh.rs b/src/ssh.rs index a9cf66395..55c2ec8d7 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -227,16 +227,22 @@ pub struct RemoteSshDomain { pty_system: Box, config: Arc, id: DomainId, + name: String, } impl RemoteSshDomain { - pub fn with_pty_system(config: &Arc, pty_system: Box) -> Self { + pub fn with_pty_system( + name: &str, + config: &Arc, + pty_system: Box, + ) -> Self { let config = Arc::clone(config); let id = alloc_domain_id(); Self { pty_system, config, id, + name: name.to_string(), } } } @@ -281,6 +287,10 @@ impl Domain for RemoteSshDomain { self.id } + fn domain_name(&self) -> &str { + &self.name + } + fn attach(&self) -> Fallible<()> { Ok(()) }