From 9612e48ca70ff5d8c9dc5164a70f5d9ead9f83d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Feb 2023 15:08:10 +0000 Subject: [PATCH 1/3] deps: update libp2p requirement from 0.50 to 0.51 Updates the requirements on [libp2p](https://github.com/libp2p/rust-libp2p) to permit the latest version. - [Release notes](https://github.com/libp2p/rust-libp2p/releases) - [Changelog](https://github.com/libp2p/rust-libp2p/blob/master/CHANGELOG.md) - [Commits](https://github.com/libp2p/rust-libp2p/compare/v0.50.0...v0.51.0) --- updated-dependencies: - dependency-name: libp2p dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3927a32..1d8b2f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ tokio-crate = { package = "tokio", version = "1", optional = true, default-featu tor-rtcompat = "0.8" [dev-dependencies] -libp2p = { version = "0.50", features = ["mplex", "noise", "ping", "yamux", "macros", "async-std"] } +libp2p = { version = "0.51", features = ["mplex", "noise", "ping", "yamux", "macros", "async-std"] } tokio-crate = { package = "tokio", version = "1", features = ["rt", "macros"] } async-std-crate = { package = "async-std", version = "1", features = ["attributes"] } From ea30be3008280b94394d149d9cae660f4aa877e3 Mon Sep 17 00:00:00 2001 From: umgefahren <55623006+umgefahren@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:08:00 +0200 Subject: [PATCH 2/3] Fixed config and implemented clippy suggestions --- Cargo.toml | 4 ++-- examples/ping-onion.rs | 6 ++++-- src/address.rs | 17 +++++++---------- src/lib.rs | 29 ++++++++++++++++++++++++++--- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d8b2f0..473ddce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-community-tor" -version = "0.2.0-alpha" +version = "0.3.0-alpha" edition = "2021" license = "MIT" resolver = "2" @@ -12,7 +12,7 @@ authors = ["umgefahren "] arti-client = { version = "0.8", default-features = false } async-std-crate = { package = "async-std", version = "1", optional = true, default-features = false } futures = "0.3" -libp2p-core = { version = "0.38" } +libp2p-core = { version = "0.39" } thiserror = "1" tokio-crate = { package = "tokio", version = "1", optional = true, default-features = false } tor-rtcompat = "0.8" diff --git a/examples/ping-onion.rs b/examples/ping-onion.rs index 7961a9f..3ac99b1 100644 --- a/examples/ping-onion.rs +++ b/examples/ping-onion.rs @@ -45,7 +45,7 @@ use async_std_crate as async_std; use futures::prelude::*; -use libp2p::swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent}; +use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}; use libp2p::{core::upgrade, identity, mplex, noise, ping, yamux, Multiaddr, PeerId, Transport}; use libp2p_community_tor::{AddressConversion, AsyncStdRustlsTorTransport}; use std::error::Error; @@ -84,7 +84,9 @@ async fn main() -> Result<(), Box> { let transport = onion_transport(local_key).await?; - let mut swarm = Swarm::with_async_std_executor(transport, Behaviour::default(), local_peer_id); + let mut swarm = + SwarmBuilder::with_async_std_executor(transport, Behaviour::default(), local_peer_id) + .build(); // Dial the peer identified by the multi-address given as the second // command-line argument, if any. diff --git a/src/address.rs b/src/address.rs index 2d7ecf0..aa991e9 100644 --- a/src/address.rs +++ b/src/address.rs @@ -25,8 +25,8 @@ use std::net::SocketAddr; /// "Dangerously" extract a Tor address from the provided [`Multiaddr`]. /// /// See [`DangerouslyIntoTorAddr`] for details around the safety / privacy considerations. -pub fn dangerous_extract_tor_address(multiaddr: &Multiaddr) -> Option { - if let Some(tor_addr) = safe_extract_tor_address(multiaddr) { +pub fn dangerous_extract(multiaddr: &Multiaddr) -> Option { + if let Some(tor_addr) = safe_extract(multiaddr) { return Some(tor_addr); } @@ -42,7 +42,7 @@ pub fn dangerous_extract_tor_address(multiaddr: &Multiaddr) -> Option { /// "Safely" extract a Tor address from the provided [`Multiaddr`]. /// /// See [`IntoTorAddr`] for details around the safety / privacy considerations. -pub fn safe_extract_tor_address(multiaddr: &Multiaddr) -> Option { +pub fn safe_extract(multiaddr: &Multiaddr) -> Option { let mut protocols = multiaddr.into_iter(); let tor_addr = try_to_domain_and_port(&protocols.next()?, &protocols.next()?)? @@ -89,7 +89,7 @@ mod tests { let actual = addresses .iter() - .filter_map(safe_extract_tor_address) + .filter_map(safe_extract) .collect::>(); assert_eq!( @@ -111,7 +111,7 @@ mod tests { let actual = addresses .iter() - .filter_map(dangerous_extract_tor_address) + .filter_map(dangerous_extract) .collect::>(); assert_eq!( @@ -133,7 +133,7 @@ mod tests { let actual = addresses .iter() - .filter_map(dangerous_extract_tor_address) + .filter_map(dangerous_extract) .collect::>(); assert_eq!( @@ -154,10 +154,7 @@ mod tests { "/tcp/10/ip4/1.1.1.1".parse().unwrap(), ]; - let all_correct = addresses - .iter() - .map(safe_extract_tor_address) - .all(|res| res.is_none()); + let all_correct = addresses.iter().map(safe_extract).all(|res| res.is_none()); assert!( all_correct, diff --git a/src/lib.rs b/src/lib.rs index ae33480..8c74202 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,8 @@ // DEALINGS IN THE SOFTWARE. #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![warn(clippy::pedantic)] +#![deny(unsafe_code)] //! Tor based transport for libp2p. Connect through the Tor network to TCP listeners. //! //! # ⚠️ Misuse warning ⚠️ - read carefully before using @@ -67,7 +69,7 @@ //! # async_std::task::block_on(async { test_func().await.unwrap() }); //! ``` -use address::{dangerous_extract_tor_address, safe_extract_tor_address}; +use address::{dangerous_extract, safe_extract}; use arti_client::{TorClient, TorClientBuilder}; use futures::{future::BoxFuture, FutureExt}; use libp2p_core::{transport::TransportError, Multiaddr, Transport}; @@ -115,6 +117,11 @@ pub enum AddressConversion { } impl TorTransport { + /// Builds a `TorTransport` from an Arti `TorClientBuilder`. + /// + /// # Errors + /// + /// Could return errors emitted from Arti. pub fn from_builder( builder: TorBuilder, conversion_mode: AddressConversion, @@ -127,18 +134,34 @@ impl TorTransport { }) } + /// Bootstraps the `TorTransport` into the Tor network. + /// + /// # Errors + /// + /// Could return error emitted during bootstrap by Arti. pub async fn bootstrap(&self) -> Result<(), TorError> { self.client.bootstrap().await } + /// Set the address conversion mode + #[must_use] pub fn with_address_conversion(mut self, conversion_mode: AddressConversion) -> Self { self.conversion_mode = conversion_mode; self } } +#[cfg(all( + any(feature = "native-tls", feature = "rustls"), + any(feature = "async-std", feature = "tokio") +))] macro_rules! default_constructor { () => { + /// Creates a bootstrapped `TorTransport` + /// + /// # Errors + /// + /// Could return error emitted during Tor bootstrap by Arti. pub async fn bootstrapped() -> Result { let builder = Self::builder(); let ret = Self::from_builder(builder, AddressConversion::DnsOnly)?; @@ -242,8 +265,8 @@ where fn dial(&mut self, addr: Multiaddr) -> Result> { let maybe_tor_addr = match self.conversion_mode { - AddressConversion::DnsOnly => safe_extract_tor_address(&addr), - AddressConversion::IpAndDns => dangerous_extract_tor_address(&addr), + AddressConversion::DnsOnly => safe_extract(&addr), + AddressConversion::IpAndDns => dangerous_extract(&addr), }; let tor_address = maybe_tor_addr.ok_or(TransportError::MultiaddrNotSupported(addr))?; From d62d271c39e7653ba942f453750f4cfe192aa011 Mon Sep 17 00:00:00 2001 From: umgefahren <55623006+umgefahren@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:12:22 +0200 Subject: [PATCH 3/3] Updated changelog file --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d8178b..8bd4364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,13 @@ - Updated dependencies: See [PR 6]. - [`arti-client` to `v0.8`] - - [`libp2p-core` to `v0.8`] + +- Updated dependencies: See [PR 8]. + - [`libp2p-core` to `v0.39`] + - [`libp2p` to `0.51`] [PR 6]: https://github.com/umgefahren/libp2p-tor/pull/6 +[PR 8]: https://github.com/umgefahren/libp2p-tor/pull/8 # 0.2.0-alpha