Skip to content

Commit 268b79b

Browse files
committed
Add TransportErrorKind::ProxyError
Signed-off-by: Eval EXEC <execvy@gmail.com>
1 parent 9b4cef9 commit 268b79b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

tentacle/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub enum TransportErrorKind {
99
/// IO error
1010
#[error("transport io error: `{0:?}`")]
1111
Io(#[from] IOError),
12+
/// Proxy server error
13+
#[error("proxy error: `{0:?}`")]
14+
ProxyError(IOError),
1215
/// Protocol not support
1316
#[error("multiaddr `{0:?}` is not supported")]
1417
NotSupported(Multiaddr),

tentacle/src/runtime/tokio_runtime/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,17 @@ where
154154
let socks5_config = socks5_config::parse(&proxy_url, onion_random_socks_auth)?;
155155

156156
let dial_addr: SocketAddr = socks5_config.proxy_url.parse().map_err(io::Error::other)?;
157-
let stream = connect_direct(dial_addr, socket_transformer).await?;
157+
let stream = connect_direct(dial_addr, socket_transformer)
158+
.await
159+
.map_err(|err| {
160+
io::Error::other(format!("connect to proxy:{}, failed: {:?}", dial_addr, err))
161+
})?;
158162

159163
super::proxy::socks5::establish_connection(stream, target_addr, socks5_config)
160164
.await
161-
.map_err(io::Error::other)
165+
.map_err(|err| {
166+
io::Error::other(format!("failed to establish connection to target:{}", err))
167+
})
162168
}
163169

164170
pub(crate) async fn connect(
@@ -174,7 +180,14 @@ pub(crate) async fn connect(
174180

175181
match proxy_url {
176182
Some(proxy_url) => {
177-
connect_by_proxy(target_addr, socket_transformer, proxy_url, false).await
183+
connect_by_proxy(target_addr, socket_transformer, proxy_url.clone(), false)
184+
.await
185+
.map_err(|err| {
186+
io::Error::new(
187+
io::ErrorKind::Other,
188+
format!("connect_by_proxy: {}, error: {}", proxy_url, err),
189+
)
190+
})
178191
}
179192
None => connect_direct(target_addr, socket_transformer).await,
180193
}

tentacle/src/transports/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,13 @@ mod os {
445445
) -> Result<TcpStream> {
446446
match crate::runtime::timeout(timeout, crate::runtime::connect(addr, tcp_config)).await {
447447
Err(_) => Err(TransportErrorKind::Io(io::ErrorKind::TimedOut.into())),
448-
Ok(res) => res.map_err(Into::into),
448+
Ok(res) => res.map_err(|err| {
449+
if err.to_string().contains("connect_by_proxy") {
450+
TransportErrorKind::ProxyError(err)
451+
} else {
452+
err.into()
453+
}
454+
}),
449455
}
450456
}
451457

@@ -463,7 +469,13 @@ mod os {
463469
.await
464470
{
465471
Err(_) => Err(TransportErrorKind::Io(io::ErrorKind::TimedOut.into())),
466-
Ok(res) => res.map_err(Into::into),
472+
Ok(res) => res.map_err(|err| {
473+
if err.to_string().contains("connect_by_proxy") {
474+
TransportErrorKind::ProxyError(err)
475+
} else {
476+
err.into()
477+
}
478+
}),
467479
}
468480
}
469481
}

0 commit comments

Comments
 (0)