From 669d4196720557e031d61793aebe29eeae254925 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Wed, 10 Nov 2021 12:41:08 -0600 Subject: [PATCH] Remove dns resolution for ssh session and add disclaimer to distant session about dns resolution --- distant-core/src/client/session/mod.rs | 4 ++++ distant-ssh2/src/lib.rs | 30 ++++++++++++++------------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/distant-core/src/client/session/mod.rs b/distant-core/src/client/session/mod.rs index fc3d919..fdc1c3d 100644 --- a/distant-core/src/client/session/mod.rs +++ b/distant-core/src/client/session/mod.rs @@ -43,6 +43,9 @@ pub enum SessionDetails { /// Indicates session type is inmemory Inmemory { tag: String }, + + /// Indicates session type is a custom type (such as ssh) + Custom { tag: String }, } impl SessionDetails { @@ -52,6 +55,7 @@ impl SessionDetails { Self::Tcp { tag, .. } => tag.as_str(), Self::Socket { tag, .. } => tag.as_str(), Self::Inmemory { tag } => tag.as_str(), + Self::Custom { tag } => tag.as_str(), } } diff --git a/distant-ssh2/src/lib.rs b/distant-ssh2/src/lib.rs index 23d66e9..880031f 100644 --- a/distant-ssh2/src/lib.rs +++ b/distant-ssh2/src/lib.rs @@ -358,8 +358,21 @@ impl Ssh2Session { } // Determine distinct candidate ip addresses for connecting + // + // NOTE: This breaks when the host is an alias defined within an ssh config; however, + // we need to be able to resolve the IP address(es) for use in TCP connect. The + // end solution would be to have wezterm-ssh provide some means to determine the + // IP address of the end machine it is connected to, but that probably isn't + // possible with ssh. So, for now, connecting to a distant server from an + // established ssh connection requires that we can resolve the specified host let mut candidate_ips = tokio::net::lookup_host(format!("{}:{}", self.host, self.port)) - .await? + .await + .map_err(|x| { + io::Error::new( + x.kind(), + format!("{} needs to be resolvable outside of ssh: {}", self.host, x), + ) + })? .into_iter() .map(|addr| addr.ip()) .collect::>(); @@ -488,19 +501,8 @@ impl Ssh2Session { } let (t1, t2) = Transport::pair(1); - let addr = tokio::net::lookup_host(format!("{}:{}", self.host, self.port)) - .await? - .next() - .ok_or_else(|| { - io::Error::new( - io::ErrorKind::AddrNotAvailable, - format!("Failed to resolve host: {}", self.host), - ) - })?; - let tag = t1.to_connection_tag(); - - let session = - Session::initialize_with_details(t1, Some(SessionDetails::Tcp { addr, tag }))?; + let tag = format!("ssh {}:{}", self.host, self.port); + let session = Session::initialize_with_details(t1, Some(SessionDetails::Custom { tag }))?; // Spawn tasks that forward requests to the ssh session // and send back responses from the ssh session