ptmgr: Fill in some error-related code; resolve TODOs.

This commit is contained in:
Nick Mathewson 2022-11-28 14:11:06 -05:00
parent 1fa9296f9c
commit 4b5be3685f
3 changed files with 55 additions and 8 deletions

View File

@ -341,6 +341,11 @@ pub enum ErrorKind {
#[display(fmt = "local authentication refused.")]
LocalProtocolFailed,
/// A problem occurred when launching or communicating with an external
/// process running on this computer.
#[display(fmt = "local plug-in tool failed")]
LocalPluginFailed,
/// A relay had an identity other than the one we expected.
///
/// This could indicate a MITM attack, but more likely indicates that the

View File

@ -78,21 +78,55 @@ pub enum PtError {
error: CfgPathError,
},
/// The pluggable transport reactor failed.
#[error("PT reactor failed")]
// TODO pt-client: This should just be a bug.
ReactorFailed,
#[error("Internal error")]
Internal(#[from] tor_error::Bug),
}
// TODO pt-client: implement.
impl HasKind for PtError {
fn kind(&self) -> ErrorKind {
todo!()
use ErrorKind as EK;
use PtError as E;
match self {
E::ClientTransportsUnsupported(_) => EK::InvalidConfig,
E::ChildProtocolViolation(_)
| E::ProtocolViolation(_)
| E::UnsupportedVersion
| E::IpcParseFailed { .. } => EK::LocalProtocolViolation,
E::Timeout
| E::ClientTransportFailed { .. }
| E::ChildGone
| E::ChildReadFailed(_)
| E::ChildSpawnFailed { .. }
| E::StdioUnavailable
| E::ProxyError(_) => EK::LocalPluginFailed,
E::TempdirCreateFailed(_) => EK::FsPermissions,
E::PathExpansionFailed { .. } => EK::InvalidConfig,
E::Internal(e) => e.kind(),
}
}
}
impl HasRetryTime for PtError {
fn retry_time(&self) -> RetryTime {
todo!()
use PtError as E;
use RetryTime as RT;
match self {
E::ClientTransportsUnsupported(_)
| E::ClientTransportFailed { .. }
| E::ChildProtocolViolation(_)
| E::ProtocolViolation(_)
| E::ChildSpawnFailed { .. }
| E::IpcParseFailed { .. }
| E::UnsupportedVersion
| E::Internal(_)
| E::PathExpansionFailed { .. } => RT::Never,
E::TempdirCreateFailed(_)
| E::StdioUnavailable
| E::Timeout
| E::ProxyError(_)
| E::ChildGone
| E::ChildReadFailed(_) => RT::AfterWaiting,
}
}
}

View File

@ -250,11 +250,19 @@ impl<R: Runtime> tor_chanmgr::factory::AbstractPtMgr for PtMgr<R> {
pt: transport.clone(),
result: tx,
})
.map_err(|_| Arc::new(PtError::ReactorFailed) as Arc<dyn AbstractPtError>)?;
.map_err(|_| {
Arc::new(PtError::Internal(tor_error::internal!(
"PT reactor closed unexpectedly"
))) as Arc<dyn AbstractPtError>
})?;
cmethod = Some(
// NOTE(eta): Could be improved with result flattening.
rx.await
.map_err(|_| Arc::new(PtError::ReactorFailed) as Arc<dyn AbstractPtError>)?
.map_err(|_| {
Arc::new(PtError::Internal(tor_error::internal!(
"PT reactor closed unexpectedly"
))) as Arc<dyn AbstractPtError>
})?
.map_err(|x| Arc::new(x) as Arc<dyn AbstractPtError>)?,
);
} else {