From 936439858bf70efb509cc228a970cdb383d1a569 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 31 Mar 2022 15:38:48 -0400 Subject: [PATCH] chanmgr: implement HasRetryTime. --- crates/tor-chanmgr/src/err.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/tor-chanmgr/src/err.rs b/crates/tor-chanmgr/src/err.rs index c7ea6789e..3776700ac 100644 --- a/crates/tor-chanmgr/src/err.rs +++ b/crates/tor-chanmgr/src/err.rs @@ -92,6 +92,37 @@ impl tor_error::HasKind for Error { } } +impl tor_error::HasRetryTime for Error { + fn retry_time(&self) -> tor_error::RetryTime { + use tor_error::RetryTime as RT; + use Error as E; + match self { + // We can retry this action immediately; there was already a time delay. + E::ChanTimeout => RT::Immediate, + + // These are worth retrying in a little while. + // + // TODO: Someday we might want to distinguish among different kinds of IO + // errors. + E::PendingFailed | E::Proto(_) | E::Io { .. } => RT::AfterWaiting, + + // This error reflects multiple attempts, but every failure is an IO + // error, so we can also retry this after a delay. + // + // TODO: Someday we might want to distinguish among different kinds + // of IO errors. + E::ChannelBuild { .. } => RT::AfterWaiting, + + // This one can't succeed: if the ChanTarget have addresses to begin with, + // it won't have addresses in the future. + E::UnusableTarget(_) => RT::Never, + + // These aren't recoverable at all. + E::Spawn { .. } | E::Internal(_) => RT::Never, + } + } +} + impl Error { /// Construct a new `Error` from a `SpawnError`. pub(crate) fn from_spawn(spawning: &'static str, err: SpawnError) -> Error {