Skip to main content

tor_basic_utils/
onionperf_types.rs

1//! Types representing events that are emitted to enable onionperf.
2//!
3//! These are intended to reflect the C Tor meanings of the similar events,
4//! see [asynchronous events spec] for more details, as well as arti#173.
5//!
6//! [asynchronous events spec]: https://spec.torproject.org/control-spec/replies.html#asynchronous-events
7
8// It would be nice to include various IDs in these enums,
9// but doing so would create a circular dependency,
10// as the crates that define those types depend on tor-basic-utils.
11#[derive(Debug)]
12#[non_exhaustive]
13/// An event that is intended to be ingested by onionperf.
14pub enum OnionperfEvent {
15    /// A stream-related event (`STREAM` in C Tor)
16    ///
17    /// Note that this somewhat conflates SOCKS proxy streams and data streams,
18    /// as C Tor does the same.
19    ///
20    /// These can be distinguished, as the data streams have a stream ID set in
21    /// the emitted events, while the SOCKS streams do not.
22    Stream(OnionperfStreamStatus),
23    /// A circuit-related event (`CIRC` in C Tor).
24    Circuit(OnionperfCircuitStatus),
25    /// A guard-related event (`GUARD` in C Tor).
26    Guard(OnionperfGuardStatus),
27}
28
29#[derive(Debug)]
30#[non_exhaustive]
31/// A stream status that is intended to be ingested by onionperf.
32pub enum OnionperfStreamStatus {
33    /// A stream was newly created (`NEW` in C Tor).
34    New,
35    /// A stream was closed (`CLOSED` in C Tor).
36    Closed,
37    /// A stream has failed and been closed due to an error (`FAILED` in C Tor).
38    Failed,
39}
40
41#[derive(Debug)]
42#[non_exhaustive]
43/// A circuit status that is intended to be ingested by onionperf.
44pub enum OnionperfCircuitStatus {
45    /// A new circuit was built (`BUILT` in C Tor).
46    Built,
47    /// This tunnel is now usable (`LAUNCHED` in C Tor).
48    Launched,
49    /// This circuit was successfully extended by another hop (`EXTENDED` in C Tor).
50    Extended,
51    /// This circuit was closed, either cleanly or due to an error (`CLOSED` in C Tor).
52    Closed,
53    /// This tunnel was not successfully created (`FAILED` in C Tor).
54    Failed,
55}
56
57#[derive(Debug)]
58#[non_exhaustive]
59/// A guard status that is intended to be ingested by onionperf.
60pub enum OnionperfGuardStatus {
61    /// A new guard has been added to the set of available guards (`NEW` in C Tor).
62    New,
63    /// This guard has been used successfully (`UP` in C Tor).
64    Up,
65    /// We attempted to use this guard but were not successful (`DOWN` in  C Tor).
66    Down,
67    /// This guard was removed from the set of available guards (`DROPPED` in C Tor).
68    Dropped,
69}