1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3#![allow(renamed_and_removed_lints)] #![allow(unknown_lints)] #![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::unchecked_time_subtraction)]
34#![deny(clippy::unnecessary_wraps)]
35#![warn(clippy::unseparated_literal_suffix)]
36#![deny(clippy::unwrap_used)]
37#![deny(clippy::mod_module_files)]
38#![allow(clippy::let_unit_value)] #![allow(clippy::uninlined_format_args)]
40#![allow(clippy::significant_drop_in_scrutinee)] #![allow(clippy::result_large_err)] #![allow(clippy::needless_raw_string_hashes)] #![allow(clippy::needless_lifetimes)] #![allow(mismatched_lifetime_syntaxes)] #![allow(clippy::collapsible_if)] #![deny(clippy::unused_async)]
47#![deny(clippy::string_slice)] #![allow(clippy::cognitive_complexity)]
53#![cfg_attr(
55 not(all(feature = "full", feature = "experimental")),
56 allow(unused, unreachable_pub)
57)]
58
59#[cfg(feature = "bench")]
60pub mod bench_utils;
61pub mod channel;
62pub mod circuit;
63pub mod client;
64pub(crate) mod conflux;
65mod congestion;
66mod crypto;
67pub mod memquota;
68pub mod peer;
69pub mod stream;
70pub(crate) mod streammap;
71pub(crate) mod tunnel;
72mod util;
73
74#[cfg(feature = "relay")]
75pub mod relay;
76#[cfg(feature = "relay")]
77pub use relay::channel::{RelayChannelAuthMaterial, RelayChannelBuilder};
78
79pub use util::err::{Error, ResolveError};
80pub use util::skew::ClockSkew;
81
82pub use channel::params::ChannelPaddingInstructions;
83pub use client::{ClientTunnel, HopLocation, TargetHop, channel::ClientChannelBuilder};
84pub use congestion::params as ccparams;
85pub use crypto::cell::{HopNum, HopNumDisplay};
86pub use stream::flow_ctrl::params::{CellCount, FlowCtrlParameters};
87#[cfg(feature = "send-control-msg")]
88pub use {
89 crate::client::Conversation,
90 crate::client::msghandler::{MsgHandler, UserMsgHandler},
91 crate::client::reactor::MetaCellDisposition,
92};
93
94pub type Result<T> = std::result::Result<T, Error>;
96
97use std::fmt::Debug;
98use tor_memquota::{
99 HasMemoryCost,
100 mq_queue::{self, ChannelSpec as _},
101};
102use tor_rtcompat::DynTimeProvider;
103
104#[doc(hidden)]
105pub use {derive_deftly, tor_memquota};
106
107static LAST_INCOMING_TRAFFIC: util::ts::AtomicOptTimestamp = util::ts::AtomicOptTimestamp::new();
111
112#[inline]
116pub(crate) fn note_incoming_traffic() {
117 LAST_INCOMING_TRAFFIC.update();
118}
119
120pub fn time_since_last_incoming_traffic() -> Option<std::time::Duration> {
132 LAST_INCOMING_TRAFFIC.time_since_update().map(Into::into)
133}
134
135#[cfg(any(test, feature = "testing"))] pub(crate) fn fake_mpsc<T: HasMemoryCost + Debug + Send>(
138 buffer: usize,
139) -> (
140 mq_queue::Sender<T, mq_queue::MpscSpec>,
141 mq_queue::Receiver<T, mq_queue::MpscSpec>,
142) {
143 mq_queue::MpscSpec::new(buffer)
144 .new_mq(
145 DynTimeProvider::new(tor_rtmock::MockRuntime::default()),
151 &tor_memquota::Account::new_noop(),
152 )
153 .expect("create fake mpsc")
154}
155
156pub fn supported_client_protocols() -> tor_protover::Protocols {
159 use tor_protover::named::*;
160 let mut protocols = vec![
163 LINK_V4,
164 LINK_V5,
165 LINKAUTH_ED25519_SHA256_EXPORTER,
166 FLOWCTRL_AUTH_SENDME,
167 RELAY_NTOR,
168 RELAY_EXTEND_IPv6,
169 RELAY_NTORV3,
170 RELAY_NEGOTIATE_SUBPROTO,
171 ];
172 #[cfg(feature = "flowctl-cc")]
173 protocols.push(FLOWCTRL_CC);
174 #[cfg(feature = "counter-galois-onion")]
175 protocols.push(RELAY_CRYPT_CGO);
176
177 protocols.into_iter().collect()
178}
179
180#[cfg(test)]
181mod test {
182 #![allow(clippy::bool_assert_comparison)]
184 #![allow(clippy::clone_on_copy)]
185 #![allow(clippy::dbg_macro)]
186 #![allow(clippy::mixed_attributes_style)]
187 #![allow(clippy::print_stderr)]
188 #![allow(clippy::print_stdout)]
189 #![allow(clippy::single_char_pattern)]
190 #![allow(clippy::unwrap_used)]
191 #![allow(clippy::unchecked_time_subtraction)]
192 #![allow(clippy::useless_vec)]
193 #![allow(clippy::needless_pass_by_value)]
194 #![allow(clippy::string_slice)] use cfg_if::cfg_if;
198
199 use super::*;
200
201 #[test]
202 fn protocols() {
203 let pr = supported_client_protocols();
204 cfg_if! {
205 if #[cfg(all(feature="flowctl-cc", feature="counter-galois-onion"))] {
206 let expected = "FlowCtrl=1-2 Link=4-5 LinkAuth=3 Relay=2-6".parse().unwrap();
207 } else if #[cfg(feature="flowctl-cc")] {
208 let expected = "FlowCtrl=1-2 Link=4-5 LinkAuth=3 Relay=2-5".parse().unwrap();
209 } else {
211 let expected = "FlowCtrl=1 Link=4-5 LinkAuth=3 Relay=2-5".parse().unwrap();
212 }
213 }
214 assert_eq!(pr, expected);
215 }
216}