1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
//! Declare an error type for tor-circmgr
use retry_error::RetryError;
use thiserror::Error;
/// An error returned while looking up or building a circuit
#[derive(Error, Debug, Clone)]
#[non_exhaustive]
pub enum Error {
/// No suitable relays for a request
#[error("no relays for circuit: {0}")]
NoRelays(String),
/// We need to have a consensus directory to build this kind of
/// circuits, and we only got a list of fallbacks.
#[error("Consensus directory needed")]
NeedConsensus,
/// We were waiting on a pending circuit, but it didn't succeed.
#[error("Pending circuit(s) failed to launch")]
PendingFailed,
/// A circuit build took too long to finish.
#[error("Circuit took too long to build")]
CircTimeout,
/// We started building a circuit on a guard, but later decided not
/// to use that guard.
#[error("Discarded circuit because of speculative guard selection")]
GuardNotUsable,
/// Tried to take a circuit for a purpose it doesn't support.
#[error("Circuit usage not supported: {0}")]
UsageNotSupported(String),
/// A request spent too long waiting for a circuit
#[error("Spent too long waiting for a circuit to build")]
RequestTimeout,
/// Unable to get or build a circuit, despite retrying.
#[error("{0}")]
RequestFailed(RetryError<Box<Error>>),
/// An error caused by a programming issue or a failure in another
/// library that we can't work around.
#[error("Internal error: {0}")]
Internal(String),
/// Couldn't get a channel for a circuit.
#[error("Couldn't get channel for circuit: {0}")]
ChanFailed(#[from] tor_chanmgr::Error),
/// Protocol issue while building a circuit.
#[error("Problem building a circuit: {0}")]
Protocol(#[from] tor_proto::Error),
/// Problem loading or storing persistent state.
#[error("Problem loading or storing state: {0}")]
State(#[from] tor_persist::Error),
/// Problem creating or updating a guard manager.
#[error("Problem creating or updating guards list: {0}")]
GuardMgr(#[source] tor_guardmgr::GuardMgrError),
/// Problem selecting a guard relay.
#[error("Unable to select a guard relay: {0}")]
Guard(#[from] tor_guardmgr::PickGuardError),
}
impl From<futures::channel::oneshot::Canceled> for Error {
fn from(_: futures::channel::oneshot::Canceled) -> Error {
Error::PendingFailed
}
}
impl From<futures::task::SpawnError> for Error {
fn from(_: futures::task::SpawnError) -> Error {
Error::Internal("Unable to spawn new task in executor.".into())
}
}
impl From<tor_rtcompat::TimeoutError> for Error {
fn from(_: tor_rtcompat::TimeoutError) -> Error {
Error::CircTimeout
}
}
impl From<tor_guardmgr::GuardMgrError> for Error {
fn from(err: tor_guardmgr::GuardMgrError) -> Error {
match err {
tor_guardmgr::GuardMgrError::State(e) => Error::State(e),
_ => Error::GuardMgr(err),
}
}
}
|