Skip to content

Commit fbf7ea1

Browse files
authored
fix: allow Stream to connect to multiple addresses (#545)
1 parent da27fc5 commit fbf7ea1

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

russh-config/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
clippy::panic
66
)]
77
use std::io::Read;
8-
use std::net::ToSocketAddrs;
98
use std::path::Path;
109

1110
use globset::Glob;
@@ -19,8 +18,6 @@ pub enum Error {
1918
HostNotFound,
2019
#[error("No home directory")]
2120
NoHome,
22-
#[error("Cannot resolve the address")]
23-
NotResolvable,
2421
#[error("{}", 0)]
2522
Io(#[from] std::io::Error),
2623
}
@@ -80,11 +77,9 @@ impl Config {
8077
.await
8178
.map_err(Into::into)
8279
} else {
83-
let address = (self.host_name.as_str(), self.port)
84-
.to_socket_addrs()?
85-
.next()
86-
.ok_or(Error::NotResolvable)?;
87-
Stream::tcp_connect(&address).await.map_err(Into::into)
80+
Stream::tcp_connect((self.host_name.as_str(), self.port))
81+
.await
82+
.map_err(Into::into)
8883
}
8984
}
9085
}

russh-config/src/proxy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::net::SocketAddr;
21
use std::pin::Pin;
32
use std::process::Stdio;
43

54
use futures::ready;
65
use futures::task::*;
76
use tokio::io::ReadBuf;
87
use tokio::net::TcpStream;
8+
use tokio::net::ToSocketAddrs;
99
use tokio::process::Command;
1010

1111
/// A type to implement either a TCP socket, or proxying through an external command.
@@ -18,8 +18,8 @@ pub enum Stream {
1818

1919
impl Stream {
2020
/// Connect a direct TCP stream (as opposed to a proxied one).
21-
pub async fn tcp_connect(addr: &SocketAddr) -> Result<Stream, std::io::Error> {
22-
Ok(Stream::Tcp(tokio::net::TcpStream::connect(addr).await?))
21+
pub async fn tcp_connect(addrs: impl ToSocketAddrs) -> Result<Stream, std::io::Error> {
22+
Ok(Stream::Tcp(tokio::net::TcpStream::connect(addrs).await?))
2323
}
2424
/// Connect through a proxy command.
2525
pub async fn proxy_command(cmd: &str, args: &[&str]) -> Result<Stream, std::io::Error> {

0 commit comments

Comments
 (0)