From ebfd7349565f0f354906a78ad2ce8f8d2b88bd35 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 4 Mar 2022 11:42:49 +0000 Subject: [PATCH] Move skip_fmt into tor-basic-utils Code motion and the minimal mechanical changes. As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/375#note_2783078 --- Cargo.lock | 13 +++++----- crates/arti-client/Cargo.toml | 2 +- crates/arti-client/src/status.rs | 2 +- crates/tor-basic-utils/src/lib.rs | 37 +++++++++++++++++++++++++++++ crates/tor-bytes/Cargo.toml | 1 - crates/tor-bytes/src/lib.rs | 35 --------------------------- crates/tor-cell/Cargo.toml | 1 + crates/tor-cell/src/chancell/msg.rs | 3 ++- crates/tor-chanmgr/Cargo.toml | 2 +- crates/tor-chanmgr/src/event.rs | 2 +- crates/tor-circmgr/Cargo.toml | 2 +- crates/tor-circmgr/src/impls.rs | 2 +- crates/tor-dirmgr/Cargo.toml | 2 +- crates/tor-dirmgr/src/event.rs | 2 +- crates/tor-guardmgr/Cargo.toml | 2 +- crates/tor-guardmgr/src/pending.rs | 2 +- crates/tor-proto/Cargo.toml | 1 + crates/tor-proto/src/stream/data.rs | 2 +- 18 files changed, 59 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b85af863..682cb68ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ dependencies = [ "thiserror", "tokio", "tokio-util", - "tor-bytes", + "tor-basic-utils", "tor-chanmgr", "tor-circmgr", "tor-config", @@ -3084,7 +3084,6 @@ dependencies = [ "arrayref", "bytes", "digest 0.10.3", - "educe", "generic-array", "getrandom 0.2.5", "hex-literal", @@ -3107,6 +3106,7 @@ dependencies = [ "hex-literal", "rand 0.8.5", "thiserror", + "tor-basic-utils", "tor-bytes", "tor-cert", "tor-error", @@ -3142,7 +3142,7 @@ dependencies = [ "postage", "rand 0.8.5", "thiserror", - "tor-bytes", + "tor-basic-utils", "tor-error", "tor-linkspec", "tor-llcrypto", @@ -3179,7 +3179,7 @@ dependencies = [ "serde", "static_assertions", "thiserror", - "tor-bytes", + "tor-basic-utils", "tor-chanmgr", "tor-config", "tor-error", @@ -3276,7 +3276,7 @@ dependencies = [ "tempfile", "thiserror", "time", - "tor-bytes", + "tor-basic-utils", "tor-checkable", "tor-circmgr", "tor-config", @@ -3327,7 +3327,7 @@ dependencies = [ "retain_mut", "serde", "thiserror", - "tor-bytes", + "tor-basic-utils", "tor-config", "tor-error", "tor-linkspec", @@ -3470,6 +3470,7 @@ dependencies = [ "thiserror", "tokio", "tokio-util", + "tor-basic-utils", "tor-bytes", "tor-cell", "tor-cert", diff --git a/crates/arti-client/Cargo.toml b/crates/arti-client/Cargo.toml index d846e014f..f304eb5f1 100644 --- a/crates/arti-client/Cargo.toml +++ b/crates/arti-client/Cargo.toml @@ -28,7 +28,7 @@ error_detail = [ ] experimental-api = [] [dependencies] -tor-bytes = { path="../tor-bytes", version = "0.1.0"} +tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"} tor-circmgr = { path="../tor-circmgr", version = "0.1.0"} tor-config = { path="../tor-config", version = "0.1.0"} tor-chanmgr = { path="../tor-chanmgr", version = "0.1.0"} diff --git a/crates/arti-client/src/status.rs b/crates/arti-client/src/status.rs index 57a868705..9a04c6650 100644 --- a/crates/arti-client/src/status.rs +++ b/crates/arti-client/src/status.rs @@ -6,7 +6,7 @@ use std::{borrow::Cow, fmt, time::SystemTime}; use derive_more::Display; use educe::Educe; use futures::{Stream, StreamExt}; -use tor_bytes::skip_fmt; +use tor_basic_utils::skip_fmt; use tor_chanmgr::{ConnBlockage, ConnStatus, ConnStatusEvents}; use tor_dirmgr::{DirBootstrapEvents, DirBootstrapStatus}; use tracing::debug; diff --git a/crates/tor-basic-utils/src/lib.rs b/crates/tor-basic-utils/src/lib.rs index 74c973678..c69f783f9 100644 --- a/crates/tor-basic-utils/src/lib.rs +++ b/crates/tor-basic-utils/src/lib.rs @@ -28,3 +28,40 @@ #![deny(clippy::unnecessary_wraps)] #![warn(clippy::unseparated_literal_suffix)] #![deny(clippy::unwrap_used)] + +use std::fmt; + +// ---------------------------------------------------------------------- + +/// Function with the signature of `Debug::fmt` that just prints `".."` +/// +/// ``` +/// use educe::Educe; +/// use tor_basic_utils::skip_fmt; +/// +/// #[derive(Educe, Default)] +/// #[educe(Debug)] +/// struct Wombat { +/// visible: usize, +/// +/// #[educe(Debug(method = "skip_fmt"))] +/// invisible: [u8; 2], +/// } +/// +/// assert_eq!( format!("{:?}", &Wombat::default()), +/// "Wombat { visible: 0, invisible: .. }" ); +/// ``` +// +// This function is here in tor-bytes because crates that want to use it will largely +// be trying to avoid dumping packet data. +// But, it may at some point want to move to a lower-layer crate. +// If we do that, we should `pub use` it here, if we don't want a semver break. +pub fn skip_fmt(_: &T, f: &mut fmt::Formatter) -> fmt::Result { + /// Inner function avoids code bloat due to generics + fn inner(f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "..") + } + inner(f) +} + +// ---------------------------------------------------------------------- diff --git a/crates/tor-bytes/Cargo.toml b/crates/tor-bytes/Cargo.toml index e381c3322..162bec898 100644 --- a/crates/tor-bytes/Cargo.toml +++ b/crates/tor-bytes/Cargo.toml @@ -23,7 +23,6 @@ thiserror = "1" [dev-dependencies] hex-literal = "0.3" -educe = "0.4.6" [target.wasm32-unknown-unknown.dependencies] getrandom = { version = "0.2.3", features = ["js"] } diff --git a/crates/tor-bytes/src/lib.rs b/crates/tor-bytes/src/lib.rs index e8d5876d3..79cfd7e73 100644 --- a/crates/tor-bytes/src/lib.rs +++ b/crates/tor-bytes/src/lib.rs @@ -82,8 +82,6 @@ mod impls; mod reader; mod writer; -use std::fmt; - pub use err::Error; pub use reader::Reader; pub use writer::Writer; @@ -196,39 +194,6 @@ pub trait Readable: Sized { // ---------------------------------------------------------------------- -/// Function with the signature of `Debug::fmt` that just prints `".."` -/// -/// ``` -/// use educe::Educe; -/// use tor_bytes::skip_fmt; -/// -/// #[derive(Educe, Default)] -/// #[educe(Debug)] -/// struct Wombat { -/// visible: usize, -/// -/// #[educe(Debug(method = "skip_fmt"))] -/// invisible: [u8; 2], -/// } -/// -/// assert_eq!( format!("{:?}", &Wombat::default()), -/// "Wombat { visible: 0, invisible: .. }" ); -/// ``` -// -// This function is here in tor-bytes because crates that want to use it will largely -// be trying to avoid dumping packet data. -// But, it may at some point want to move to a lower-layer crate. -// If we do that, we should `pub use` it here, if we don't want a semver break. -pub fn skip_fmt(_: &T, f: &mut fmt::Formatter) -> fmt::Result { - /// Inner function avoids code bloat due to generics - fn inner(f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "..") - } - inner(f) -} - -// ---------------------------------------------------------------------- - #[cfg(test)] mod test { use super::*; diff --git a/crates/tor-cell/Cargo.toml b/crates/tor-cell/Cargo.toml index 70d0c360e..9e50078d0 100644 --- a/crates/tor-cell/Cargo.toml +++ b/crates/tor-cell/Cargo.toml @@ -13,6 +13,7 @@ repository="https://gitlab.torproject.org/tpo/core/arti.git/" [dependencies] caret = { path="../caret", version = "0.1.0"} educe = "0.4.6" +tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"} tor-llcrypto = { path="../tor-llcrypto", version = "0.1.0"} tor-bytes = { path="../tor-bytes", version = "0.1.0"} tor-cert = { path="../tor-cert", version = "0.1.0"} diff --git a/crates/tor-cell/src/chancell/msg.rs b/crates/tor-cell/src/chancell/msg.rs index 56fbcbe26..8c03a1255 100644 --- a/crates/tor-cell/src/chancell/msg.rs +++ b/crates/tor-cell/src/chancell/msg.rs @@ -3,7 +3,8 @@ use super::{ChanCmd, RawCellBody, CELL_DATA_LEN}; use std::convert::TryInto; use std::net::{IpAddr, Ipv4Addr}; -use tor_bytes::{self, skip_fmt, Error, Readable, Reader, Result, Writer}; +use tor_basic_utils::skip_fmt; +use tor_bytes::{self, Error, Readable, Reader, Result, Writer}; use caret::caret_int; use educe::Educe; diff --git a/crates/tor-chanmgr/Cargo.toml b/crates/tor-chanmgr/Cargo.toml index fc5d5ea94..0fe048668 100644 --- a/crates/tor-chanmgr/Cargo.toml +++ b/crates/tor-chanmgr/Cargo.toml @@ -13,7 +13,7 @@ repository="https://gitlab.torproject.org/tpo/core/arti.git/" [features] [dependencies] -tor-bytes = { path="../tor-bytes", version = "0.1.0"} +tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"} tor-error = { path="../tor-error", version = "0.1.0"} tor-rtcompat = { path="../tor-rtcompat", version = "0.1.0"} tor-proto = { path="../tor-proto", version = "0.1.0"} diff --git a/crates/tor-chanmgr/src/event.rs b/crates/tor-chanmgr/src/event.rs index 3340658e6..9a2a21e25 100644 --- a/crates/tor-chanmgr/src/event.rs +++ b/crates/tor-chanmgr/src/event.rs @@ -8,7 +8,7 @@ use std::{ fmt, time::{Duration, Instant}, }; -use tor_bytes::skip_fmt; +use tor_basic_utils::skip_fmt; /// The status of our connection to the internet. #[derive(Default, Debug, Clone)] diff --git a/crates/tor-circmgr/Cargo.toml b/crates/tor-circmgr/Cargo.toml index 9db4e2b66..660fd2ea8 100644 --- a/crates/tor-circmgr/Cargo.toml +++ b/crates/tor-circmgr/Cargo.toml @@ -18,7 +18,7 @@ repository="https://gitlab.torproject.org/tpo/core/arti.git/" experimental-api = [] [dependencies] -tor-bytes = { path = "../tor-bytes", version = "0.1.0"} +tor-basic-utils = { path = "../tor-basic-utils", version = "0.1.0"} tor-chanmgr = { path="../tor-chanmgr", version = "0.1.0"} tor-config = { path="../tor-config", version = "0.1.0"} tor-error = { path="../tor-error", version = "0.1.0"} diff --git a/crates/tor-circmgr/src/impls.rs b/crates/tor-circmgr/src/impls.rs index 189b305bd..1107f5927 100644 --- a/crates/tor-circmgr/src/impls.rs +++ b/crates/tor-circmgr/src/impls.rs @@ -9,7 +9,7 @@ use educe::Educe; use futures::future::OptionFuture; use std::convert::TryInto; use std::sync::Arc; -use tor_bytes::skip_fmt; +use tor_basic_utils::skip_fmt; use tor_error::internal; use tor_proto::circuit::{CircParameters, ClientCirc}; use tor_rtcompat::Runtime; diff --git a/crates/tor-dirmgr/Cargo.toml b/crates/tor-dirmgr/Cargo.toml index 4814df54c..70323b0fb 100644 --- a/crates/tor-dirmgr/Cargo.toml +++ b/crates/tor-dirmgr/Cargo.toml @@ -18,8 +18,8 @@ static = ["rusqlite/bundled"] routerdesc = ["tor-dirclient/routerdesc"] [dependencies] +tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"} retry-error = { path = "../retry-error", version = "0.1.0"} -tor-bytes = { path="../tor-bytes", version = "0.1.0"} tor-checkable = { path = "../tor-checkable", version = "0.1.0"} tor-circmgr = { path = "../tor-circmgr", version = "0.1.0"} tor-config = { path = "../tor-config", version = "0.1.0"} diff --git a/crates/tor-dirmgr/src/event.rs b/crates/tor-dirmgr/src/event.rs index eb97a0436..3a28445a8 100644 --- a/crates/tor-dirmgr/src/event.rs +++ b/crates/tor-dirmgr/src/event.rs @@ -19,7 +19,7 @@ use std::{ use educe::Educe; use futures::{stream::Stream, Future, StreamExt}; use time::OffsetDateTime; -use tor_bytes::skip_fmt; +use tor_basic_utils::skip_fmt; use tor_netdoc::doc::netstatus; /// An event that a DirMgr can broadcast to indicate that a change in diff --git a/crates/tor-guardmgr/Cargo.toml b/crates/tor-guardmgr/Cargo.toml index 140cc7e11..ea1b4c345 100644 --- a/crates/tor-guardmgr/Cargo.toml +++ b/crates/tor-guardmgr/Cargo.toml @@ -18,7 +18,7 @@ default = [] testing = [] [dependencies] -tor-bytes = { path="../tor-bytes", version = "0.1.0"} +tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"} tor-config = { path="../tor-config", version = "0.1.0"} tor-error = { path="../tor-error", version = "0.1.0"} tor-netdir = { path="../tor-netdir", version = "0.1.0"} diff --git a/crates/tor-guardmgr/src/pending.rs b/crates/tor-guardmgr/src/pending.rs index 31690526f..fff7e2cce 100644 --- a/crates/tor-guardmgr/src/pending.rs +++ b/crates/tor-guardmgr/src/pending.rs @@ -21,7 +21,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::task::{Context, Poll}; use std::time::Instant; -use tor_bytes::skip_fmt; +use tor_basic_utils::skip_fmt; /// A future used to see if we have "permission" to use a guard. /// diff --git a/crates/tor-proto/Cargo.toml b/crates/tor-proto/Cargo.toml index 86e8e94e8..dabf7ff9f 100644 --- a/crates/tor-proto/Cargo.toml +++ b/crates/tor-proto/Cargo.toml @@ -17,6 +17,7 @@ ntor_v3 = [] tokio = ["tokio-crate", "tokio-util"] [dependencies] +tor-basic-utils = { path = "../tor-basic-utils", version = "0.1.0"} tor-llcrypto = { path = "../tor-llcrypto", version = "0.1.0"} tor-bytes = { path = "../tor-bytes", version = "0.1.0"} tor-cert = { path = "../tor-cert", version = "0.1.0"} diff --git a/crates/tor-proto/src/stream/data.rs b/crates/tor-proto/src/stream/data.rs index 24e1e7948..7fe231a0f 100644 --- a/crates/tor-proto/src/stream/data.rs +++ b/crates/tor-proto/src/stream/data.rs @@ -23,7 +23,7 @@ use educe::Educe; use crate::circuit::StreamTarget; use crate::stream::StreamReader; -use tor_bytes::skip_fmt; +use tor_basic_utils::skip_fmt; use tor_cell::relaycell::msg::{Data, RelayMsg}; use tor_error::internal;