From 4fff9f9dda33ffdbc74694b1c4484bf004a01f3e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 29 Nov 2022 11:10:26 -0500 Subject: [PATCH 1/3] chanmgr: Report Pt errors correctly. We were panicking if the PtMgr gave us an error, which isn't so good. --- crates/tor-chanmgr/src/factory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tor-chanmgr/src/factory.rs b/crates/tor-chanmgr/src/factory.rs index 863cd442f..68ef30793 100644 --- a/crates/tor-chanmgr/src/factory.rs +++ b/crates/tor-chanmgr/src/factory.rs @@ -160,7 +160,7 @@ impl ChannelFactory for CompoundFactory { Some(mgr) => mgr .factory_for_transport(a.transport()) .await - .expect("TODO pt-client") + .map_err(|e| crate::Error::Pt(e))? .ok_or_else(|| crate::Error::NoSuchTransport(a.transport().clone().into()))?, None => return Err(crate::Error::NoSuchTransport(a.transport().clone().into())), }, From c6aa587dc8d105729da6081351206aaf8fd767c4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 29 Nov 2022 11:15:36 -0500 Subject: [PATCH 2/3] chanmgr: remove a now-stale TODO. --- crates/tor-chanmgr/src/mgr.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/tor-chanmgr/src/mgr.rs b/crates/tor-chanmgr/src/mgr.rs index 674faeae5..ad47b51fa 100644 --- a/crates/tor-chanmgr/src/mgr.rs +++ b/crates/tor-chanmgr/src/mgr.rs @@ -158,8 +158,6 @@ impl AbstractChanMgr { ) -> Result<(CF::Channel, ChanProvenance)> { use ChannelUsage as CU; - // TODO pt-client: This is not yet used. - let chan = self.get_or_launch_internal(target).await?; match usage { From 8cc09c27289718a82bffd7353f9db3442fdf0e96 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 29 Nov 2022 11:21:41 -0500 Subject: [PATCH 3/3] chanmgr: Distinguish failure to connect to proxy from other IO failures --- crates/tor-chanmgr/src/err.rs | 2 +- crates/tor-chanmgr/src/transport/proxied.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/tor-chanmgr/src/err.rs b/crates/tor-chanmgr/src/err.rs index 9e8fe9d52..8ed339848 100644 --- a/crates/tor-chanmgr/src/err.rs +++ b/crates/tor-chanmgr/src/err.rs @@ -110,7 +110,7 @@ pub enum Error { #[error("Channel request cancelled or superseded")] RequestCancelled, - /// We tried to create a channel with + /// We tried to create a channel through a proxy, and encountered an error. #[error("Problem while connecting to Tor via a proxy")] Proxy(#[from] ProxyError), diff --git a/crates/tor-chanmgr/src/transport/proxied.rs b/crates/tor-chanmgr/src/transport/proxied.rs index 86921b95e..4aa3100a7 100644 --- a/crates/tor-chanmgr/src/transport/proxied.rs +++ b/crates/tor-chanmgr/src/transport/proxied.rs @@ -69,8 +69,10 @@ pub(crate) async fn connect_via_proxy( protocol: &Protocol, target: &PtTargetAddr, ) -> Result { - // a different error type would be better TODO pt-client - let mut stream = runtime.connect(proxy).await?; + let mut stream = runtime + .connect(proxy) + .await + .map_err(|e| ProxyError::ProxyConnect(Arc::new(e)))?; let Protocol::Socks(version, auth) = protocol; @@ -161,7 +163,11 @@ pub(crate) async fn connect_via_proxy( #[derive(Clone, Debug, thiserror::Error)] #[non_exhaustive] pub enum ProxyError { - /// We had an IO error while talking to the proxy + /// We had an IO error while trying to open a connection to the proxy. + #[error("Problem while connecting to proxy")] + ProxyConnect(#[source] Arc), + + /// We had an IO error while talking to the proxy. #[error("Problem while communicating with proxy")] ProxyIo(#[source] Arc), @@ -214,7 +220,7 @@ impl tor_error::HasKind for ProxyError { use tor_error::ErrorKind as EK; use ProxyError as E; match self { - E::ProxyIo(_) => EK::LocalNetworkError, + E::ProxyConnect(_) | E::ProxyIo(_) => EK::LocalNetworkError, E::InvalidSocksAddr(_) | E::InvalidSocksRequest(_) => EK::BadApiUsage, E::UnrecognizedAddr => EK::NotImplemented, E::SocksProto(_) => EK::LocalProtocolViolation, @@ -231,7 +237,7 @@ impl tor_error::HasRetryTime for ProxyError { use ProxyError as E; use SocksStatus as S; match self { - E::ProxyIo(_) => RT::AfterWaiting, + E::ProxyConnect(_) | E::ProxyIo(_) => RT::AfterWaiting, E::InvalidSocksAddr(_) => RT::Never, E::UnrecognizedAddr => RT::Never, E::InvalidSocksRequest(_) => RT::Never,