1
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
2
#![doc = include_str!("../README.md")]
3
// @@ begin lint list maintained by maint/add_warning @@
4
#![cfg_attr(not(ci_arti_stable), allow(renamed_and_removed_lints))]
5
#![cfg_attr(not(ci_arti_nightly), allow(unknown_lints))]
6
#![warn(missing_docs)]
7
#![warn(noop_method_call)]
8
#![warn(unreachable_pub)]
9
#![warn(clippy::all)]
10
#![deny(clippy::await_holding_lock)]
11
#![deny(clippy::cargo_common_metadata)]
12
#![deny(clippy::cast_lossless)]
13
#![deny(clippy::checked_conversions)]
14
#![warn(clippy::cognitive_complexity)]
15
#![deny(clippy::debug_assert_with_mut_call)]
16
#![deny(clippy::exhaustive_enums)]
17
#![deny(clippy::exhaustive_structs)]
18
#![deny(clippy::expl_impl_clone_on_copy)]
19
#![deny(clippy::fallible_impl_from)]
20
#![deny(clippy::implicit_clone)]
21
#![deny(clippy::large_stack_arrays)]
22
#![warn(clippy::manual_ok_or)]
23
#![deny(clippy::missing_docs_in_private_items)]
24
#![warn(clippy::needless_borrow)]
25
#![warn(clippy::needless_pass_by_value)]
26
#![warn(clippy::option_option)]
27
#![deny(clippy::print_stderr)]
28
#![deny(clippy::print_stdout)]
29
#![warn(clippy::rc_buffer)]
30
#![deny(clippy::ref_option_ref)]
31
#![warn(clippy::semicolon_if_nothing_returned)]
32
#![warn(clippy::trait_duplication_in_bounds)]
33
#![deny(clippy::unnecessary_wraps)]
34
#![warn(clippy::unseparated_literal_suffix)]
35
#![deny(clippy::unwrap_used)]
36
#![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness
37
#![allow(clippy::uninlined_format_args)]
38
#![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945
39
#![allow(clippy::result_large_err)] // temporary workaround for arti#587
40
#![allow(clippy::needless_raw_string_hashes)] // complained-about code is fine, often best
41
//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
42

            
43
// TODO probably remove this at some point - see tpo/core/arti#1060
44
#![cfg_attr(
45
    not(all(feature = "full", feature = "experimental")),
46
    allow(unused_imports)
47
)]
48

            
49
pub mod channel;
50
pub mod circuit;
51
mod crypto;
52
pub mod stream;
53
mod util;
54

            
55
pub use util::err::{Error, ResolveError};
56
pub use util::skew::ClockSkew;
57

            
58
pub use channel::params::ChannelPaddingInstructions;
59
pub use crypto::cell::{HopNum, HopNumDisplay};
60

            
61
/// A Result type for this crate.
62
pub type Result<T> = std::result::Result<T, Error>;
63

            
64
/// Timestamp object that we update whenever we get incoming traffic.
65
///
66
/// Used to implement [`time_since_last_incoming_traffic`]
67
static LAST_INCOMING_TRAFFIC: util::ts::OptTimestamp = util::ts::OptTimestamp::new();
68

            
69
/// Called whenever we receive incoming traffic.
70
///
71
/// Used to implement [`time_since_last_incoming_traffic`]
72
#[inline]
73
301
pub(crate) fn note_incoming_traffic() {
74
301
    LAST_INCOMING_TRAFFIC.update();
75
301
}
76

            
77
/// Return the amount of time since we last received "incoming traffic".
78
///
79
/// This is a global counter, and is subject to interference from
80
/// other users of the `tor_proto`.  Its only permissible use is for
81
/// checking how recently we have been definitely able to receive
82
/// incoming traffic.
83
///
84
/// When enabled, this timestamp is updated whenever we receive a valid
85
/// cell, and whenever we complete a channel handshake.
86
///
87
/// Returns `None` if we never received "incoming traffic".
88
105
pub fn time_since_last_incoming_traffic() -> Option<std::time::Duration> {
89
105
    LAST_INCOMING_TRAFFIC.time_since_update().map(Into::into)
90
105
}