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)] #![cfg_attr(not(all(feature = "full", feature = "experimental")), allow(unused))]
49
50mod address;
51mod builder;
52mod client;
53mod protostatus;
54mod release_date;
55#[cfg(feature = "rpc")]
56pub mod rpc;
57mod util;
58
59pub mod config;
60pub mod status;
61
62pub use address::{DangerouslyIntoTorAddr, IntoTorAddr, TorAddr, TorAddrError};
63pub use builder::{MAX_LOCAL_RESOURCE_TIMEOUT, TorClientBuilder};
64pub use client::{BootstrapBehavior, DormantMode, InertTorClient, StreamPrefs, TorClient};
65pub use config::TorClientConfig;
66
67pub use tor_circmgr::IsolationToken;
68pub use tor_circmgr::isolation;
69pub use tor_error::{ErrorKind, HasKind};
70pub use tor_proto::client::stream::{DataReader, DataStream, DataWriter};
71
72mod err;
73pub use err::{Error, ErrorHint, HintableError};
74
75#[cfg(feature = "error_detail")]
76pub use err::ErrorDetail;
77
78pub type Result<T> = std::result::Result<T, Error>;
80
81#[cfg(feature = "experimental-api")]
82pub use builder::DirProviderBuilder;
83
84#[cfg(all(feature = "onion-service-client", feature = "experimental-api"))]
85pub use {
86 tor_hscrypto::pk::{HsClientDescEncKey, HsId},
87 tor_keymgr::KeystoreSelector,
88};
89
90#[cfg(feature = "geoip")]
91pub use tor_geoip::CountryCode;
92
93pub(crate) fn supported_protocols() -> tor_protover::Protocols {
100 let protocols = tor_proto::supported_client_protocols()
101 .union(&tor_netdoc::supported_protocols())
102 .union(&tor_dirmgr::supported_client_protocols());
103
104 #[cfg(feature = "onion-service-service")]
112 let protocols = protocols.union(&tor_hsservice::supported_hsservice_protocols());
113 #[cfg(feature = "onion-service-client")]
114 let protocols = protocols.union(&tor_hsclient::supported_hsclient_protocols());
115
116 let hs_protocols = {
117 use tor_protover::named::*;
120 [
121 HSINTRO_V3,
123 HSINTRO_RATELIM,
124 HSREND_V3,
125 HSDIR_V3,
126 ]
127 .into_iter()
128 .collect()
129 };
130
131 protocols.union(&hs_protocols)
132}
133
134pub(crate) fn software_release_date() -> std::time::SystemTime {
138 use time::OffsetDateTime;
139
140 let format = time::macros::format_description!("[year]-[month]-[day]");
141 let date = time::Date::parse(release_date::ARTI_CLIENT_RELEASE_DATE, &format)
142 .expect("Invalid hard-coded release date!?");
143 OffsetDateTime::new_utc(date, time::Time::MIDNIGHT).into()
144}
145
146#[cfg(test)]
147mod test {
148 #![allow(clippy::bool_assert_comparison)]
150 #![allow(clippy::clone_on_copy)]
151 #![allow(clippy::dbg_macro)]
152 #![allow(clippy::mixed_attributes_style)]
153 #![allow(clippy::print_stderr)]
154 #![allow(clippy::print_stdout)]
155 #![allow(clippy::single_char_pattern)]
156 #![allow(clippy::unwrap_used)]
157 #![allow(clippy::unchecked_time_subtraction)]
158 #![allow(clippy::useless_vec)]
159 #![allow(clippy::needless_pass_by_value)]
160 use cfg_if::cfg_if;
163
164 use super::*;
165
166 #[test]
167 fn protocols_enforced() {
168 let pr = supported_protocols();
169
170 for recommendation in [
171 "Cons=2 Desc=2 Link=4 Microdesc=2 Relay=2",
173 "Cons=2 Desc=2 DirCache=2 HSDir=2 HSIntro=4 HSRend=2 Link=4-5 Microdesc=2 Relay=2",
175 "Cons=2 Desc=2 FlowCtrl=1 Link=4 Microdesc=2 Relay=2",
177 ] {
181 let rec: tor_protover::Protocols = recommendation.parse().unwrap();
182
183 let unsupported = rec.difference(&pr);
184
185 assert!(unsupported.is_empty(), "{} not supported", unsupported);
186 }
187
188 {
190 let rec: tor_protover::Protocols =
192 "Cons=2 Desc=2 DirCache=2 FlowCtrl=1-2 HSDir=2 HSIntro=4 \
193 HSRend=2 Link=4-5 Microdesc=2 Relay=2-4"
194 .parse()
195 .unwrap();
196
197 cfg_if! {
199 if #[cfg(feature="flowctl-cc")] {
200 let permitted_missing: tor_protover::Protocols =
201 [].into_iter().collect();
202 } else {
203 let permitted_missing: tor_protover::Protocols =
204 [tor_protover::named::FLOWCTRL_CC].into_iter().collect();
205 }
206 }
207 let unsupported = rec.difference(&pr);
208 assert!(unsupported.difference(&permitted_missing).is_empty());
209 }
210 }
211
212 #[test]
213 fn release_date_format() {
214 let _d: std::time::SystemTime = software_release_date();
216 }
217}